bibliofabric.datacite
The DataCite client (bibliofabric.datacite) is a Python client for the
DataCite REST API. It types the public
read routes for DOIs, clients, providers, repositories, prefixes, prefix
assignments, activities, and events, flattens the JSON:API envelope so
record fields sit at the top level of each model, and sends queries to the
public GraphQL API. It ships an async client and a generated sync twin with
the same API.
Install
uv add bibliofabric
The DataCite client ships in bibliofabric 0.9.0 and newer. Requires Python 3.12 or newer.
Authentication
Public reads need no login and no key. The client never sends credentials. Routes that need a login (DOI writes, media, usage reports, draft and registered records, API keys) are not wrapped; see upstream quirks.
Anonymous traffic is metered at 500 requests per 5 minutes. The client paces itself at 1.5 requests per second by default.
Quick start
import asyncio
from bibliofabric.datacite import DataCiteClient
async def main():
async with DataCiteClient() as client:
doi = await client.dois.get("10.5438/0012")
print(doi.title, doi.resource_type, doi.client_id)
page = await client.dois.search(
{"client-id": "cern.zenodo", "resource-type-id": "dataset"},
query="photosynthesis",
select=["doi", "titles"],
)
print(page.total, len(page.results))
async for record in client.dois.iterate({"prefix": "10.5438"}, limit=10):
print(record.doi, record.created)
asyncio.run(main())
Every resource client exposes get(), exists(), search(), iterate(),
collect(), first(), and count(). The clients, providers, and prefixes
clients add totals() for DOI production statistics and a dois() helper
that reads the DOIs of one account or prefix. Start with the
DOIs page.
Sync usage
DataCiteSyncClient is generated from the async source and behaves the
same: same parameters, errors, retries, paging, and rate limits. It uses
plain httpx.Client and never starts or touches an event loop.
from bibliofabric.datacite import DataCiteSyncClient
with DataCiteSyncClient() as client:
doi = client.dois.get("10.5438/0012")
print(doi.title, doi.publicationYear)
for record in client.providers.search(page_size=5):
print(record.symbol, record.displayName)
Settings
DataCiteSettings loads from environment variables prefixed with
DATACITE_: DATACITE_MAX_REQUESTS_PER_SECOND (default 1.5),
DATACITE_MAX_CONCURRENCY (default 3), DATACITE_TIMEOUT (default
30), DATACITE_MAX_RETRIES (default 3), DATACITE_MAX_RETRY_WAIT,
DATACITE_USER_AGENT, and DATACITE_MAILTO.
Examples
Runnable scripts live in
packages/bibliofabric/examples/datacite:
quickstart.py for DOI lookup, search, and bounded cursor iteration;
dois_sync.py for DataCiteSyncClient; and rest_vs_graphql.py for
reading one DOI through both the REST and the GraphQL API.
Where to go next
- One usage page per resource family: dois, clients, providers, repositories, prefixes, events, media, and GraphQL.
- Upstream quirks observed in the live DataCite API.
- The API reference is generated from the source.