API reference
Generated from the source with mkdocstrings.
Client
bibliofabric.nasads.NasAdsClient
Client for the NASA ADS Developer API.
The client paces itself at one request per second on one connection by
default, inside the per-endpoint daily quotas ADS reports in the
X-RateLimit-* response headers. Every route needs a token; see
:class:bibliofabric.nasads.config.NasAdsSettings.
records: RecordsResource
cached
property
The bibliographic record search resource.
tokens: TokensResource
cached
property
The query tokenization resource.
exports: ExportsResource
cached
property
The citation format export resource.
Sync client
bibliofabric.nasads.NasAdsSyncClient
Client for the NASA ADS Developer API.
The client paces itself at one request per second on one connection by
default, inside the per-endpoint daily quotas ADS reports in the
X-RateLimit-* response headers. Every route needs a token; see
:class:bibliofabric.nasads.config.NasAdsSettings.
records: RecordsSyncResource
cached
property
The bibliographic record search resource.
tokens: TokensSyncResource
cached
property
The query tokenization resource.
exports: ExportsSyncResource
cached
property
The citation format export resource.
The sync twins of the resource clients are exported from the package root
(RecordsSyncResource, TokensSyncResource, ExportsSyncResource). They
mirror the async resource clients method for method.
Settings
bibliofabric.nasads.NasAdsSettings
NASA ADS specific client settings.
Inherits timeout, max_retries, max_retry_wait,
max_requests_per_second, max_concurrency, rate_limits,
user_agent and mailto from
:class:bibliofabric.config.BaseApiSettings and sets NASA ADS defaults
(1 request per second, concurrency 1). Every route needs a token; get
one at https://ui.adsabs.harvard.edu/user/settings/token and set it as
api_token or through the NASADS_API_TOKEN environment variable.
api_token is a SecretStr; read it with get_secret_value().
ADS reports daily quotas per endpoint in the X-RateLimit-* response
headers, reset at midnight UTC; the bigquery route allows about 100
requests per day.
Resource clients
Each resource client inherits the generic operations from
bibliofabric.Resource (get, search, iterate, collect, first,
count, batch_get) through the client's internal NasAdsResource base.
Only class-specific members are shown here; records.exists and
records.batch_get, and every inherited operation of tokens and
exports except the ones listed, raise ConfigurationError.
bibliofabric.nasads.RecordsResource
Client for the search/query and search/bigquery endpoints.
iterate(filters: BaseModel | Mapping[str, Any] | None = None, *, query: str | None = None, sort: str | Sequence[str] | None = None, select: Sequence[str] | None = None, page_size: int | None = None, limit: int | None = None, cursor: str | None = None, on_error: OnError = 'raise', failures: list[ValidationError] | None = None, on_page: Callable[[int, str | None], Any] | None = None, params: Mapping[str, Any] | None = None) -> AsyncIterator[Doc]
Yield matching records using cursorMark paging.
Solr requires a deterministic sort containing the unique key
when cursorMark is used, so sort defaults to "id asc"
when omitted.
get(id: str | int, *, select: Sequence[str] | None = None, params: Mapping[str, Any] | None = None) -> Doc
async
Fetch one record by bibcode; an unknown bibcode raises
:class:NotFoundError.
The API has no single-record route, so the lookup is a q=bibcode:
search. Without select, the request asks for the common
bibliographic fields; pass select= for a different projection.
bigquery(bibcodes: Sequence[str], *, query: str = '*:*', sort: str | Sequence[str] | None = None, select: Sequence[str] | None = None, page: int | None = None, page_size: int | None = None, params: Mapping[str, Any] | None = None) -> Page[Doc]
async
Search a list of up to 2,000 bibcodes through search/bigquery.
The list of bibcodes filters the results of query; the default
q=*:* returns the bibcodes themselves. The API applies its
default rows of 10 regardless of the list size, so the request
asks for as many rows as bibcodes unless page_size says
otherwise. ADS allows about 100 bigquery requests per day.
bibliofabric.nasads.TokensResource
Client for the search/tokens endpoint.
The route splits a query string into the tokens the search engine
parses; it is not described in the ADS OpenAPI document, so only the
documented request parameter q is sent. :meth:parse is the only
supported operation.
parse(query: str, *, params: Mapping[str, Any] | None = None) -> TokenAnalysis
async
Return the tokens the search engine parses out of query.
bibliofabric.nasads.ExportsResource
Client for the export/{format} endpoints.
export(bibcodes: Sequence[str], *, output_format: ExportFormat = 'bibtex', sort: str | None = None, params: Mapping[str, Any] | None = None) -> ExportResult
async
Export bibcodes in one of the tagged, LaTeX, or XML formats.
sort uses the search sort grammar, as in "first_author asc";
the service sorts by date and then bibcode when it is omitted.
csl(bibcodes: Sequence[str], *, style: CslStyle, output_format: CslOutputFormat, journal_format: CslJournalFormat | None = None, sort: str | None = None, params: Mapping[str, Any] | None = None) -> ExportResult
async
Export bibcodes in a journal style encoded as Unicode, HTML, or LaTeX.
journal_format selects the journal-name style and applies to the
aastex, aspc, and aasj styles only.
custom(bibcodes: Sequence[str], format_string: str, *, sort: str | None = None, params: Mapping[str, Any] | None = None) -> ExportResult
async
Export bibcodes through a custom format string of format codes.
single(bibcode: str, *, output_format: ExportFormat = 'bibtex', params: Mapping[str, Any] | None = None) -> str
async
Export one bibcode through the GET route of output_format.
The route answers with the export itself rather than the
{"msg", "export"} object of the batch routes.
Filter models
The filter model dumps into one fq entry per set field and allows extra
fields.
bibliofabric.nasads.filters.RecordFilters
Filter criteria for the records search.
Values follow the Solr query syntax of the q parameter: a year
range reads "2012 TO 2013", a citation floor ">100", and a
phrase needs its quotes, as in 'Spergel, D.'.
bibstem: StrFilter = None
class-attribute
instance-attribute
Journal abbreviation such as ApJ.
database: StrFilter = None
class-attribute
instance-attribute
astronomy, physics, or general.
property: StrFilter = None
class-attribute
instance-attribute
Record flags such as refereed or openaccess.
Dialect and helpers
bibliofabric.nasads.dialect
NASA ADS query dialect constants.
NASADS_DIALECT tells bibliofabric how NASA ADS names its query
parameters. The resource-client base that consumes these constants lives in
:mod:bibliofabric.nasads._async.resources (its sync twin is generated from
it).
Behavior notes:
rowsaccepts 1 to 2,000; the API default is 10 and larger values are documented as capped at 2,000.- Offset paging uses 0-based
start. Cursor paging uses SolrcursorMark(start value*), which needs a stablesortand ends when the answer repeats the sent cursor asnextCursorMark. - Sorting is one string of
<field> <asc|desc>(a space, not a colon).iterate()pages by cursor, so it always sendssort; the caller must pass one.
NASADS_API_BASE_URL = 'https://api.adsabs.harvard.edu/v1'
module-attribute
NASADS_MAX_PAGE_SIZE = 2000
module-attribute
MAX_BIBCODES_PER_REQUEST = 2000
module-attribute
DEFAULT_SELECT_FIELDS = ('bibcode', 'title', 'author', 'abstract', 'doi', 'pub', 'pubdate', 'keyword', 'citation_count', 'property', 'identifier')
module-attribute
bibliofabric.nasads.unwrapper.NasAdsUnwrapper
Read records, totals, cursors, and metadata out of a Solr envelope.
item(body: Any) -> dict[str, Any]
Return the first record of the response.docs array, or {}.
The search API has no single-record route, so this only fires for callers that hand an answer body to a model directly.
meta(body: Any) -> dict[str, Any]
Return the envelope minus response.docs.
numFound, start, and nextCursorMark are flattened to the
top level next to responseHeader and highlighting.
next_cursor(body: Any) -> str | None
Return nextCursorMark from the top-level envelope, or None.
Live Solr returns nextCursorMark at the top level of the JSON
response; falls back to response.nextCursorMark if absent.
Absent means the search did not page by cursorMark; exhaustion
itself is reported by the cursor repeating, which the paging code
compares against the sent cursor.
results(body: Any) -> list[dict[str, Any]]
Return the records of the response.docs array, in order.
total(body: Any) -> int | None
Return response.numFound when it is an integer.
Models
bibliofabric.nasads.models.Doc
One bibliographic record of a search answer.
Which fields are populated depends on the fl the search asked for.
id is an internal, non-persistent integer served as a string; use
bibcode as the stable identifier.
bibliofabric.nasads.models.Token
One token of a parsed query.
The /search/tokens route is not described in the ADS OpenAPI
document; the model keeps the three fields the route is known to carry
and passes everything else through extra.
bibliofabric.nasads.models.TokenAnalysis
The parsed tokens of a query string.
bibliofabric.nasads.models.ExportResult
The answer of an export request.