UKRI Gateway to Research
bibliofabric.ukrigtr is a Python client for the GTR-2 API of the UKRI Gateway to Research. It covers project, person, organisation, and fund search and records, all outcomes types, and the API metadata routes. Every call returns typed Pydantic models, and each client ships as an async class plus a generated sync twin.
The API needs no credentials. Gateway to Research publishes no numeric rate limit and asks clients to pace themselves; the client defaults to 2 requests per second. GtR is open and free to use under the Open Government Licence; the terms of use govern API use.
The API rejects page sizes under 10 and over 100 with HTTP 400, so first() requests a page of 10. batch_get is disabled on every resource: upstream has no query that returns many records by id, so calling it raises ConfigurationError and you call get() per id.
Quick start
import asyncio
from bibliofabric.ukrigtr import UkriGtrClient
async def main() -> None:
async with UkriGtrClient() as client:
# A small project search. The API sorts by relevance by default.
page = await client.projects.search(query="graphene", page_size=10)
print("projects mentioning graphene:", page.total)
project = page.results[0]
print(project.title, f"({project.lead_funder}, {project.status})")
for reference in project.identifiers.identifier:
print("grant reference:", reference.value)
# The fund carries the value of the project.
funds = await client.projects.funds(project.id)
fund = funds.results[0]
value = fund.value_pounds
print(
"funded:", f"{value.amount} {value.currency_code}" if value else "unknown"
)
# The people on the project.
people = await client.projects.persons(project.id)
person = people.results[0]
print("person:", person.first_name, person.surname)
asyncio.run(main())
projects mentioning graphene: 688
Inkjet Printing of Plasma Functionalised Graphene to Deliver Multifunctional Polymer Composites for Aerospace Applications (PlasmaGraph) (Innovate UK, Closed)
grant reference: 132259
funded: 112679 GBP
person: Beverly Frain
Sync quick start
UkriGtrSyncClient is generated from the async source and offers the same methods without async and await. The page Async and sync clients explains when to use which.
from bibliofabric.ukrigtr import UkriGtrSyncClient
with UkriGtrSyncClient() as client:
page = client.projects.search(query="graphene", page_size=10)
print("projects:", page.total)
fund = client.projects.funds(page.results[0].id).results[0]
print("funded:", fund.value_pounds.amount, fund.value_pounds.currency_code)
What the client offers
| Attribute | Resource | Common methods | Client-specific methods |
|---|---|---|---|
client.projects |
/projects, /projects/{id}, and the per-project sub-routes |
search, iterate, collect, first, count, get, exists |
funds, persons, organisations, outcomes |
client.persons |
/persons, /persons/{id}, and the per-person sub-routes |
the common methods | projects, organisations |
client.organisations |
/organisations, /organisations/{id}, and the per-organisation sub-routes |
the common methods | funds, persons, projects |
client.funds |
/funds, /funds/{id} |
the common methods | none |
client.outcomes |
/outcomes (all types merged) |
search, first, count; iterate and collect raise ConfigurationError |
13 typed resources; see below |
client.configs |
/configs/{resource} and /examples |
get |
examples |
The typed resources on client.outcomes offer search, iterate, collect, first, count, get, and exists against one outcome type each, plus for_project(id) for the project-scoped route: key_findings, impact_summaries, publications, collaborations, intellectual_properties, policy_influences, products, research_materials, spin_outs, further_fundings, disseminations, artistic_products, and software_products. Upstream serves no per-type route for exploitation, other research item, or research database and model outcomes; accessing those attributes raises ConfigurationError, and the records still appear in the merged /outcomes stream.
Search takes query (the q parameter) and sort (a field code with an optional asc or desc, for example "pro.sd desc"); client.configs.get("projects") lists the field codes. The shared behavior of search, iterate, collect, first, and count is described in Paging, and query strings in Search.
Examples
Runnable scripts live in packages/bibliofabric/examples/ukrigtr/:
quickstart.pysearches projects, reads the fund of one project, and lists its people.project_outcomes.pywalks the merged outcomes stream and the typed publication route.
Next
- Upstream quirks lists where the live API differs from its documentation.
- The API reference is generated from the source.