Pybtex is a BibTeX-compatible bibliography processor written in Python, designed to read citation information from various formats (BibTeX, BibTeXML, YAML) and produce formatted bibliographies. It supports traditional BibTeX `.bst` styles and also allows for defining custom styles directly in Python, with output options including LaTeX, HTML, Markdown, or plain text. Currently at version 0.26.1, it is actively maintained and serves as a flexible alternative or drop-in replacement for the original BibTeX.
pip install pybtexVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a BibTeX file, apply a predefined formatting style (or a custom one), and output the result to an HTML file using Pybtex's Python API. It creates a dummy `.bib` file, processes it, and then cleans up the generated files. For more complex use cases, especially with `.aux` files, the command-line interface or the `pybtex.Engine` might be more suitable.
For `.bst` styles, expect LaTeX output. For HTML/Markdown/plain text output, use Pythonic styles and configure the output backend explicitly (e.g., `pybtex --style-language python --output-backend html` or use `pybtex.database.output.html.Writer` in API).
Use `entry.persons['author']` for authors and `entry.fields['title']` for titles. Avoid `entry[0]` as `Entry` objects do not support indexing.
When using Pybtex programmatically, anticipate and handle `PybtexError` exceptions. For command-line use, the `--strict` option can be used to make warnings into errors.
Consult the latest Pybtex documentation for the recommended API when reading/writing data and creating custom styles, especially for `pybtex.richtext` objects.
Access entry properties using their specific attributes like `entry.type`, `entry.fields`, and `entry.persons`.
Before accessing a person role, check for its existence using `if 'editor' in entry.persons:` or use the `.get()` method with a default value, e.g., `entry.persons.get('editor', [])`.Ensure that the BibTeX input adheres to standard BibTeX format (e.g., `@article{key, ...}`). If using specific LaTeX packages, the bibliography might need to be converted to standard BibTeX format before processing with Pybtex.Verify that `pybtex` is correctly installed (`pip install pybtex`). If it is, check the import statement for typos and ensure the module path is correct according to the `pybtex` documentation, e.g., `from pybtex.database.input import bibtex`.
No dependency data recorded yet.