Skip to content

API reference

Generated from the source with mkdocstrings.

Client

hodoi.HodoiClient

Bases: BaseApiClient

Client for the DOI System proxy server at https://doi.org.

The proxy needs no credentials. It resolves DOIs (resolve, locations), looks up registration agencies (/ra/), serves Handle.net records (/api/handles/), and negotiates metadata representations on plain DOI URLs (content, raw).

Redirects stay off by default so a caller can inspect the resolver's 302 response. :meth:content turns them on for the request it sends.

agencies(dois) async

Return the registration agency of one or many DOIs.

Sends GET /ra/{doi} with the DOIs joined by commas. A request carries at most :data:~hodoi.dialect.RA_BATCH_SIZE DOIs and stays under :data:~hodoi.dialect.RA_MAX_PATH_CHARS characters, so a long list takes several requests. Every entry arrives as HTTP 200: known DOIs carry RA, unknown ones a status string, both modeled as :class:~hodoi.models.AgencyAnswer. The result order follows the request order across requests. The argument takes a bare DOI, a DOI URL, or a doi: string; anything else is sent as given, and the proxy answers Invalid DOI.

agency(doi) async

Return the registration agency answer for one DOI.

handle(doi, *, index=None, type=None, auth=False, cert=False) async

Return the Handle.net record of a DOI.

Sends GET /api/handles/{doi} and validates the answer into :class:~hodoi.models.HandleRecord. index and type restrict the returned values; each takes one value or a list, and the proxy answers the values that match any of them. auth=True bypasses the proxy cache and asks the primary handle server; cert=True asks for an authenticated answer from it. An unknown DOI answers HTTP 404, which raises :class:bibliofabric.exceptions.NotFoundError.

landing_url(doi) async

Return the landing page URL stored in the DOI's handle record.

Reads the URL entry of the record without fetching the landing page itself. A DOI whose record has no URL value raises :class:bibliofabric.exceptions.ConfigurationError; :meth:locations lists the URLs of a multiple-resolution DOI.

resolve(doi) async

Return the proxy's answer to GET https://doi.org/{doi}.

The request asks for text/html, so the proxy answers 302 with the landing page URL in the Location header and a small HTML body titled "Handle Redirect". Redirects follow the follow_redirects setting (off by default), so the response is the 302 itself unless the setting is on. An unknown DOI answers 404, which raises :class:bibliofabric.exceptions.NotFoundError.

locations(doi) async

Return every URL the proxy could redirect a DOI to.

Sends GET https://doi.org/{doi}?action=showurls, the proxy's XML listing. An ordinary DOI has two entries: the landing page (mode="legacy") and the registration agency's metadata server (http_role="conneg", with a href_template). A multiple-resolution DOI lists its further locations. An unknown DOI answers 404, which raises :class:bibliofabric.exceptions.NotFoundError.

content(doi, media_type) async

Return the negotiated metadata representation for a DOI.

Sends GET https://doi.org/{doi} with the given Accept header and follows the resolver's redirect to the registration agency's data server. The three JSON media types parse into typed models (:class:~hodoi.models.CslItem for :data:~hodoi.media_types.CSL_JSON, :class:~hodoi.models.DataciteRecord for :data:~hodoi.media_types.DATACITE_JSON, :class:~hodoi.models.SchemaOrgThing for :data:~hodoi.media_types.SCHEMAORG_JSONLD); every other media type (BibTeX, RIS, the XML dialects, a formatted citation) returns as text. The answer is None when the agency reports 204, which means that no metadata is available. A media type the agency does not answer raises :class:bibliofabric.exceptions.APIError with its HTTP 406.

raw(doi, media_type, *, follow_redirects=None) async

Return the un-parsed bytes of a negotiated representation.

follow_redirects=None keeps the client setting (off), so the bytes are the resolver's 302 body ("Handle Redirect"); pass follow_redirects=True to receive the agency's metadata bytes. To read the Location header of the 302, use :meth:resolve.

Sync client

hodoi.HodoiSyncClient

Bases: SyncBaseApiClient

Client for the DOI System proxy server at https://doi.org.

