Support for citations in FLM (see flm-core package)
Project description
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
sourcesentry 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_fileis replaced bycache_dir+cache_base. The cache is no longer a single JSON file. The old.flm-citations.cache.jsonis not read and can be deleted.cache_entry_duration_dtis 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, viattl_seconds.chunk_sizeandchunk_query_delay_msare 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_filenow 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
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flm_citations-0.3.0.tar.gz.
File metadata
- Download URL: flm_citations-0.3.0.tar.gz
- Upload date:
- Size: 67.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
600a8d8e79355f535cdcaa3d1a9e41f346f64cf8e308e3d94dc50800ed1c5125
|
|
| MD5 |
365c4ba3c17bb17500356e111718ec57
|
|
| BLAKE2b-256 |
87d6ba8ea36d238be4f737a5fa2126a641c520107de61ceae1073040edc2da76
|
Provenance
The following attestation bundles were made for flm_citations-0.3.0.tar.gz:
Publisher:
build-wheels.yml on phfaist/flm-citations
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flm_citations-0.3.0.tar.gz -
Subject digest:
600a8d8e79355f535cdcaa3d1a9e41f346f64cf8e308e3d94dc50800ed1c5125 - Sigstore transparency entry: 2256215020
- Sigstore integration time:
-
Permalink:
phfaist/flm-citations@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/phfaist
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file flm_citations-0.3.0-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: flm_citations-0.3.0-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bab22ddea4c9ac5517b3742d2a21827f7f3dc97d6349952354d9e2584287108
|
|
| MD5 |
e2d318dba6a677df3392d10e82a92651
|
|
| BLAKE2b-256 |
71abc7b0ab1dfbba38390258ccb5088a898f27409ec02e1fb16654344bdc1be9
|
Provenance
The following attestation bundles were made for flm_citations-0.3.0-cp39-abi3-win_amd64.whl:
Publisher:
build-wheels.yml on phfaist/flm-citations
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flm_citations-0.3.0-cp39-abi3-win_amd64.whl -
Subject digest:
8bab22ddea4c9ac5517b3742d2a21827f7f3dc97d6349952354d9e2584287108 - Sigstore transparency entry: 2256215042
- Sigstore integration time:
-
Permalink:
phfaist/flm-citations@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/phfaist
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file flm_citations-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: flm_citations-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7d6bb256db289cf907c3140f9e398d4c4228f092b67db9a2d0b9f828d53e7fb
|
|
| MD5 |
e96f475472410998f34aabed88ca18c1
|
|
| BLAKE2b-256 |
40fcbe6889d7a012276c368ebd4715e673c3b334ac3df9fd9f707ea85c7015d4
|
Provenance
The following attestation bundles were made for flm_citations-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
build-wheels.yml on phfaist/flm-citations
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flm_citations-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
e7d6bb256db289cf907c3140f9e398d4c4228f092b67db9a2d0b9f828d53e7fb - Sigstore transparency entry: 2256215056
- Sigstore integration time:
-
Permalink:
phfaist/flm-citations@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/phfaist
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file flm_citations-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: flm_citations-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2338eb5231841bebfb3f47ffa1c5d18fcb50e043c3914e8aa3274aa061b09b42
|
|
| MD5 |
e9cf04d66149bba094e3c81c1ecb70ae
|
|
| BLAKE2b-256 |
da40e5ab99a7e8317d16c07eb2d398cc41ee18c89c043428cdb03462abc51f82
|
Provenance
The following attestation bundles were made for flm_citations-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
build-wheels.yml on phfaist/flm-citations
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flm_citations-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
2338eb5231841bebfb3f47ffa1c5d18fcb50e043c3914e8aa3274aa061b09b42 - Sigstore transparency entry: 2256215072
- Sigstore integration time:
-
Permalink:
phfaist/flm-citations@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/phfaist
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file flm_citations-0.3.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: flm_citations-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f0964500c3aae5d9e537d09ac8a2f876b2d71c2d8694351b1b825583b5ee3fe
|
|
| MD5 |
550e7c5472fd846c3d8e30698eadc403
|
|
| BLAKE2b-256 |
ec16803b61a89ea764c8499c0cc38a57192cc57c30f887eca3579548c61f40af
|
Provenance
The following attestation bundles were made for flm_citations-0.3.0-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
build-wheels.yml on phfaist/flm-citations
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flm_citations-0.3.0-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
1f0964500c3aae5d9e537d09ac8a2f876b2d71c2d8694351b1b825583b5ee3fe - Sigstore transparency entry: 2256215083
- Sigstore integration time:
-
Permalink:
phfaist/flm-citations@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/phfaist
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file flm_citations-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: flm_citations-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f73ded0d419b4c88ec7343ff92dad7f9f9ae3c850a2772ab144460846f3d3502
|
|
| MD5 |
c6c2fbc428171d814de337f950fba315
|
|
| BLAKE2b-256 |
29e75a0f515f3a61bf931e138187d08e35961be07feab837314b0215ed14ff67
|
Provenance
The following attestation bundles were made for flm_citations-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl:
Publisher:
build-wheels.yml on phfaist/flm-citations
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flm_citations-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl -
Subject digest:
f73ded0d419b4c88ec7343ff92dad7f9f9ae3c850a2772ab144460846f3d3502 - Sigstore transparency entry: 2256215098
- Sigstore integration time:
-
Permalink:
phfaist/flm-citations@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/phfaist
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-wheels.yml@2833fe2ae0a775f7dff5be1b90d2fde59b03ebd5 -
Trigger Event:
workflow_dispatch
-
Statement type: