bibtexparser: API¶
bibtexparser — Parsing and writing BibTeX files¶
BibTeX <http://en.wikipedia.org/wiki/BibTeX> is a bibliographic data file format.
The bibtexparser module provides parsing and writing of BibTeX files functionality. The API is similar to the
json module. The parsed data is returned as a simple BibDatabase object with the main attribute being
entries representing bibliographic sources such as books and journal articles.
Parsing is a simple as:
>>>> import bibtexparser
>>>> with open('bibtex.bib') as bibtex_file:
>>>> bibtex_database = bibtexparser.load(bibtex_file)
And writing:
>>>> import bibtexparser
>>>> with open('bibtex.bib', 'w') as bibtex_file:
>>>> bibtexparser.dump(bibtex_database, bibtex_file)
-
bibtexparser.load(bibtex_file, parser=None)[source]¶ Load
BibDatabaseobject from a fileParameters: - bibtex_file (file) – input file to be parsed
- parser (BibTexParser) – custom parser to use (optional)
Returns: bibliographic database object
Return type:
-
bibtexparser.loads(bibtex_str, parser=None)[source]¶ Load
BibDatabaseobject from a stringParameters: - bibtex_str (str or unicode) – input BibTeX string to be parsed
- parser (BibTexParser) – custom parser to use (optional)
Returns: bibliographic database object
Return type:
-
bibtexparser.dumps(bib_database, writer=None)[source]¶ Dump
BibDatabaseobject to a BibTeX stringParameters: - bib_database (BibDatabase) – bibliographic database object
- writer (BibTexWriter) – custom writer to use (optional) (not yet implemented)
Returns: BibTeX string
Return type: unicode
-
bibtexparser.dump(bib_database, bibtex_file, writer=None)[source]¶ Save
BibDatabaseobject as a BibTeX text fileParameters: - bib_database (BibDatabase) – bibliographic database object
- bibtex_file (file) – file to write to
- writer (BibTexWriter) – custom writer to use (optional) (not yet implemented)
bibtexparser.bibdatabase — The bibliographic database object¶
-
class
bibdatabase.BibDatabase[source]¶ A bibliographic database object following the data structure of a BibTeX file.
-
comments= None¶ List of BibTeX comment (@comment{...}) blocks.
-
entries= None¶ List of BibTeX entries, for example @book{...}, @article{...}, etc. Each entry is a simple dict with BibTeX field-value pairs, for example ‘author’: ‘Bird, R.B. and Armstrong, R.C. and Hassager, O.’ Each entry will always have the following dict keys (in addition to other BibTeX fields):
- ID (BibTeX key)
- ENTRYTYPE (entry type in lowercase, e.g. book, article etc.)
-
entries_dict¶ Return a dictionary of BibTeX entries. The dict key is the BibTeX entry key
-
preambles= None¶ List of BibTeX preamble (@preamble{...}) blocks.
-
strings= None¶ OrderedDict of BibTeX string definitions (@string{...}). In order of definition.
-