OpenAire
The OpenAire client (bibliofabric.openaire) is a Python client (async and generated sync twin) for the OpenAIRE
Graph API and the Scholexplorer API. It is built on the shared
bibliofabric core, which provides
retries, rate limiting, and pagination; OpenAire adds the OpenAIRE query
dialect, typed filter models, and response parsing.
Install
uv add bibliofabric
The OpenAire client ships in bibliofabric 0.9.0 and newer. Requires Python 3.12 or newer.
Quick start
import asyncio
from bibliofabric.openaire import OpenAireClient
async def main() -> None:
async with OpenAireClient() as client:
page = await client.research_products.search(query="quantum dots", page_size=10)
for product in page.results:
print(product.id, product.mainTitle)
asyncio.run(main())
Without credentials the client is anonymous. For the registered-service
quota, set OPENAIRE_CLIENT_ID and
OPENAIRE_CLIENT_SECRET (environment variables or a .env file);
the client then fetches a bearer token from the OpenAIRE Keycloak endpoint
and reuses it until it expires. Setting only one of the two raises
ConfigurationError. You can also set OPENAIRE_REFRESH_TOKEN
(or pass refresh_token=) for OAuth2 refresh-token authentication, or pass an
explicit auth_strategy= (auth= is kept as a deprecated alias).
Sync usage
OpenAire ships two variants of every client class. The async code is the single source of truth; the sync twins are generated from it with unasync and committed.
| Async | Sync |
|---|---|
OpenAireClient |
OpenAireSyncClient |
ResearchProductsResource |
SyncResearchProductsResource |
ScholixResource |
SyncScholixResource |
Use the async client inside asyncio applications. Use the sync client in
scripts and notebooks, or from code that runs inside a running event loop:
it uses httpx.Client, time.sleep, and threads, and never starts or
touches an event loop.
from bibliofabric.openaire import OpenAireSyncClient
with OpenAireSyncClient() as client:
page = client.research_products.search(query="quantum dots", page_size=10)
for product in page.results:
print(product.id, product.mainTitle)
Both variants take the same parameters, raise the same errors, retry and
page the same way, and enforce the same rate limits. Every resource
attribute of OpenAireSyncClient (research_products, projects,
organizations, data_sources, persons, scholix) exposes the matching
Sync* resource class.
The client
| Attribute | Resource | Host |
|---|---|---|
client.research_products |
V4 research products plus link helpers | Graph |
client.projects |
V4 projects | Graph |
client.organizations |
V4 organizations | Graph |
client.data_sources |
V4 data sources | Graph |
client.persons |
V4 persons | Graph |
client.research_products.search_links |
V3 relations between products | Graph |
client.scholix |
Scholexplorer Links (V3, V2 for linkProvider) |
Scholexplorer |
Every entity resource supports search, iterate, collect, first,
count, facets, and group_by. get(id) reads the V3 by-id route
because V4 has none; it takes internal OpenAIRE ids (they contain ::), and
research_products.get also accepts DOIs and persons.get accepts ORCID
iDs, resolving each through the matching filter and raising NotFoundError
when nothing matches. See the usage pages for each resource family.
Examples
Runnable scripts live in
packages/bibliofabric/examples/openaire:
a quickstart (DOI lookup, get, search, bounded iterate), the same calls with
the sync client, batch DOI lookups with sparse field fetches and
aggregations, and relations through the Graph links route and Scholix. Each
script states its run command in its docstring; details are in
examples/openaire/README.md.