Registry / serialization / pybtex-docutils

pybtex-docutils

JSON →
library1.0.3pypypi✓ verified 24d ago

pybtex-docutils is a Docutils backend for the Pybtex bibliography processor. It enables the insertion of BibTeX citations into documentation generated by Docutils, particularly for reStructuredText. The current version is 1.0.3, and while releases are not on a strict schedule, the library is actively maintained.

pip install pybtex-docutils
INSTALL
IMPORT
SIG · PYBTEX-DOCUTILS
P
pybtex-docutils
serializationpythonv1.0.3
Install
2.2s avg
Import
214ms
Disk
24MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.218s · 25.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.2s · import 0.210s · 27MB
24MB installed
● package 24MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SimpleBibliography
from pybtex_docutils import SimpleBibliography
Used to register the 'simplebibliography' directive in custom Docutils scripts.
Backend
from pybtex_docutils import Backend
The primary backend class, also accessible via pybtex.plugin.find_plugin('pybtex.backends', 'docutils').

This quickstart demonstrates how to use the `simplebibliography` directive with a pure Docutils workflow. It generates a sample BibTeX file (`refs.bib`) and an reStructuredText file (`example.rst`), then uses a Python script to process `example.rst` into `example.html`, including the bibliography. This setup requires manually registering the `SimpleBibliography` directive with Docutils.

import io from docutils.parsers.rst import directives, Directive from docutils.core import publish_cmdline, default_description from pybtex_docutils import SimpleBibliography # Create a dummy .bib file with open('refs.bib', 'w') as f: f.write(''' @Book{Nelson1987, author = {Edward Nelson}, title = {Radically Elementary Probability Theory}, publisher = {Princeton University Press}, year = {1987} } ''') # Create a dummy .rst file with open('example.rst', 'w') as f: f.write(''' .. highlight:: python Example Document ================ See {Nelson1987}_ for an introduction to non-standard analysis. .. simplebibliography:: refs.bib ''') # Register the directive and publish the document description = ('Like rst2html5.py, but with .. simplebibliography support' + default_description) directives.register_directive("simplebibliography", SimpleBibliography) publish_cmdline(writer_name='html5', description=description, argv=['example.rst', 'example.html']) print("Generated example.html with bibliography.")
Debug
Known issues
gotchaWhen using the `simplebibliography` directive directly with Docutils, citation keys in your BibTeX file cannot contain colons. This is because Docutils uses citation keys as labels, and colons are not valid characters for these labels. This limitation is lifted when using `sphinxcontrib-bibtex`.
fix
Ensure BibTeX citation keys do not contain colons, or use `sphinxcontrib-bibtex` for Sphinx projects if more complex keys are needed.
affects: All versions
gotchaThe `simplebibliography` directive provided by `pybtex-docutils` is primarily intended for simple single-document Docutils workflows. For projects built with Sphinx, it is strongly recommended to use `sphinxcontrib-bibtex` instead, as it offers more features and better integration with Sphinx's build process.
fix
For Sphinx-based projects, install and configure `sphinxcontrib-bibtex` instead of relying on `pybtex-docutils` directly.
affects: All versions
gotchaExtending Docutils with custom directives like `simplebibliography` currently requires writing a custom Python command script that registers the directive before processing the reStructuredText document. There is no simpler plugin mechanism for pure Docutils outside of a custom script.
fix
Always prepare a Python script to register `SimpleBibliography` (e.g., `directives.register_directive("simplebibliography", SimpleBibliography)`) and then use `publish_cmdline` or similar Docutils API calls to process your `.rst` files.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pybtex.database'; 'pybtex' is not a package
This error occurs when the 'pybtex' package, a core dependency for pybtex-docutils, is not installed or incorrectly installed in the Python environment being used.
fix
Ensure pybtex is installed in the active Python environment: `pip install pybtex`.
WARNING: could not find bibtex key "MYKEY"
The citation key specified in the reStructuredText document does not correspond to any entry in the provided BibTeX (.bib) files, or there's an issue with splitting bibtex entries across multiple files with repeated keys.
fix
Verify that the citation key (e.g., `MYKEY`) exactly matches an entry ID in your `.bib` file(s) and that all required `.bib` files are correctly referenced. Consider consolidating `.bib` files if using multiple.
Citation keys contain colons (e.g., `key:with:colon`) when using with pure Docutils.
When using `pybtex-docutils` directly with Docutils (not through Sphinx and `sphinxcontrib-bibtex`), Docutils' default parsing for citation labels does not support colons in citation keys.
fix
Rename BibTeX citation keys to remove colons (and any other characters not valid for Docutils citation labels). If colons are necessary, use `sphinxcontrib-bibtex` within Sphinx, which supports them.
AttributeError: 'dict' object has no attribute 'fields'
This error typically arises when a custom Pybtex formatting style attempts to access bibliography entry data using an outdated or incorrect attribute, like `entry.fields['title']`, on an object that is now a dictionary-like structure.
fix
Update the custom Pybtex style to access bibliography entry data using the current Pybtex API, which often involves direct dictionary-style access, e.g., `entry['title']`.
Upgrade
Version history
1.0.3latest on PyPI · released Aug 22, 2023
Audit
Dependencies
pybtexrequiredCore bibliography processing engine.
docutilsrequiredCore documentation utilities for reStructuredText processing.
Agent activity
7 hits · last 30 days
node
6
Resources
pybtex-docutils — pip install pybtex-docutils · libregistry