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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 invenio_rest_api_client-12.0.3.tar.gz.
File metadata
- Download URL: invenio_rest_api_client-12.0.3.tar.gz
- Upload date:
- Size: 198.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
545c968bdfdd3fc1f1fa848393fd0bb0eb5eca1fd46e27bf03d7e8ef5d650e81
|
|
| MD5 |
76d3fa6e3b9956b6cb65af4375abbe0d
|
|
| BLAKE2b-256 |
cd4c0494daa45de1b260d96c09a07deac367c9aca0848c59d2ce1eddbbe4dfc1
|
Provenance
The following attestation bundles were made for invenio_rest_api_client-12.0.3.tar.gz:
Publisher:
package.yaml on Terradue/invenio-rest-api-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
invenio_rest_api_client-12.0.3.tar.gz -
Subject digest:
545c968bdfdd3fc1f1fa848393fd0bb0eb5eca1fd46e27bf03d7e8ef5d650e81 - Sigstore transparency entry: 2292482378
- Sigstore integration time:
-
Permalink:
Terradue/invenio-rest-api-client@38c70e033182fb301d5366672f534d5401748a21 -
Branch / Tag:
refs/tags/v12.0.3 - Owner: https://github.com/Terradue
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
package.yaml@38c70e033182fb301d5366672f534d5401748a21 -
Trigger Event:
push
-
Statement type:
File details
Details for the file invenio_rest_api_client-12.0.3-py3-none-any.whl.
File metadata
- Download URL: invenio_rest_api_client-12.0.3-py3-none-any.whl
- Upload date:
- Size: 210.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ac0941c63e98729200427a982e25bfcec731ed05292462e19d904df03c782c4
|
|
| MD5 |
bcb47cac7b6e7d8c7f71d95dc8134936
|
|
| BLAKE2b-256 |
72c127941b324dc7323d4f42242d0cf71dd11190a18e42e36533ecf224fb4844
|
Provenance
The following attestation bundles were made for invenio_rest_api_client-12.0.3-py3-none-any.whl:
Publisher:
package.yaml on Terradue/invenio-rest-api-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
invenio_rest_api_client-12.0.3-py3-none-any.whl -
Subject digest:
5ac0941c63e98729200427a982e25bfcec731ed05292462e19d904df03c782c4 - Sigstore transparency entry: 2292482418
- Sigstore integration time:
-
Permalink:
Terradue/invenio-rest-api-client@38c70e033182fb301d5366672f534d5401748a21 -
Branch / Tag:
refs/tags/v12.0.3 - Owner: https://github.com/Terradue
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
package.yaml@38c70e033182fb301d5366672f534d5401748a21 -
Trigger Event:
push
-
Statement type: