NIH RePORTER
The NihReporter client (bibliofabric.nihreporter) reads the
NIH RePORTER API v2: NIH and non-NIH funded
research projects and the publications linked to them. Calls return typed
Pydantic models through an async client and a generated sync twin.
Credentials
The API serves public domain data of the United States government and needs
no credentials. NIH asks API users to send no more than one request per
second, so the client paces itself at 1 request per second with 1 concurrent
request. Tune both with NIHREPORTER_MAX_REQUESTS_PER_SECOND and
NIHREPORTER_MAX_CONCURRENCY; see the settings guide.
The constructor also takes a keyword-only mailto= contact address; it
overrides NIHREPORTER_MAILTO and appears in the User-Agent the client
sends.
Quick start
import asyncio
from bibliofabric.nihreporter import NihReporterClient, ProjectFilters
async def main() -> None:
async with NihReporterClient() as client:
page = await client.projects.search(
filters=ProjectFilters(fiscal_years=[2023], org_states=["VT"]),
page_size=5,
)
print(page.total, "projects")
for project in page:
print(
" ",
project.appl_id,
project.project_title[:60],
project.organization.org_name if project.organization else None,
)
pubs = await client.publications.search(
filters={"core_project_nums": ["UG1HD078437"]}, page_size=5
)
print(pubs.total, "publications")
for publication in pubs:
print(" ", publication.pmid, publication.core_project_num)
asyncio.run(main())
The same calls exist on NihReporterSyncClient without async and await:
from bibliofabric.nihreporter import NihReporterSyncClient, ProjectFilters
with NihReporterSyncClient() as client:
page = client.projects.search(
filters=ProjectFilters(fiscal_years=[2023], org_states=["VT"]),
page_size=5,
)
for project in page:
print(project.appl_id, project.project_num)
What the routes serve
The API has two routes and the client wraps both:
| Route | Resource | Operations |
|---|---|---|
POST /v2/projects/search |
client.projects |
search, iterate, collect, first, count, batch_get |
POST /v2/publications/search |
client.publications |
search, iterate, collect, first, count, batch_get |
get() and exists() raise ConfigurationError on both resources, because
the API has no single-record route. batch_get() reads through the search
route: pass field="appl_id" on projects and field="pmid" or
"core_project_num" on publications. A publication id matches several
records (one publication appears once per linked project), so the
publications resource batches one id per request and batch_get() returns
one record per id.
A sample run of the quick start prints:
151 projects
10617263 Host-pathogen interactions in Bordetella infection UNIVERSITY OF VERMONT
...
54 publications
24806181 UG1HD078437
...
Where to go next
- Upstream quirks documents the paging caps, the
CamelCase
include_fieldsnames, and the other surprises of the API. - API reference lists every model and resource member.
- Runnable scripts live in
packages/bibliofabric/examples/nihreporter/.