Skip to content

API reference

Generated from the source with mkdocstrings.

Client

opcitato.OpcitatoClient

Bases: BaseApiClient

Client for the OpenCitations Index API v2, the Meta API v1, and SPARQL.

The APIs need no credentials. The documented limit is 180 requests per minute per IP address, which the settings pace to 3 requests per second. OpenCitations hands out a free Access Token by email and uses it to count unique users; the token travels in an authorization header, and this client does not manage one. To send one, pass a prepared httpx.AsyncClient that carries the header. The client sends Accept: application/json on every request; format="csv" selects the CSV representation regardless of that header. The two SPARQL endpoints live on a second host and share the request pacing.

index cached property

The Index API resource client (citations, references, counts, SPARQL).

meta cached property

The Meta API resource client (metadata, authors, editors, SPARQL).

Sync client

opcitato.OpcitatoSyncClient

Bases: SyncBaseApiClient

Client for the OpenCitations Index API v2, the Meta API v1, and SPARQL.

The APIs need no credentials. The documented limit is 180 requests per minute per IP address, which the settings pace to 3 requests per second. OpenCitations hands out a free Access Token by email and uses it to count unique users; the token travels in an authorization header, and this client does not manage one. To send one, pass a prepared httpx.AsyncClient that carries the header. The client sends Accept: application/json on every request; format="csv" selects the CSV representation regardless of that header. The two SPARQL endpoints live on a second host and share the request pacing.

index cached property

The Index API resource client (citations, references, counts, SPARQL).

meta cached property

The Meta API resource client (metadata, authors, editors, SPARQL).

Settings

opcitato.OpcitatoSettings

Bases: BaseApiSettings

OpenCitations 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 documented pace (3 req/s, concurrency 3). The APIs need no credentials.

Resource clients

opcitato._async.resources.IndexClient

The read operations of the OpenCitations Index API v2.

Every operation sends one GET and returns the complete result; the API has no paging. citations and references accept require, filter, sort, and format; filter entries look like creation:>2019-12 (a regular expression, or =, <, > with a value), and sort looks like desc(creation). The SPARQL endpoint of the Index dataset answers arbitrary queries through :meth:sparql and :meth:sparql_text.

citation(oci) async

Return the one citation with this Open Citation Identifier.

oci is the two dash-separated numbers without the oci: prefix (06101801781-06180334099); a value with the prefix is accepted and stripped. Returns None when no citation carries the identifier.

citation_count(id) async

Return the number of incoming citations of one entity.

An unknown identifier answers 0: the API returns a zero row with status 200 (verified 2026-11-28). None means the API answered an empty list, which it did for unknown identifiers on 2026-11-27.

citations(id, *, require=None, filter=None, sort=None, format='json') async

Return the incoming citations of one entity.

Every row records a reference in which cited identifies the entity. id is a prefixed identifier (doi:, omid:, pmid:, issn:, or isbn:); an unknown identifier answers with an empty list. require drops rows whose field is empty, filter keeps matching rows, sort orders them, and format="csv" asks the server for the CSV representation.

reference_count(id) async

Return the number of outgoing references of one entity.

An unknown identifier answers 0; see :meth:citation_count.

references(id, *, require=None, filter=None, sort=None, format='json') async

Return the outgoing references of one entity.

Every row records a reference of the reference list in which citing identifies the entity. The parameters behave exactly as in :meth:citations.

sparql(query, *, method='GET', timeout=None) async

Run a SPARQL SELECT or ASK query on the Index dataset.

The endpoint is https://sparql.opencitations.net/index. A SELECT answer fills results, and rows() on the result returns the bindings as plain strings. An ASK answer fills boolean. The meta member carries the query time and the number of rows.

method="POST" sends the query in the request body, which has no length limit. A malformed query answers 400 and raises :class:~bibliofabric.exceptions.APIError with the server's message in the body.

sparql_text(query, *, format='turtle', method='GET', timeout=None) async

Run a SPARQL query and return the raw body as text.

