bibliofabric.zenodo
The Zenodo client (bibliofabric.zenodo) is a Python client for the Zenodo REST API. It types the records, communities, and vocabularies endpoints with Pydantic models, wraps the OAI-PMH endpoint, builds the Elasticsearch q clauses for you, and streams file downloads to disk. It ships an async client and a generated sync twin with the same API.
Install
uv add bibliofabric
The Zenodo client ships in bibliofabric 0.9.0 and newer. Requires Python 3.12 or newer.
Authentication
Public reads need no token. With the optional ZENODO_API_TOKEN set
the client sends Authorization: Bearer on every request and raises the
page size cap from 25 to 100, as documented upstream. Some routes outside
this client's scope (the legacy deposit routes, for example) need an
account and answer 403 without one.
Quick start
import asyncio
from bibliofabric.zenodo import ZenodoClient, community, resource_type
async def main():
async with ZenodoClient() as client:
record = await client.records.get("10.5281/zenodo.24378467")
print(record.title, record.metadata.version)
page = await client.records.search(
{"type": "dataset"},
query=community("ror-data"),
sort="mostrecent",
)
print(page.total, [record.title for record in page.results])
versions = await client.records.versions(record.id, page_size=5)
print(versions.total)
asyncio.run(main())
client.records exposes get(), exists(), search(), iterate(),
collect(), first(), count(), versions(), latest(), files(), and
download_file(). client.communities exposes search(), get(),
iterate(), records(), and subcommunities(). client.vocabularies
exposes search(), iterate(), and get(). client.oai exposes the six
OAI-PMH verbs plus iterate_records() and iterate_identifiers(). Start
with records, communities,
vocabularies, and OAI-PMH.
Sync usage
ZenodoSyncClient is generated from the async source and behaves the
same. The sync client uses plain httpx.Client and never starts or touches
an event loop, so it works in scripts, in Jupyter, in threads, and when
called from inside a running event loop.
from bibliofabric.zenodo import ZenodoSyncClient
with ZenodoSyncClient() as client:
record = client.records.get(24378467)
print(record.title)
for record in client.communities.records("ror-data", {"type": "dataset"}, limit=3):
print(record.id, record.title)
Use the async client in asyncio applications and for many concurrent
requests. Use the sync client everywhere else. Both read the ZENODO_*
settings the same way.
Settings
ZenodoSettings loads from environment variables prefixed with
ZENODO_: ZENODO_MAX_REQUESTS_PER_SECOND (default 2),
ZENODO_MAX_CONCURRENCY (default 5), ZENODO_TIMEOUT,
ZENODO_MAX_RETRIES, ZENODO_MAX_RETRY_WAIT,
ZENODO_USER_AGENT, and ZENODO_API_TOKEN.
Without a token, the record search and the search over the records of one
community allow 30 requests per minute, and every other route allows 133.
The two search routes therefore run in their own rate class:
ZENODO_RATE_LIMITS is a JSON object of requests per second per class
and defaults to {"search": 0.5}. A ZENODO_MAX_REQUESTS_PER_SECOND
that you set applies to every class, unless you also set
ZENODO_RATE_LIMITS. Zenodo rejects requests without a User-Agent
header, and the client always sends one.
Examples
Runnable scripts live in
packages/bibliofabric/examples/zenodo:
quickstart.py for record search, get(), and bounded iteration;
files.py for file listing and a small download into a temporary
directory; oaipmh.py for the OAI-PMH verbs; and records_sync.py for
ZenodoSyncClient.
Where to go next
- One usage page per resource family: records, communities, vocabularies, and OAI-PMH.
- Upstream quirks observed in the live Zenodo API.
- The API reference is generated from the source.