Skip to content

NSF Award Search API reference

Generated from the source with mkdocstrings. Every name below is importable from bibliofabric.nsfawards; nested value models stay importable from bibliofabric.nsfawards.models.

Client

bibliofabric.nsfawards.NsfAwardsClient

Client for the NSF Award Search APIs.

The v1 award routes and the v2 lookup routes share one base URL and need no credentials. The client sends Accept: application/json on every request.

awards: AwardsResource cached property

The award resource: search, by-id, project outcomes, facets.

lookups: LookupsResource cached property

The v2 lookup resource: vocabularies and record searches.

exports: ExportsResource cached property

The fiscal-year export files of the award search site.

Settings

bibliofabric.nsfawards.NsfAwardsSettings

NSF Award Search client settings.

Inherits timeout, max_retries, max_retry_wait, max_requests_per_second, max_concurrency, user_agent and mailto from :class:bibliofabric.config.BaseApiSettings. The API needs no credentials: every award, lookup, and export route answers without a key.

Resources

bibliofabric.nsfawards.AwardsResource

Client for award records: search, by-id, project outcomes, facets.

The search route requires offset + rpp to stay at or under the 10,000-record window, and broad queries report a display-capped total of 10,000. get() fetches v1/awards/{id}.json; unknown ids answer an empty record list with HTTP 200, which raises :class:NotFoundError. exists() uses the same read because the gateway answers HEAD 200 for every id, present or not.

exists(id: str | int) -> bool async

Return True when the id answers an award record.

The gateway answers every HEAD with 200, so the probe reads the by-id route instead.

project_outcomes(id: str | int, *, params: dict[str, Any] | None = None) -> Award async

Fetch the project outcomes report record of one award.

The route answers the same body as get() today, with the outcomes report carried in project_outcomes_report.

refine(filters: dict[str, Any] | None = None, *, query: str | None = None, params: dict[str, Any] | None = None) -> dict[str, list[RefineBucket]] async

Fetch the facet buckets of a search on v2/refine.

The answer maps filter field names, for example inst.ctry_code or org_code_dir, to buckets of key and docCount. The filters travel as raw query parameters under the v2 field names, since the route shares its grammar with the award search web UI rather than the v1 filter list.

bibliofabric.nsfawards.LookupsResource

Client for the fixed vocabularies and the lookup searches.

org_names() -> dict[str, str] async

Map NSF organization codes to long names.

states() -> dict[str, str] async

Map state and territory codes to names.

countries() -> dict[str, str] async

Map country codes to names.

instruments() -> dict[str, str] async

Map transaction type codes to names.

congressional_districts(state_code: str) -> list[str] async

List the congressional district codes of one state.

principal_investigators(query: str, limit: int = _LOOKUP_LIMIT) -> list[PrincipalInvestigator] async

Find people whose names match query.

institutions(query: str, limit: int = _LOOKUP_LIMIT) -> list[Institution] async

Find institutions whose names match query.

programs(query: str, limit: int = _LOOKUP_LIMIT) -> list[Program] async

Find funding programs whose names match query.

program_elements(query: str, *, include_admin: bool = False, limit: int = _LOOKUP_LIMIT) -> list[ProgramElement] async

Find program elements whose names match query.

include_admin adds the administrative program elements the web UI keeps behind a toggle.

program_references(query: str, limit: int = _LOOKUP_LIMIT) -> list[ProgramReference] async

Find program references matching query.

Live queries returned an empty list for every tested input; the route answers 200 with an empty list rather than an error.

bibliofabric.nsfawards.ExportsResource

Client for the fiscal-year award export files.

list_files() -> S3FileList async

List the export files with their sizes and download URLs.

A historical year is a few kilobytes; a recent year is over 150 MB. Check size before downloading.

download(file_name: str, dest: Path | str) -> Path async

Stream one export file from the listing to dest.

