Entry module

The Entry class is the generic class of an entry from which the classes for the different BibTeX entry types (like Article, Book, etc.) are derived. A list of the implemented types is appended to the tutorial.

A BibTeX entry is of a certain type, which reflects in the object type, and might have a citation-key. The various characteristic of a specific BibTeX entry is defined by a number of tags. A tag is a key-value pair, the tag name and its contents. The allowed tag names are defined in Entry.processedTags, and a list is given here.

To create an entry object, we recommend to use the classmethod Entry.get_Instance(). It will return an entry object of proper type, depending on the dictionary committed.

>>> # First we setup a dictionary containing the initial data, ..
>>> inputdict = {'ENTRYTYPE': 'mastersthesis', 'ID': 'Mayer2008',
             'author': u'Hans. H. Mayer',
             'school': u'University of Nowhere'
             'title': u'A very interesting thesis.',
             'year': u'2008'}

>>> # and than create the entry object.
>>> entryObject = biblib.Entry.get_Instance(inputdict)
>>> print entryObject
<biblib._entry.Mastersthesis object at 0x7f25456d6810>

The entry object is designed to behave similar to a python dictionary, which seems likely because of its key-value structure regarding the tags. Therefore the standard operators (get-,set-, delitem) are implemented. To manipulate the tags of an entry, one can either use the class methods (Entry.get_tag(), Entry.set_tag() and Entry.del_tag()) or the standard operators, like:

>>> tag_contents = entryObject['tag name']
>>> entryObject['tag name'] = u'tag contents'
>>> del entryObject['tag name']

Like a dictionary it supports the methods keys(), values(), and items(). Furthermore it is iterable, like:

>>> for tag_name, tag_contents in entryObject.items():
>>>     ...

It also supports the built-in function hash() and comparison operator: ==, !=.

Note

Because the hash value represents the contents, an entry object should not been used as a key in hashable collections!

To check if a tag is defined, one can simply:

>>> if tag_name in entryObject:
>>>     ...

Some tags are mandatory for certain types of BibTeX entries (e.g. Article.mandatoryTags), some are optional. The property Entry.is_complete can be used to check if a mandatory tag is missed, and the property Entry.missingTags which tag is missed.


Entry class

class biblib.Entry(inputdict)[source]

This is the generic class of a BibTeX Entry object.

Parameters:

inputdict (Entry.datadict) – initial data of the Entry

Returns:

BibTeX Entry object

Return type:

Entry

Raises:
  • NameError – if ENTRYTYPE is invalid or inconsistent with Entry object type
  • KeyError – if ENTRYTYPE is missed
processedTags = ['abstract', 'address', 'annote', 'author', 'booktitle', 'chapter', 'comment', 'crossref', 'doi', 'edition', 'editor', 'howpublished', 'institution', 'isbn', 'journal', 'key', 'keywords', 'month', 'note', 'number', 'organization', 'pages', 'publisher', 'school', 'series', 'title', 'type', 'url', 'volume', 'year']

List of tag names which are processed. All other tags will be ignored!

protectedTags = ['doi', 'url']

List of tag names which are protected from de- or encoding of LaTeX character code to unicode character or vice versa.

mandatoryTags = []

List containing the names of the tags which are required for the BibTeX entry type. It will be overwritten by the subclass definition.

BibTeXType = None

Defines the BibTeX Entry type of the object class as a string. It will be overwritten by the subclass definition.

classmethod get_Instance(inputdict)[source]

This is the recommended method to generate a BibTeX Entry object.

It returns an Entry object depending on the ENTRYTYPE as defined in the inputdict. To initialize an Entry object one need to commit an dictionary containing the initial tags of an Entry, like {'ID':'Doe2015', 'ENTRYTYPE':'article', 'year':'2015', ...}.

Parameters:

inputdict (Entry.datadict) – the initial values of an Entry

Returns:

BibTeX Entry object

Return type:

Article | Book | …

Raises:
  • NameError – if ENTRYTYPE is invalid
  • KeyError – if ENTRYTYPE is missed