The proxy needs no credentials. It resolves DOIs (resolve, locations), looks up registration agencies (/ra/), serves Handle.net records (/api/handles/), and negotiates metadata representations on plain DOI URLs (content, raw).

Redirects stay off by default so a caller can inspect the resolver's 302 response. :meth:content turns them on for the request it sends.

agencies(dois)

Return the registration agency of one or many DOIs.

Sends GET /ra/{doi} with the DOIs joined by commas. A request carries at most :data:~hodoi.dialect.RA_BATCH_SIZE DOIs and stays under :data:~hodoi.dialect.RA_MAX_PATH_CHARS characters, so a long list takes several requests. Every entry arrives as HTTP 200: known DOIs carry RA, unknown ones a status string, both modeled as :class:~hodoi.models.AgencyAnswer. The result order follows the request order across requests. The argument takes a bare DOI, a DOI URL, or a doi: string; anything else is sent as given, and the proxy answers Invalid DOI.

agency(doi)

Return the registration agency answer for one DOI.

handle(doi, *, index=None, type=None, auth=False, cert=False)

Return the Handle.net record of a DOI.

Sends GET /api/handles/{doi} and validates the answer into :class:~hodoi.models.HandleRecord. index and type restrict the returned values; each takes one value or a list, and the proxy answers the values that match any of them. auth=True bypasses the proxy cache and asks the primary handle server; cert=True asks for an authenticated answer from it. An unknown DOI answers HTTP 404, which raises :class:bibliofabric.exceptions.NotFoundError.

landing_url(doi)

Return the landing page URL stored in the DOI's handle record.

Reads the URL entry of the record without fetching the landing page itself. A DOI whose record has no URL value raises :class:bibliofabric.exceptions.ConfigurationError; :meth:locations lists the URLs of a multiple-resolution DOI.

resolve(doi)

Return the proxy's answer to GET https://doi.org/{doi}.

The request asks for text/html, so the proxy answers 302 with the landing page URL in the Location header and a small HTML body titled "Handle Redirect". Redirects follow the follow_redirects setting (off by default), so the response is the 302 itself unless the setting is on. An unknown DOI answers 404, which raises :class:bibliofabric.exceptions.NotFoundError.

locations(doi)

Return every URL the proxy could redirect a DOI to.

Sends GET https://doi.org/{doi}?action=showurls, the proxy's XML listing. An ordinary DOI has two entries: the landing page (mode="legacy") and the registration agency's metadata server (http_role="conneg", with a href_template). A multiple-resolution DOI lists its further locations. An unknown DOI answers 404, which raises :class:bibliofabric.exceptions.NotFoundError.

content(doi, media_type)

Return the negotiated metadata representation for a DOI.

Sends GET https://doi.org/{doi} with the given Accept header and follows the resolver's redirect to the registration agency's data server. The three JSON media types parse into typed models (:class:~hodoi.models.CslItem for :data:~hodoi.media_types.CSL_JSON, :class:~hodoi.models.DataciteRecord for :data:~hodoi.media_types.DATACITE_JSON, :class:~hodoi.models.SchemaOrgThing for :data:~hodoi.media_types.SCHEMAORG_JSONLD); every other media type (BibTeX, RIS, the XML dialects, a formatted citation) returns as text. The answer is None when the agency reports 204, which means that no metadata is available. A media type the agency does not answer raises :class:bibliofabric.exceptions.APIError with its HTTP 406.

raw(doi, media_type, *, follow_redirects=None)

Return the un-parsed bytes of a negotiated representation.

follow_redirects=None keeps the client setting (off), so the bytes are the resolver's 302 body ("Handle Redirect"); pass follow_redirects=True to receive the agency's metadata bytes. To read the Location header of the 302, use :meth:resolve.

Settings

hodoi.HodoiSettings

Bases: BaseApiSettings

DOI System client settings.

Inherits timeout, max_retries, max_retry_wait, max_requests_per_second, max_concurrency, user_agent, mailto and follow_redirects from :class:bibliofabric.config.BaseApiSettings and sets DOI defaults (2 req/s, concurrency 2, timeout 60 s). No credentials exist for doi.org.

