Skip to content

API reference

Generated from the source with mkdocstrings.

Client

bibliofabric.arxiv.ArxivClient

Bases: BaseApiClient

Client for the arXiv API (https://export.arxiv.org/api).

The API needs no credentials and answers Atom XML, which the client parses into :class:bibliofabric.arxiv.ArxivEntry models. Requests are paced at one every three seconds over one connection, as the arXiv terms of use ask.

query cached property

The /query route: search, lookup by id, and paging.

default_headers property

Headers sent with every request: the Atom representation.

The sync client ArxivSyncClient and its QuerySyncClient mirror the async classes method for method.

Query client

bibliofabric.arxiv.QueryClient

Search and look up papers through /api/query.

query is the arXiv search syntax (ti:transformer AND cat:cs.CL, au:bengio, all:electron); ids restricts the results to arXiv ids. Both may be combined, as the API allows. Every result is one paper version as an :class:ArxivEntry.

batch_get(ids, *, on_error='raise', failures=None) async

Return the papers for many ids, keyed by the normalized input id.

Sends id_list requests of up to 100 ids and drops blank ids. An id without a version maps to the newest version of the paper; an id with one maps to that version. Unknown ids are absent from the result. With on_error="skip", entries that fail validation are dropped and recorded in failures.

collect(query=None, *, ids=None, sort_by=None, sort_order=None, page_size=100, limit=None, on_error='raise', failures=None) async

Collect iterate() output into a list, optionally bounded.

count(query=None, *, ids=None) async

Return opensearch:totalResults for a query (one 1-result request).

first(query=None, *, ids=None, sort_by=None, sort_order=None, on_error='raise', failures=None) async

Return the first matching entry, or None when there is none.

get(id) async

Return one paper by arXiv id, with or without a version.

Accepts 1706.03762, 1706.03762v1, hep-th/9711200, and arXiv: or https://arxiv.org/abs/ forms. Without a version the API answers the newest version. An unknown id raises :class:NotFoundError.

iterate(query=None, *, ids=None, sort_by=None, sort_order=None, page_size=100, limit=None, on_error='raise', failures=None) async

Yield every result, page by page, up to limit or 30,000.

Each page is one request, paced by the client settings (one request every three seconds by default). limit=0 yields nothing without a request; a negative limit raises ConfigurationError. ids go out in chunks of BATCH_SIZE ids, each chunk paged from start 0, and limit counts across all chunks.

search(query=None, *, ids=None, sort_by=None, sort_order=None, start=0, page_size=DEFAULT_PAGE_SIZE, on_error='raise', failures=None) async

Return one page of results.

start is the 0-based offset and page_size the max_results value (at most 2000). start + page_size may not pass 30,000, the documented reach of one query. page.total is opensearch:totalResults; page.meta holds the feed id, updated, start, and per_page. ids takes at most 100 ids; blank values are dropped.

Query helpers

bibliofabric.arxiv.clause(prefix, value)

Return one prefix:value clause of the arXiv search syntax.

The value is stripped; a value with whitespace is wrapped in double quotes, which arXiv reads as an exact phrase. Raises :class:ConfigurationError when the value is empty or contains a double quote, which the syntax has no escape for.

bibliofabric.arxiv.date_range(field, start=None, end=None)

Return field:[START TO END] with 12-digit GMT stamps.

A date bound becomes midnight (0000) for start and 2359 for end of that day; a datetime bound is converted to UTC; a naive datetime is read as GMT. A missing bound is filled with a concrete date the API accepts (arXiv's start, or 2099-12-31), because arXiv answers HTTP 500 for an open * bound.

bibliofabric.arxiv.combine(*clauses, operator='AND')

Join query clauses with operator between them.

operator is one of AND, OR, or ANDNOT. Raises :class:ConfigurationError for another operator or an empty clause list.

Unwrapper

bibliofabric.arxiv.ArxivUnwrapper

Extracts entries, totals, and metadata from a parsed feed.

item(body)

Return the first entry, or an empty dict for an empty feed.

meta(body)

Return the feed fields other than the entries.

next_cursor(body)

Return None; the API pages by start offset.

results(body)

Return the entry dicts in feed order.

total(body)

Return opensearch:totalResults.

Settings

bibliofabric.arxiv.ArxivSettings

Bases: BaseApiSettings

arXiv-specific client settings.

Inherits timeout, max_retries, max_retry_wait, max_requests_per_second, max_concurrency, user_agent and mailto from :class:bibliofabric.config.BaseApiSettings and sets the arXiv terms of use as defaults: one request every three seconds over one connection. The API needs no credentials.

bibliofabric.arxiv.get_settings() cached

Return the process-wide settings, loaded once from the environment.

Models

bibliofabric.arxiv.ArxivEntry

Bases: BaseModel

One paper version from the arXiv query API.

id is the abstract URL of the version the feed returned (http://arxiv.org/abs/1706.03762v7); :attr:arxiv_id and :attr:version split it. published is the date of version 1 and updated the date of this version.

arxiv_id property

The id without its version, such as 1706.03762.

author_names property

The author names in feed order.

pdf_url property

The URL of the PDF of this version.

version property

The version number, such as 7.

versioned_id property

The id with its version, such as 1706.03762v7.

bibliofabric.arxiv.ArxivAuthor

Bases: BaseModel

One author of an entry with the affiliations arXiv knows.

Bases: BaseModel

One link element: the abstract page, the PDF, or the DOI.

Atom parser

bibliofabric.arxiv.parse_feed(text)

Return the feed as {"id", "updated", "total", "start", "per_page", "entries"}.

Raises :class:APIError when the body is not XML or its root element is not an Atom feed (an HTML maintenance page, for example). Raises :class:ConfigurationError when the feed is an error feed (an entry whose id starts with an arXiv API error URL), because the API answers that for malformed ids and queries.

Constants

Name Value Meaning
ARXIV_API_BASE_URL https://export.arxiv.org/api Base URL; /query below it is the one read route
DEFAULT_PAGE_SIZE 10 Default page_size of search(), as on the API
MAX_RESULTS_PER_PAGE 2000 Largest page_size one request may ask for
MAX_TOTAL_RESULTS 30000 Reach of one query through start and max_results
SORT_BY relevance, lastUpdatedDate, submittedDate Values of the sortBy parameter
SORT_ORDER ascending, descending Values of the sortOrder parameter
BATCH_SIZE 100 Ids per id_list request in batch_get() and iterate()
ERROR_ID_PREFIXES http://arxiv.org/api/errors, https://arxiv.org/api/errors Entry id prefixes that mark an error feed