keys()[source]

Returns a list of tag names defined for the entry object.

Returns:list of tag names
Return type:list
values()[source]

Returns a list of tags contents defined for the entry object.

Returns:list of tags contents
Return type:list
items()[source]

Returns a list of sets containing tag name/value.

Returns:list of sets tag name/value
Return type:list
set_tag(name, contents)[source]

Method to (re)set a tag.

Parameters:
  • name (str) – tag name
  • contents (str) – tag contents
Raises:

KeyError – if name is invalid (not in processedTags)

get_tag(name, default=None)[source]

Return the contents for a tag name if tag is defined for the Entry, else default.

Parameters:
  • name (str) – tag name
  • default – default return if tag is not defined
Returns:

tag contents

Return type:

str

del_tag(name)[source]

Method to delete a tag.

Parameters:name (str) – tag name
Raises:KeyError – if tag is not defined in entry
bibtex(ckey=None)[source]

Returns the BibTeX formatted string of the Entry object. If ckey is not defined, the initial ckey will be used.

Deprecated since version 0.1.dev1-r67: Use function db_to_string() instead.

Parameters:ckey (str) – BibTeX citation-key
Returns:BibTeX formated Entry
Return type:str
datadict

Property containing the BibTeX tag names and contents of the Entry as key-value pairs in a dictionary like {'ID':'Doe2015', 'ENTRYTYPE':'article', 'year':'2015', ...}. The keys ENTRYTYPE and ID are of special interest, they refer to the BibTeX Entry type, respectively the citation-key.

ckey

Property containing the initial BibTeX citation-key of the Entry.

authors

A list of dictionaries like [{'given': 'John', 'family': 'Doe'}, ...], or None, if author tag is not defined.

Note

author string needs to be a valid BibTeX format, like “John Doe and …” or “Doe, John and …”

missingTags

Checks if all tags which are defined as required (Entry.mandatoryTags) are set. It returns name of the tags which are not meet as a list of strings. If all requirements are fulfilled it will return None.

is_complete

Checks if all tags which are defined as required (Entry.mandatoryTags) are set.


Entrytype classes

This are child classes from Entry. To initalize them use the factory class method Entry.get_Instance().

class biblib.Article(inputdict)[source]

An article from a journal or magazine.

mandatoryTags = ['author', 'title', 'journal', 'year']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Book(inputdict)[source]

A book with an explicit publisher.

mandatoryTags = ['author', 'title', 'publisher', 'year']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Booklet(inputdict)[source]

A work that is printed and bound, but without a named publisher or sponsoring institution.

mandatoryTags = ['title']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Inbook(inputdict)[source]

A part of a book, e.g., a chpater, section, or whatever and/or a range of pages.

mandatoryTags = ['author', 'title', 'publisher', 'year', 'chapter', 'pages']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Incollection(inputdict)[source]

A part of a book having its own title.

mandatoryTags = ['author', 'title', 'booktitle', 'publisher', 'year']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Inproceedings(inputdict)[source]

An article in a conference proceedings.

mandatoryTags = ['author', 'title', 'booktitle', 'year']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Manual(inputdict)[source]

Technical documentation.

mandatoryTags = ['title']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Mastersthesis(inputdict)[source]

A master’s thesis.

mandatoryTags = ['author', 'title', 'school', 'year']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Misc(inputdict)[source]

Use this type when nothing else fits.

mandatoryTags = []

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Phdthesis(inputdict)[source]

A Ph.D. thesis.

mandatoryTags = ['author', 'title', 'school', 'year']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Proceedings(inputdict)[source]

Conference proceedings.

mandatoryTags = ['title', 'year']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Techreport(inputdict)[source]

A report published by a school or other institution, usually numbered within a series.

mandatoryTags = ['author', 'title', 'note']

List containing the names of the tags which are required for the BibTeX entry type.

class biblib.Unpublished(inputdict)[source]

A document having an author and title, but not formally published.

mandatoryTags = ['author', 'title', 'institution', 'year']

List containing the names of the tags which are required for the BibTeX entry type.