Skip to content

NASA ADS

The NASA ADS client (bibliofabric.nasads) searches the NASA Astrophysics Data System and exports records as citation formats: keyword and bibcode searches over 30 years of astronomy and physics literature, list queries through search/bigquery, query tokenization, and BibTeX, AASTeX, RIS, and XML exports. Every call returns typed Pydantic models, and the client paces itself inside the ADS daily quotas. Install bibliofabric first if you have not (setup). An async client and a generated sync twin share the same API.

Verification status

This client was built from the published API documentation (the developer API repository and the help pages) without a live check, because no ADS token was available while building it. The request and answer shapes follow the recorded responses in that documentation. Run the example scripts in packages/bibliofabric/examples/nasads/ against your own token before a production harvest, and read upstream quirks for the parts a token should confirm first.

Credentials

Every route needs a token. Get one at ui.adsabs.harvard.edu/user/settings/token and set it as the NASADS_API_TOKEN environment variable, or put it in your .env file:

export NASADS_API_TOKEN="your-token"

The token travels as an Authorization: Bearer header on every request. ADS meters daily quotas per endpoint and reports them in the X-RateLimit-* response headers, reset at midnight UTC; the bigquery route allows about 100 requests per day. The client sends at most 1 request per second on one connection by default (NASADS_MAX_REQUESTS_PER_SECOND, NASADS_MAX_CONCURRENCY).

The client refuses to start without a token.

Quick start

import asyncio

from bibliofabric.nasads import NasAdsClient, RecordFilters


async def main():
    async with NasAdsClient() as client:
        record = await client.records.get("2018Sci...359.1453C")
        print(record.title[0], f"({record.year})")

        filters = RecordFilters(database="astronomy", property="refereed")
        page = await client.records.search(
            filters,
            query="exoplanet atmospheres",
            select=["bibcode", "title", "citation_count"],
            sort="citation_count:desc",
            page_size=5,
        )
        print(f"{page.total} matches")
        for result in page.results:
            print(result.bibcode, result.citation_count)

        result = await client.exports.export(
            [r.bibcode for r in page.results], output_format="bibtex"
        )
        print(result.export)


asyncio.run(main())

The script fetches one record by bibcode, runs one filtered search sorted by citations, and exports the page as BibTeX. A record carries exactly the fields the search asked for in select; records.get() requests the common bibliographic fields when you pass none.

Sync quick start

from bibliofabric.nasads import NasAdsSyncClient


with NasAdsSyncClient() as client:
    page = client.records.search(query="black holes", page_size=5)
    for result in page.results:
        print(result.bibcode)

Search and paging

The search API speaks the same syntax as Apache Solr, and the ADS search help lists the field and property names. The client accepts that syntax through query= (title:exoplanets, year:[2012 TO 2013]) and through RecordFilters, which turns each field into one fq filter (a list becomes field:(a OR b)).

Paging uses Solr cursorMark cursors. Pass sort= (a stable sort is required) and iterate:

async for record in client.records.iterate(
    query="black holes", sort="bibcode asc", limit=100
):
    print(record.bibcode)

Iteration stops when ADS repeats the cursor, which is its end-of-results signal. search(page=n) pages by the start offset instead. One page returns at most 2,000 records (rows).

Bigquery and tokens

records.bigquery() searches a list of up to 2,000 bibcodes in one request:

page = await client.records.bigquery(bibcodes, query="*:*", select=["bibcode", "title"])

The list filters the results of query; the default q=*:* returns the bibcodes themselves. The API applies its default page size of 10 regardless of the list size, so the client asks for as many rows as bibcodes. ADS allows about 100 bigquery requests per day.

tokens.parse() splits a query the way the search engine does, which helps explain a rejected query:

analysis = await client.tokens.parse('title:"transiting exoplanets"')
print([token.value for token in analysis.tokens])

Exports

exports.export() covers the tagged, LaTeX, and XML formats (bibtex, aastex, ris, dcxml, and more); exports.csl() and exports.custom() cover the two formats with extra required fields; exports.single() fetches one bibcode through the GET route. See reference.

Reference

The full operation and model list lives in reference; the ADS-specific behavior in upstream quirks.