format selects the representation through the Accept header: json, xml, csv, tsv, turtle, or n-triples. CONSTRUCT and DESCRIBE answers are RDF, so use this method for them: the endpoint answers Turtle for a CONSTRUCT query that asks for the JSON representation (verified 2026-11-28).

venue_citation_count(issn) async

Return the number of incoming citations to a whole venue.

issn is an issn:-prefixed identifier; this is the only scheme the operation accepts. An unknown identifier answers 0; see :meth:citation_count.

opcitato._async.resources.MetaClient

The read operations of the OpenCitations Meta API v1.

The rows share the shape of :class:~opcitato.models.MetadataRecord; missing values are empty strings. The row-shaping parameters behave as in the Index API. The SPARQL endpoint of the Meta dataset answers arbitrary queries through :meth:sparql and :meth:sparql_text.

author(id, *, require=None, filter=None, sort=None, format='json') async

Return the entities the person with this identifier authored.

id is orcid:0000-0002-8420-0696 or the OpenCitations id of a responsible entity (omid:ra/0601).

editor(id, *, require=None, filter=None, sort=None, format='json') async

Return the entities the person with this identifier edited.

id is an orcid: or omid:ra/ identifier, as in :meth:author.

metadata(ids, *, require=None, filter=None, sort=None, format='json') async

Return the bibliographic metadata of one or more entities.

ids is one prefixed identifier or a list of them; the accepted schemes are doi, issn, isbn, omid, openalex, pmid, and pmcid. Several identifiers are packed into one request with the __ separator, and one answer row comes back per identifier found. An unknown identifier contributes no row.

sparql(query, *, method='GET', timeout=None) async

Run a SPARQL SELECT or ASK query on the Meta dataset.

The endpoint is https://sparql.opencitations.net/meta. The answer follows the same shape as in :meth:IndexClient.sparql.

sparql_text(query, *, format='turtle', method='GET', timeout=None) async

Run a SPARQL query and return the raw body as text.

The parameters behave exactly as in :meth:IndexClient.sparql_text.

Dialect and helpers

opcitato.dialect

OpenCitations dialect constants.

Both REST APIs are served by one host and are built with RAMOSE, so they share the row-shaping parameters (require, filter, sort, format, json) and the documented rate limit. Each dataset also has a SPARQL endpoint on a second host. The resource clients that consume these constants live in :mod:opcitato._async (their sync twins are generated from them).

OPENCITATIONS_API_BASE_URL = 'https://api.opencitations.net' module-attribute

INDEX_API_PATH = 'index/v2' module-attribute

INDEX_SPARQL_URL = 'https://sparql.opencitations.net/index' module-attribute

META_API_PATH = 'meta/v1' module-attribute

META_SPARQL_URL = 'https://sparql.opencitations.net/meta' module-attribute

MULTI_ID_SEPARATOR = '__' module-attribute

FORMATS = frozenset({'json', 'csv'}) module-attribute

INDEX_ID_SCHEMES = frozenset({'omid', 'doi', 'pmid', 'issn', 'isbn'}) module-attribute

META_ID_SCHEMES = frozenset({'doi', 'issn', 'isbn', 'omid', 'openalex', 'pmid', 'pmcid'}) module-attribute

PERSON_ID_SCHEMES = frozenset({'orcid', 'omid'}) module-attribute

opcitato.ids.parse_identifiers(text)

Split a space-separated identifier string into typed identifiers.

"omid:br/06120344846 doi:10.1038/nature12373" becomes two :class:ParsedIdentifier entries. Raises :class:ConfigurationError when a part carries no scheme: prefix, because every identifier OpenCitations returns is prefixed and a bare part would hide an upstream format change.

opcitato.ids.ParsedIdentifier dataclass

One prefixed identifier of an OpenCitations record.

scheme is the lowercase prefix (doi, omid, pmid, openalex, issn, isbn, pmcid, or orcid) and value the identifier without the prefix (an OMID keeps its br/ or ra/ part, as in br/06120344846).

opcitato.ids.normalize_index_id(value)

Validate one Index API identifier for the URL path.

Accepts the schemes the Index API documents (omid, doi, pmid, issn, isbn) and returns the identifier percent-encoded. Raises :class:ConfigurationError for a bare id or an unsupported scheme, which the API would answer with 400.

