NSF Award Search
bibliofabric.nsfawards is a Python client for the NSF Award Search APIs: the v1 award routes on api.nsf.gov and the v2 lookup routes that back the award search web site. It covers award search with filters, award records by id, project outcomes, search facets, the fixed vocabularies, and the fiscal-year award export files. Every call returns typed Pydantic models, and the client ships as an async class plus a generated sync twin.
The APIs need no credentials, and the award data is United States public domain.
Quick start
import asyncio
from bibliofabric.nsfawards import AwardFilters, NsfAwardsClient
async def main() -> None:
async with NsfAwardsClient() as client:
page = await client.awards.search(query="robotics", page_size=5)
print("total reported:", page.total)
for award in page.results:
print(award.id, award.awardee_name, "-", award.title)
award = await client.awards.get("1052893")
print(award.title, award.estimated_total_amt)
page = await client.awards.search(
filters=AwardFilters(awardee_state_code="MT", active_awards=True),
page_size=3,
)
print("active awards in Montana:", page.total)
asyncio.run(main())
Sync quick start
NsfAwardsSyncClient 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.nsfawards import NsfAwardsSyncClient
with NsfAwardsSyncClient() as client:
award = client.awards.get("1052893")
print(award.title, award.estimated_total_amt)
What the client offers
| Attribute | Routes | Common methods | Client-specific methods |
|---|---|---|---|
client.awards |
GET /v1/awards.json, GET /v1/awards/{id}.json, GET /v1/awards/{id}/projectoutcomes.json, GET /v2/refine |
search, iterate, collect, first, count, get, exists; batch_get raises ConfigurationError |
project_outcomes, refine |
client.lookups |
GET /v2/orgNames, /v2/states, /v2/countries, /v2/instruments, /v2/congDistCodeByState/{state}, /v2/piLookup/{q}/{limit}, /v2/institutionsLookup/{q}/{limit}, /v2/programsLookup/{q}/{limit}, /v2/pgmElesLookup/{q}/{includeAdmin}/{limit}, /v2/pgmRefsLookup/{q}/{limit} |
none of the common methods | org_names, states, countries, instruments, congressional_districts, principal_investigators, institutions, programs, program_elements, program_references |
client.exports |
GET /v2/s3/list-files, presigned S3 download |
none of the common methods | list_files, download |
search and iterate accept filters=AwardFilters(...) with the documented v1 criteria: awardee and performance location fields, date ranges, amount ranges, program codes, transaction types, and the active and historical award flags. query becomes the keyword parameter. Dates serialize to the mm/dd/yyyy form the API requires, and multi-value criteria serialize to the comma-joined lists the API documents.
Search pages with offset and rpp. The server accepts rpp up to 3000, and one query reaches at most 10,000 records: a request whose offset + rpp exceeds that window fails. The client rejects it with ConfigurationError before sending, and iterate() walks the window in pages of 2500. Broad queries report a display-capped total of 10,000 rather than the true match count.
Export files
NSF publishes one zipped JSON export per fiscal year on the download page. The client lists the files, downloads a file through its presigned URL, and reads the archive:
from bibliofabric.nsfawards import NsfAwardsSyncClient, iter_export_awards
with NsfAwardsSyncClient() as client:
files = client.exports.list_files()
zips = [item for item in files.files if (item.file_name or "").endswith(".zip")]
small = min(zips, key=lambda f: f.size or 0)
print(small.file_name, small.size)
path = client.exports.download(small.file_name, small.file_name)
awards = list(iter_export_awards(path))
print(awards[0].awd_id, awards[0].inst.inst_name)
A historical year is a few kilobytes; a recent year is over 150 MB. Check size before downloading. iter_export_awards yields ExportAward records and reads the archive entry by entry, so memory use stays flat on the large files.
Examples
Runnable scripts live in packages/bibliofabric/examples/nsfawards/:
quickstart.pysearches, fetches one award, and lists facet buckets.export_years.pylists the export files, downloads a small year, and reads it.
Next
- Upstream quirks lists where the live APIs differ from their documentation.
- The API reference is generated from the source.