Crossref
The Crossref client (bibliofabric.crossref) is a Python client for the Crossref REST API, with an async variant and a generated sync twin. It covers the works, journals, funders, members, types, prefixes, and licenses routes with typed Pydantic models, plus the beta Data Citations API.
Install
uv add bibliofabric
The Crossref client ships in bibliofabric 0.9.0 and newer. Requires Python 3.12 or newer.
Quick start
import asyncio
from bibliofabric.crossref import CrossrefClient
async def main() -> None:
async with CrossrefClient(mailto="you@example.org") as client:
work = await client.works.get("10.1038/nature12373")
print(work.primary_title)
page = await client.works.search(
query="proteomics", select=["DOI", "title"], page_size=5
)
for work in page.results:
print(work.doi, work.primary_title)
asyncio.run(main())
search() returns a Page with .results (typed models), .total, .next_cursor, and .meta (the response envelope minus the results).
Sync usage
Every class has a generated sync twin: CrossrefClient pairs with CrossrefSyncClient, and each resource class pairs with a Sync-prefixed twin (WorksResource -> SyncWorksResource). Both variants take the same parameters, raise the same errors, retry and page the same way, and enforce the same per-class rate limits.
from bibliofabric.crossref import CrossrefSyncClient
with CrossrefSyncClient(mailto="you@example.org") as client:
work = client.works.get("10.1038/nature12373")
page = client.works.search(query="proteomics", select=["DOI", "title"], page_size=5)
for work in page.results:
print(work.doi, work.primary_title)
The sync client uses httpx.Client, time.sleep, and threads, and never starts or touches an event loop, so it works in plain scripts, in Jupyter, and when called from inside a running event loop. See Sync usage for when to pick which variant.
Credentials
The Crossref API needs no authentication. Two optional credentials change how requests are sent:
| Credential | How to set it | What it does |
|---|---|---|
| Polite pool email | mailto= or CROSSREF_MAILTO |
Sent as a mailto query parameter; raises your rate limits |
| Metadata Plus key | plus_token= or CROSSREF_PLUS_TOKEN |
Sent as a crossref-api-key: Bearer <key> header |
A plus_token replaces mailto as the credential when both are set. An explicit auth_strategy= argument overrides both.
When rate limits are not explicitly configured, CrossrefClient applies pool-aware defaults (Public: 5/1 req/s, Polite: 10/3 req/s, Metadata Plus: 50/50 req/s for the single/list classes; the datacitations class runs at 3 req/s in every pool) and tracks Crossref's x-api-pool / x-rate-limit-* / x-rate-limit response headers via client.last_pool and client.last_rate_limit_headers.
Examples
Runnable scripts live in
packages/bibliofabric/examples/crossref:
quickstart.py for get, search, and cursor iteration, and
batch_and_scopes.py for batch DOI lookup, facets, scoped works, and error
handling.
Where to go next
- Works: search, filters, cursor iteration, batch DOI lookup, facets, sample, agency, and scoped works routes.
- Data citations: the beta Data Citations API.
- Errors, retries, rate limits.
- Crossref quirks: behavior the client defends against.
- API reference.