opcitato.ids.normalize_issn(value)

Validate that value is an issn: id, as the venue count route needs.

opcitato.ids.normalize_meta_ids(value)

Validate Meta identifiers and join them with the __ separator.

Accepts one identifier or a list of them (a single string may already carry the __ separator). Each identifier must use a scheme the Meta /metadata operation documents, and comes back percent-encoded. Raises :class:ConfigurationError otherwise.

opcitato.ids.normalize_person_id(value)

Validate a Meta person identifier (orcid:... or omid:ra/...).

Raises :class:ConfigurationError for any other scheme.

opcitato.ids.normalize_oci(value)

Normalize an Open Citation Identifier to its first-second form.

The oci: prefix is optional on input and is never sent, because the Index /citation/{oci} operation expects the bare numbers. Raises :class:ConfigurationError for any other shape.

opcitato.csvparse.parse_csv_rows(text)

Parse an OpenCitations CSV table into row dictionaries.

Short rows are padded with empty strings, exactly like the JSON representation fills unknown fields with "". A None key (a row longer than the header) is dropped, because no model field can receive it.

opcitato.unwrapper.OpcitatoUnwrapper

Reads results, totals, and metadata from OpenCitations JSON lists.

item(body)

Return the first row of the list.

Raises :class:NotFoundError when the list is empty, which is how the APIs answer an unknown identifier.

meta(body)

Return {}; a top-level list carries no envelope metadata.

next_cursor(body)

Return None; no operation of either API pages its results.

results(body)

Return the row objects of a top-level list, in order.

total(body)

Return the length of the result list (the complete result set).

Models

The models live in opcitato.models and are re-exported from the top-level package. They are plain Pydantic models with extra="allow".

opcitato.models.Citation

Bases: BaseModel

One citation row of the Index API.

citing and cited hold the identifiers of the citing and the cited entity, space-separated and each prefixed with its scheme (omid:br/06120344846 doi:10.1038/nature12373 pmid:23903748). creation is the publication date of the citing entity in ISO format and may be partial (2013 or 2013-07). timespan is the XSD duration between the publication dates and can be negative (-P1Y1M16D). journal_sc and author_sc are "yes" or "no" strings that report a journal self-citation and an author self-citation.

citing_identifiers property

The identifiers of the citing entity, parsed from citing.

cited_identifiers property

The identifiers of the cited entity, parsed from cited.

opcitato.models.Count

Bases: BaseModel

The one row a count operation returns.

The JSON representation carries the number as a string ({"count": "1806"}) even though the documentation types it as int; :attr:count coerces it.

opcitato.models.MetadataRecord

Bases: BaseModel

One bibliographic metadata row of the Meta API.

id holds all known identifiers of the entity, space-separated and prefixed (doi:10.1038/nature12373 pmid:23903748 omid:br/06120344846). author and editor are semicolon-separated lists of person strings such as Peroni, Silvio [orcid:0000-0003-0530-4305 omid:ra/0614010840729]; venue is the venue title followed by its identifiers in brackets. Missing values are empty strings.

identifiers property

The identifiers of the entity, parsed from id.

authors property

The author field split into person strings.

editors property

The editor field split into person strings.

opcitato.models.SparqlResult

Bases: BaseModel

A SPARQL 1.1 JSON result as the endpoints answer sparql-results+json.

A SELECT answer carries head and results. An ASK answer carries head and boolean. OpenCitations adds a meta object with the query time (query-time-ms) and the number of rows (result-size-total).

rows()

Return the bindings as plain variable -> value strings.

An ASK answer has no bindings and returns []; read :attr:boolean for it.

opcitato.models.SparqlTerm

Bases: BaseModel

One typed term of a result row.

type is uri, literal, or bnode. A literal can carry a datatype (an XSD datatype IRI) or a language tag (xml:lang in the payload, :attr:xml_lang on the model).

opcitato.models.SparqlHead

Bases: BaseModel

The head member: the result variables.

opcitato.models.SparqlResults

Bases: BaseModel

The results member with its bindings rows.