The presigned URL comes from the listing, so this method requests the listing first. An interrupted download leaves no partial file behind; the path is returned. Read the archive with :func:bibliofabric.nsfawards.iter_export_awards.

Sync twins

NsfAwardsSyncClient, AwardsSyncResource, LookupsSyncResource, and ExportsSyncResource are the generated sync twins of the classes above, with the same methods without async and await. See Async and sync clients.

Models

bibliofabric.nsfawards.Award

One NSF award record of the v1 API.

Amount fields arrive as strings or integers; the Y/N flags arrive as strings or booleans. The person lists arrive as lists, and a scalar string becomes a one-element list. Dates use mm/dd/yyyy.

bibliofabric.nsfawards.AwardFilters

Filters for AwardsResource.search() and iterate().

Every field is optional; omitted fields leave the criterion out of the query. The API accepts one value per criterion except where a sequence is documented.

bibliofabric.nsfawards.CodeNameMap

A code-to-name map: organizations, states, countries, instruments.

bibliofabric.nsfawards.CongressionalDistricts

The congressional district codes of one state.

bibliofabric.nsfawards.ExportAward

One award of a downloaded export file.

The export format differs from the v1 API records: snake_case keys, ISO dates, and nested objects for the institution, the performance site, the investigators, and the funding sources. pgm_ref stays a raw dict list because its non-null record shape is unverified.

bibliofabric.nsfawards.ExportFile

One entry of the award export listing.

bibliofabric.nsfawards.ExportFund

One funding source of an export record.

bibliofabric.nsfawards.ExportInstitution

The awardee institution of an export record.

bibliofabric.nsfawards.ExportObligation

One fiscal-year obligation of an export record.

bibliofabric.nsfawards.ExportPerformanceSite

The performance site of an export record.

bibliofabric.nsfawards.ExportPrincipalInvestigator

One principal investigator of an export record.

bibliofabric.nsfawards.ExportProgramElement

One program element of an export record.

bibliofabric.nsfawards.Institution

One organization record of the institutionsLookup route.

bibliofabric.nsfawards.JournalArticle

One publication linked to an award through the jrnl field.

bibliofabric.nsfawards.PrincipalInvestigator

One person record of the piLookup route.

bibliofabric.nsfawards.Program

One program record of the programsLookup route.

bibliofabric.nsfawards.ProgramElement

One program element record of the pgmElesLookup route.

bibliofabric.nsfawards.ProgramReference

One program reference record of the pgmRefsLookup route.

Live queries returned an empty list for every tested input, so only the code key the web UI reads is typed; the rest stays in extra.

bibliofabric.nsfawards.RefineBucket

One facet bucket of a refine answer.

bibliofabric.nsfawards.RefineResponse

The facet buckets of a refine answer, keyed by filter field.

bibliofabric.nsfawards.S3FileList

The award export listing of the s3/list-files route.

bibliofabric.nsfawards.ServiceNotification

One entry of the serviceNotification error list.

Dialect constants

NSFAWARDS_DIALECT declares the paging names of the search route (offset, rpp, the 3,000 page-size clamp, and the offset + rpp <= 10000 window that NSFAWARDS_MAX_WINDOW names). NSFAWARDS_API_BASE_URL is https://api.nsf.gov/services. SORT_FIELDS lists the sortKey values and NSFAWARDS_ITERATE_PAGE_SIZE, NSFAWARDS_MAX_PAGE_SIZE, and NSFAWARDS_MAX_OFFSET carry the limits. They are exported for inspection, not for composition.

Helpers

bibliofabric.nsfawards.iter_export_awards(path: Path | str) -> Iterator[ExportAward]

Yield the award records of a downloaded export file.

Each fiscal-year export is a zip with one JSON file per award. The reader walks the zip entries in their stored order, so memory use stays flat on the multi-hundred-MB files. A record that fails validation raises :class:bibliofabric.ValidationError with the raw record attached.