Skip to main content

Extra citations support for FLM

See the FLM README file.

Install with:

$ pip install flm-citations

Use the additional config front matter in your FLM files to enable citations with automatic citation retrieval from arXiv, DOI, etc.

---
$import:
  -  pkg:flm_citations
bibliography:
  - my-csl-bibliography.yaml
---

Then process your file as usual with flm.

The bibliography file(s) you provide (in the example above, my-csl-bibliography.yaml) should be in CSL JSON or CSL YAML format. They can easily be exported from Zotero, for example.

With the default configuration, the following citation keys are processed:

  • \cite{arXiv:XXXX.YYYYY} - fetch citation information from the arXiv, and from its corresponding DOI if applicable.
  • \cite{doi:XXX} - fetch citation information using its DOI
  • \cite{manual:{X et al., Journal of Future Results (2034)}} - manual citation text
  • \cite{bib:BibKey2023} - use a citation from any of your bibliography files specified in your document front matter.

Configuration

All options go under flm.features.flm_citations in your config or front matter.

Option
sources which citation sources to enable, and under which prefixes — see below
bib_csl_style path to a CSL style file for rendering entries
cache_dir, cache_base where the citation cache lives (default: next to the document, base .flm-citations)
on_citation_error fatal (default) aborts the build on an unresolvable citation; warn logs it and renders a visible placeholder
user_agent User-Agent sent with every request; arXiv and doi.org throttle harder when they cannot tell who is calling, and adding a contact address is customary
drop_csl_fields top-level CSL fields stripped before caching (default abstract, reference — doi.org returns the cited paper's entire bibliography under reference)
manual_format markup name manual: citation text is stored under (default flm). Setting it to anything else declares that those keys are not FLM, so they render verbatim rather than as markup
ttl_policy, retry, max_chain_depth cache-expiry and retry/backoff tuning
prune_cache drop cache entries expired past the grace window after each run (default off)
write_csljson_file, write_bibtex_file export the document's citations
on_event a callable receiving one dict per retrieval event (passes, per-source progress, requests, waits) — for driving a progress display. Not settable from YAML, since it takes a function

Progress is otherwise reported through the flm_citations.retrieve logger: at INFO you get passes and per-source counters, at DEBUG every HTTP request and resolved citation. Nothing is reported, and no reporter is even attached, when that logger is quieter than INFO.

Each entry of sources is {name: …, config: {…}}. A source's cite_prefix chooses the citation prefix it answers to, so the same kind of source can be registered more than once — for instance a second bibliography over different files:

flm:
  features:
    flm_citations:
      sources:
        - $defaults:
        - $merge-config:
            name: 'bibliographyfile'
            config:
              cite_prefix: b
              bibliography_file:
                - my-other-bibliography.yaml

The citation cache

Resolved citations are cached in .flm-citations.jsonl next to your document: one sorted entry per line, so a diff stays readable. Commit it if you want builds to be reproducible offline. A run also creates a few throwaway lock and log files while it is in flight; they all carry a ._ prefix and delete themselves, so one ignore rule covers them:

._.flm-citations*

Manual citation text is never written to the cache at all, so arbitrary \cite{manual:…} text cannot leak into a committed file.

Metadata Fetching

Thank you to arXiv and doi.org for use of their open access interoperability.

Since version 0.3, retrieval is handled by autocitefetch, a Rust library shipped as a compiled extension module. It brings automatic retry with backoff, correct rate limiting, stale-while-revalidate caching, and per-citation error tolerance. This package keeps the FLM integration and the citeproc-py rendering.

In case citeproc chokes on certain entries fetched by DOI

Sometimes automatically generated citeproc/JSON entries fetched through various available online APIs (doi.org, crossref.org, arXiv.org, etc.) might not be fully conforming or exactly matching the structure expected by the citeproc-py citation formatting library that this project uses. If you run against such issues, you might consider installing a patched version of the library that smoothed out some issues I had in the past; you can install it with

> pip install git+https://github.com/phfaist/citeproc-py.git@pr-branch

until my upstream PR is considered.

Note that citeproc-py needs issued in the {"date-parts": [[2022, 8, 12]]} form; the [{year: 2022, month: 8}] shape some CSL-YAML exporters produce is not accepted.

Upgrading from 0.2

Existing configurations keep working, with two exceptions and a few deprecations that are reported when they are used:

  • Custom Python citation source classes are gone. A sources entry naming an importable class (name: 'my.module.MyClass') is now an error; retrieval happens in the Rust library, which has no Python source interface.
  • cache_file is replaced by cache_dir + cache_base. The cache is no longer a single JSON file. The old .flm-citations.cache.json is not read and can be deleted.
  • cache_entry_duration_dt is ignored. Cache lifetimes are now per source (arXiv 10 days, DOI 360 days, bibliography files 60 s, manual entries not cached); only a bibliography source's lifetime is configurable, via ttl_seconds.
  • chunk_size and chunk_query_delay_ms are ignored. Chunk sizes and request pacing are properties of each remote API and are fixed by the library.

Two output differences are worth knowing about:

  • An arXiv entry's date is now its last revision (<updated>) rather than its original submission, so a paper's citation year may change.
  • write_csljson_file / write_bibtex_file now export exactly the citations the document uses, rather than everything that happened to be in the cache.

Development

pip install maturin
maturin develop            # build the extension into the current virtualenv
cargo test                 # Rust unit tests
pytest -m 'not network'    # Python tests, offline
pytest -m network          # live arXiv/doi.org checks (slow, rate-limited)

The Rust half depends on autocitefetch, pulled as a git dependency over anonymous https; no credentials are needed to build.

License

MIT

Release files for flm-citations 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flm-citations 0.3.0
File Size Uploaded
flm_citations-0.3.0.tar.gz 67.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for flm-citations 0.3.0
File
flm_citations-0.3.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
flm_citations-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
flm_citations-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
flm_citations-0.3.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
flm_citations-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 6.7 MB

Release files / flm_citations-0.3.0.tar.gz

Download URL flm_citations-0.3.0.tar.gz
Size 67.6 kB
Tags Source
SHA-256 checksum
How to use checksums
600a8d8e79355f535cdcaa3d1a9e41f346f64cf8e308e3d94dc50800ed1c5125
BLAKE2b-256 checksum
How to use checksums
87d6ba8ea36d238be4f737a5fa2126a641c520107de61ceae1073040edc2da76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / flm_citations-0.3.0-cp39-abi3-win_amd64.whl

Download URL flm_citations-0.3.0-cp39-abi3-win_amd64.whl
Size 1.2 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8bab22ddea4c9ac5517b3742d2a21827f7f3dc97d6349952354d9e2584287108
BLAKE2b-256 checksum
How to use checksums
71abc7b0ab1dfbba38390258ccb5088a898f27409ec02e1fb16654344bdc1be9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / flm_citations-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL flm_citations-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.4 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
e7d6bb256db289cf907c3140f9e398d4c4228f092b67db9a2d0b9f828d53e7fb
BLAKE2b-256 checksum
How to use checksums
40fcbe6889d7a012276c368ebd4715e673c3b334ac3df9fd9f707ea85c7015d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / flm_citations-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL flm_citations-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.3 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2338eb5231841bebfb3f47ffa1c5d18fcb50e043c3914e8aa3274aa061b09b42
BLAKE2b-256 checksum
How to use checksums
da40e5ab99a7e8317d16c07eb2d398cc41ee18c89c043428cdb03462abc51f82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / flm_citations-0.3.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL flm_citations-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
Size 1.3 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1f0964500c3aae5d9e537d09ac8a2f876b2d71c2d8694351b1b825583b5ee3fe
BLAKE2b-256 checksum
How to use checksums
ec16803b61a89ea764c8499c0cc38a57192cc57c30f887eca3579548c61f40af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / flm_citations-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL flm_citations-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 1.3 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f73ded0d419b4c88ec7343ff92dad7f9f9ae3c850a2772ab144460846f3d3502
BLAKE2b-256 checksum
How to use checksums
29e75a0f515f3a61bf931e138187d08e35961be07feab837314b0215ed14ff67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

6 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.4

2 release files

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