follow_redirects stays False: the resolver answers metadata requests with a 302 whose body and Location header point at the registration agency's data server. Pass follow_redirects=True per request (the client does this for content()), or set it to True here to follow redirects globally.

Models

hodoi.models.AgencyAnswer

Bases: BaseModel

One entry of the GET /ra/{doi} JSON list.

A known DOI carries the registration agency name in RA (for example Crossref, DataCite, mEDRA). An unknown or malformed DOI has RA=None and a status string (DOI does not exist, Invalid DOI, or Unknown). The HTTP status is 200 in every case.

hodoi.models.HandleRecord

Bases: BaseModel

The JSON object of GET /api/handles/{doi}.

responseCode 1 means success; 100 means handle not found (then the proxy answers HTTP 404 and message explains which part failed). 200 means values not found, which arrives as HTTP 200 with no values.

hodoi.models.HandleValue

Bases: BaseModel

One entry of a handle record.

type is URL for the landing page link, HS_ADMIN for the administrator entry, HS_ALIAS for an alias, or a numeric type such as 700050. ttl is the cache time in seconds; the timestamp is an ISO 8601 string.

hodoi.models.HandleValueData

Bases: BaseModel

The data object of one handle value.

format is one of string, base64, hex, admin, vlist, or site. value is the decoded string for the first three formats, an :class:HandleAdminValue for admin, and the raw extra fields carry the rarer vlist and site shapes.

hodoi.models.HandleAdminValue

Bases: BaseModel

The value of an HS_ADMIN entry: the administrator handle.

hodoi.models.CslItem

Bases: BaseModel

One CSL JSON item (application/vnd.citationstyles.csl+json).

hodoi.models.DataciteRecord

Bases: BaseModel

One DataCite JSON record (application/vnd.datacite.datacite+json).

hodoi.models.SchemaOrgThing

Bases: BaseModel

One schema.org JSON-LD document (application/vnd.schemaorg.ld+json).

hodoi.models.RedirectLocation

Bases: BaseModel

One location element of the proxy's redirect listing.

href is the URL. The proxy sends mode="legacy" and a numeric weight for the landing page, http_role="conneg" and href_template for the registration agency's metadata server, and other attributes for the locations of a multiple-resolution DOI. Every attribute stays, as the string the proxy sends.

Helpers

hodoi.normalize_doi(value) cached

Return the bare DOI for a DOI, DOI URL, or doi: string.

Accepts 10.1038/nature12373, https://doi.org/10.1038/nature12373, http://dx.doi.org/10.1038/nature12373, and doi:10.1038/nature12373. Anything else raises :class:bibliofabric.exceptions.ConfigurationError.

hodoi.doi_path(doi)

Return doi percent-encoded for the path of a doi.org URL.

The DOI 10.1000/res#test becomes 10.1000/res%23test, the form the proxy resolves (see the DOI Resolution Documentation, section 2).

hodoi.ra_chunks(dois)

Group percent-encoded DOIs into the comma-separated bodies of /ra/ paths.

A chunk holds at most :data:RA_BATCH_SIZE DOIs and stays under :data:RA_MAX_PATH_CHARS characters, so long DOIs form more, smaller requests. A single DOI that is longer than the budget travels alone.

hodoi.strip_doi_form(value)

Strip DOI URL and doi: wrappers without validating the result.

A URL wrapper carries the DOI percent-encoded, as in https://doi.org/10.1000/res%23test; the function decodes it. In a URL a raw ? starts the query string and a raw # the fragment, so both are cut, as in https://doi.org/10.1038/nature12373?from=x. A bare DOI keeps them, because both are legal characters of a DOI name. The /ra/ route answers malformed strings itself (Invalid DOI), so the lookup sends whatever it gets after the wrapper is removed.

hodoi.parse_locations(text)

Parse the XML of ?action=showurls into :class:RedirectLocation.

The proxy answers <locations><location ... /></locations> with every URL it could redirect to. Raises :class:ConfigurationError for a body that is not that document, and :class:ValidationError for a location without an href.