Skip to main content

python-bibtexparser v2

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

Bibtexparser is available in two versions: V1 and V2. V2 is the current, recommended version and the default you get from PyPI. It provides an overall more robust and faster experience than v1, and is where all development and maintenance effort goes. Install it using pip:

pip install bibtexparser

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 still need v1, e.g. for a legacy project which you don't want to migrate right now, pin it explicitly:

pip install bibtexparser~=1.0

Note that v2 is a rewrite: a lot has changed since v1, including the primary entrypoints, the data structures and the way parsing and writing are customized. Existing v1 code will not run unchanged on v2 - have a look at our migration guide when upgrading. While v2 has been thoroughly tested and has been in pre-release for a long time, please don't hesitate to report any issues you may encounter.

V1 is in maintenance mode: small PRs 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.

Documentation

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

Advantages of v2 compared to v1

  • :rocket: Order of magnitudes faster
  • :wrench: Easily customizable parsing and writing
  • :herb: Access to raw, unparsed bibtex.
  • :shield: Fault-Tolerant: Able to parse files with syntax errors
  • :mahjong: Massively simplified, more robust 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 above transformation
    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.

Architecture and Terminology

bibtexparser

The architecture consists of the following components:

Library

Reflects the contents of a parsed bibtex files, including all comments, entries, strings, preambles 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, resolving crossreferences or re-ordering blocks. Thus, the choice of middleware allows to customize parsing and writing to ones specific usecase. Note: Middlewares, by default, do 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), supported by various awesome contributors.

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).

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.0.tar.gz (88.0 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.0-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bibtexparser-2.0.0.tar.gz
  • Upload date:
  • Size: 88.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for bibtexparser-2.0.0.tar.gz
Algorithm Hash digest
SHA256 7f1e1d989282836a0ba39caf88ecc8982dfd924a4f49de58167d7effe99768e8
MD5 715df66bfa53c18e312dadd67a1589f5
BLAKE2b-256 ca881fbb799766aed95a310676f0c44ab65d89ccaa2535517059744dede848ec

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bibtexparser-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5e6df506d53e354874240c7f7fbd98a36db4b725e139f30e175f710a72a68b7
MD5 fed4a12c8a83b9056a64e63578b0c674
BLAKE2b-256 c0e2161a0ee841d23bcf97f3d04cd1a05ab8cd412e3d86640c24ee6a1345b83c

See more details on using hashes here.

Release history Release notifications | RSS feed

2.0.1

2 files

This release

2.0.0 This release

2 files

1.4.4

1 file

1.4.3

1 file

1.4.2

1 file

1.4.1

1 file

1.4.0

1 file

1.3.0

2 files

1.2.0

1 file

1.1.0

1 file

1.0.1

1 file

1.0

1 file

0.6.2

1 file

0.6.1

1 file

0.6.0

1 file

0.5.5

1 file

0.5.4

1 file

0.5.3

1 file

0.5.2

1 file

0.5.1

1 file

0.5

1 file

0.4

1 file

0.3

1 file

0.2

1 file

0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page