Invenio REST API Client
A typed Python client for the InvenioRDM REST API, with particular emphasis on the lifecycle of records and drafts.
Why this project exists
The original Invenio OpenAPI description documented the available operations, but at the time this client was developed it did not provide the response schemas required to generate a useful typed client.
This project therefore follows a schema-first reconstruction workflow:
- study the human-readable InvenioRDM REST API documentation;
- reconstruct the missing data and response schemas from the documented fields and examples;
- add those schemas to the OpenAPI description;
- generate Pydantic models and a Python client from the enhanced contract.
Most examples and validation work focus on operations associated with the
OpenAPI Records tag and the related draft, file, and version endpoints.
Install
pip install invenio-rest-api-client
Python 3.10 or newer is required.
Configure a client
Create an API token in your InvenioRDM account and expose the instance URL and token as environment variables:
export INVENIO_BASE_URL="https://invenio.example.org"
export INVENIO_TOKEN="replace-with-your-token"
Then create an authenticated client:
import os
from invenio_rest_api_client import AuthenticatedClient
client = AuthenticatedClient(
base_url=os.environ["INVENIO_BASE_URL"],
token=os.environ["INVENIO_TOKEN"],
raise_on_unexpected_status=True,
)
Search and retrieve records
Every endpoint module provides sync, sync_detailed, asyncio, and
asyncio_detailed functions.
from invenio_rest_api_client.api.records import (
get_a_record_by_id,
search_records,
)
with client:
results = search_records.sync(
client=client,
q='metadata.title:"climate"',
size="10",
page="1",
)
record = get_a_record_by_id.sync(
"abcde-12345",
client=client,
)
Use the detailed form when status codes, headers, or raw response content matter:
from http import HTTPStatus
from invenio_rest_api_client.api.records import get_a_record_by_id
with client:
response = get_a_record_by_id.sync_detailed(
"abcde-12345",
client=client,
)
if response.status_code is HTTPStatus.OK:
record = response.parsed
else:
raise RuntimeError(
f"Invenio returned {response.status_code}: "
f"{response.content.decode(errors='replace')}"
)
Create and publish a record
The generated request models make the minimum record metadata explicit:
from datetime import date
from invenio_rest_api_client.api.drafts import publish_a_draft_record
from invenio_rest_api_client.api.records import create_a_draft_record
from invenio_rest_api_client.models import (
Access,
AccessFiles,
AccessRecord,
CreateADraftRecordBody,
Creator,
Files,
Metadata,
PersonOrOrg,
PersonOrOrgType,
ResourceType,
ResourceTypeId,
)
body = CreateADraftRecordBody(
access=Access(
record=AccessRecord.PUBLIC,
files=AccessFiles.PUBLIC,
),
files=Files(enabled=False),
metadata=Metadata(
resource_type=ResourceType(id=ResourceTypeId.DATASET),
title="Climate observations",
publication_date=date.today(),
creators=[
Creator(
person_or_org=PersonOrOrg(
type=PersonOrOrgType.PERSONAL,
given_name="Ada",
family_name="Lovelace",
)
)
],
publisher="Example Repository",
),
)
with client:
draft = create_a_draft_record.sync(client=client, body=body)
if draft is None or draft.id is None:
raise RuntimeError("Invenio did not return the created draft")
published = publish_a_draft_record.sync(draft.id, client=client)
if published is None:
raise RuntimeError("Invenio did not return the published record")
Async usage
The async API mirrors the synchronous API:
from invenio_rest_api_client.api.records import get_a_record_by_id
async with client:
record = await get_a_record_by_id.asyncio(
"abcde-12345",
client=client,
)
Documentation
The documentation follows the Diátaxis convention:
- Tutorial: create your first record
- How-to guides
- Record API reference
- Why the schemas were reconstructed
- Enhanced OpenAPI reference
Development
Run the test and quality suite with:
task quality:pre-commit:run
Build the documentation locally with:
mkdocs build --strict
License
Licensed under the Apache License 2.0.
Metadata
Release files for invenio-rest-api-client 12.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| invenio_rest_api_client-12.0.4.tar.gz | 218.4 kB | With provenance | Details for invenio_rest_api_client-12.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| invenio_rest_api_client-12.0.4-py3-none-any.whl | Python 3 | none | any | Details for invenio_rest_api_client-12.0.4-py3-none-any.whl |
Total release size: 429.0 kB
Release files / invenio_rest_api_client-12.0.4.tar.gz
| Download URL | invenio_rest_api_client-12.0.4.tar.gz |
|---|---|
| Size | 218.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a9f54d7fade5de7e3079c3ba81b1d0be5b789479f7af6cd4c6b9cc7619f3e27
|
|
BLAKE2b-256 checksum How to use checksums |
b4cf248678670295d76b3ab1c54f85497da8dac36e6afe31370e94d7a4bef6bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.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 Aug 27, 2026.
Transparency logRelease files / invenio_rest_api_client-12.0.4-py3-none-any.whl
| Download URL | invenio_rest_api_client-12.0.4-py3-none-any.whl |
|---|---|
| Size | 210.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2d5ee4a4c9456376c44c70d4231f8308571f883ea2aeb68d3c254fe29fdb5454
|
|
BLAKE2b-256 checksum How to use checksums |
e1c0e16ec3e4e1df192039a7753fe29c765e621f4ea9bdd33be9a5e8f325556d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.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 Aug 27, 2026.
Transparency logSecurity for invenio-rest-api-client 12.0.4
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for invenio_rest_api_client-12.0.4.tar.gz
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 Aug 27, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.