Skip to main content

Bibtex parser for python 3

Project description

python-bibtexparser v2

Welcome to python-bibtexparser, a parser for .bib files with a long history and wide adaption.

Bibtexparser is available in two versions: V1 and V2. For new projects, we recommend using v2 which, in the long run, will provide an overall more robust and faster experience. For now, however, note that v2 is an early beta, and does not contain all features of v1. Install v2 using pip:

pip install bibtexparser --pre

Or you can install the latest development version directly from the main branch:

pip install --no-cache-dir --force-reinstall git+https://github.com/sciunto-org/python-bibtexparser@main

If instead, you want to use v1, install it using:

pip install bibtexparser~=1.0

Note that all development and maintenance effort is focussed on v2. Small PRs for v1 are still accepted, but only as long as they are backwards compatible and don't introduce much additional technical debt. Development of version one happens on the dedicated v1 branch.

The remainder of this README is specific to v2.

Documentation

Go check out our documentation on https://bibtexparser.readthedocs.io/en/main/.

Advantages of V2

  • :rocket: Order of magnitudes faster
  • :wrench: Easily customizable parsing and writing
  • :herb: Access to raw, unparsed bibtex.
  • :hankey: Fault-Tolerant: Able to parse files with syntax errors
  • :mahjong: Massively simplified, robuster handling of de- and encoding (special chars, ...).
  • :copyright: Permissive MIT license

TLDR Usage Example

# Parsing a bibtex string with default values
bib_database = bibtexparser.parse_string(bibtex_string)
# Converting it back to a bibtex string, again with default values
new_bibtex_string = bibtexparser.write_string(bib_database)

Slightly more involved example:

# Lets parse some bibtex string.
bib_database = bibtexparser.parse_string(bibtex_string,
    # Middleware layers to transform parsed entries.
    # Here, we split multiple authors from each other and then extract first name, last name, ... for each
    append_middleware=[SeparateCoAuthors(), SplitNameParts()],
)

# Here you have a `bib_database` with all parsed bibtex blocks.

# Let's transform it back to a bibtex_string.
new_bibtex_string = bibtexparser.write_string(bib_database,
    # Revert aboves transfomration
    prepend_middleware=[MergeNameParts(), MergeCoAuthors()]
)

These examples really only show the bare minimum. Consult the documentation for a list of available middleware, parsing options and write-formatting options.

V2 Architecture and Terminology

bibtexparserv2

The architecture consists of the following components:

Library

Reflects the contents of a parsed bibtex files, including all comments, entries, strings, preamples and their metadata (e.g. order).

A Splitter

Splits a bibtex string into basic blocks (Entry, String, Preamble, ...), with correspondingly split content (e.g. fields on Entry, key-value on String, ...). The splitter aims to be forgiving when facing invalid bibtex: A line starting with a block definition (@....) ends the previous block, even if not yet every bracket is closed, failing the parsing of the previous block. Correspondingly, one block type is "ParsingFailedBlock".

Middleware

Middleware layers transform a library and its blocks, for example by decoding latex special characters, interpolating string references, resoling crossreferences or re-ordering blocks. Thus, the choice of middleware allows to customize parsing and writing to ones specific usecase. Note: Middlewares, by default, no not mutate their input, but return a modified copy.

Writer

Writes the content of a bibtex library to a .bib file. Optional formatting parameters can be passed using a corresponding dedicated data structure.

About

Since 2022, bibtexparser is primarily written and maintained by Michael Weiss (@MiWeiss).

Credits and thanks to the many contributors who helped creating this library, including François Boulogne (@sciunto, creator of the first version) and Olivier Mangin (@omangin, long-term contributor).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bibtexparser-2.0.0b6.tar.gz (37.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bibtexparser-2.0.0b6-py3-none-any.whl (38.5 kB view details)

Uploaded Python 3

File details

Details for the file bibtexparser-2.0.0b6.tar.gz.

File metadata

  • Download URL: bibtexparser-2.0.0b6.tar.gz
  • Upload date:
  • Size: 37.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for bibtexparser-2.0.0b6.tar.gz
Algorithm Hash digest
SHA256 8e6c6ebd175c79445cf3b22c851a7658d0b166299f82006f3516be6dd081ce26
MD5 dde0b00d88bb89f8d2ab99a770fa3a0a
BLAKE2b-256 6915e5fa92fa6576c6423db55a37d0e135e5fb7f7a2657f3089b0a213c6117b5

See more details on using hashes here.

File details

Details for the file bibtexparser-2.0.0b6-py3-none-any.whl.

File metadata

  • Download URL: bibtexparser-2.0.0b6-py3-none-any.whl
  • Upload date:
  • Size: 38.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for bibtexparser-2.0.0b6-py3-none-any.whl
Algorithm Hash digest
SHA256 495df0681dc4fdab617eed104b6d8d7fbb807fb65dec467f3db87273add5948b
MD5 1f9be55599a27a1e8aaa50b413b4f694
BLAKE2b-256 ebcc0afdffe146c186f96131bba101680f5d06d131ecb34ec515e9c57337d03b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page