You're reading the documentation for a development version. For the latest released version, please have a look at v0.2.

bibrecord.database module

Facilities for representing bibliographic databases.

While individual bibliographic records are handled by the bibrecord.record module and BibTeX files and records are dealt with by the bibrecord.bibtex module, this module provides means to handle bibliographic databases, i.e. a collection of individual bibrecord.record.Record objects.

Use cases

If you “only” want to have a bibliographic record as an attribute in a class, say for an implementation of an algorithm where you would like to give credit to the people who originally described the algorithm, one of the subclasses of bibrecord.record.Record is what you are usually interested in.

However, suppose you write a package that contains data from different sources (i.e., with different references) and you want to provide these references for each individual dataset. In this case, you will probably have a BibTeX bibliography file somewhere in the package data of your package that would be the original source of the bibliographic information. In this case, being able to convert this BibTeX bibliography file into an actionable representation for your package would come quite handy. This is what the Database class provides you with.

Creating such a database is a matter of only a few lines. Suppose your BibTeX database to reside in the file “literature.bib”:

import bibrecord

bibliography = bibrecord.bibtex.Bibliography()
bibliography.from_file("literature.bib")
database = bibrecord.database.Database()
database.from_bibliography(bibliography)

Now you can access all bibliographic records from your Database object.

Module documentation

class bibrecord.database.Database

Bases: object

Database of bibliographic records.

Each record is of type bibrecord.record.Record (actually, it is a subtype corresponding to the actual BibTeX entry type). Records are stored in the records attribute as a dictionary whose keys are the BibTeX keys used to cite the bibliographic record and the corresponding value the instance of the corresponding bibrecord.record.Record subclass.

records

Bibliographic records

The keys are the BibTeX keys used to cite the bibliographic record and the value the instance of the corresponding bibrecord.record.Record subclass.

Type:

dict

Examples

Suppose you have a BibTeX database residing in the file “literature.bib”. Creating a database containing the records in a form processable by the bibrecord package requires a few steps:

import bibrecord

bibliography = bibrecord.bibtex.Bibliography()
bibliography.from_file("literature.bib")
database = bibrecord.database.Database()
database.from_bibliography(bibliography)

The result is a database containing bibliographic records in a form that is processable by the bibrecord package and hence from within your code.

New in version 0.2.

from_bibliography(bibliography)

Populate database from bibliography.

Each BibTeX entry in the bibliography will be converted to an object of the corresponding bibrecord.record.Record subclass if this exists and added to the records dictionary. The key is the BibTeX key of the BibTeX entry used to cite the entry, the corresponding value the bibrecord.record.Record object.

Parameters:

bibliography (bibrecord.bibtex.Bibliography) – Representation of a BibTeX bibliography, e.g. as read from a file.