API reference
Generated from the source with mkdocstrings.
Client
bibliofabric.doi.DoiClient
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:~bibliofabric.doi.dialect.RA_BATCH_SIZE DOIs and stays
under :data:~bibliofabric.doi.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:~bibliofabric.doi.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:~bibliofabric.doi.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. An HTTP 200 answer
whose responseCode is neither 1 nor 200 raises
:class:bibliofabric.exceptions.APIError.
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.APIError;
: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". The request forces
follow_redirects=False, so the response is the 302 itself even
when DOI_FOLLOW_REDIRECTS=true. 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:~bibliofabric.doi.models.CslItem for
:data:~bibliofabric.doi.media_types.CSL_JSON,
:class:~bibliofabric.doi.models.DataciteRecord for
:data:~bibliofabric.doi.media_types.DATACITE_JSON,
:class:~bibliofabric.doi.models.SchemaOrgThing for
:data:~bibliofabric.doi.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. The client compares the answered Content-Type
with the requested media type; a server that answers another type,
such as a publisher HTML page, raises
:class:bibliofabric.exceptions.APIError instead of returning
foreign content. Media type parameters (; charset=utf-8, a
; q= weight) do not take part in the comparison.
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
bibliofabric.doi.DoiSyncClient
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:~bibliofabric.doi.dialect.RA_BATCH_SIZE DOIs and stays
under :data:~bibliofabric.doi.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:~bibliofabric.doi.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:~bibliofabric.doi.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. An HTTP 200 answer
whose responseCode is neither 1 nor 200 raises
:class:bibliofabric.exceptions.APIError.
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.APIError;
: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". The request forces
follow_redirects=False, so the response is the 302 itself even
when DOI_FOLLOW_REDIRECTS=true. 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:~bibliofabric.doi.models.CslItem for
:data:~bibliofabric.doi.media_types.CSL_JSON,
:class:~bibliofabric.doi.models.DataciteRecord for
:data:~bibliofabric.doi.media_types.DATACITE_JSON,
:class:~bibliofabric.doi.models.SchemaOrgThing for
:data:~bibliofabric.doi.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. The client compares the answered Content-Type
with the requested media type; a server that answers another type,
such as a publisher HTML page, raises
:class:bibliofabric.exceptions.APIError instead of returning
foreign content. Media type parameters (; charset=utf-8, a
; q= weight) do not take part in the comparison.
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
bibliofabric.doi.DoiSettings
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
bibliofabric.doi.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.
bibliofabric.doi.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.
bibliofabric.doi.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.
bibliofabric.doi.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, the JSON
object of a site value, and the list of entries of a vlist
value.
bibliofabric.doi.models.HandleAdminValue
Bases: BaseModel
The value of an HS_ADMIN entry: the administrator handle.
bibliofabric.doi.models.CslItem
Bases: BaseModel
One CSL JSON item (application/vnd.citationstyles.csl+json).
bibliofabric.doi.models.DataciteRecord
Bases: BaseModel
One DataCite JSON record (application/vnd.datacite.datacite+json).
publisher is a string or an object such as
{"name": "Springer", "publisherIdentifier": "..."}; the entries of
the titles dicts carry names and other values of any JSON type,
because the DataCite schema does not pin them.
bibliofabric.doi.models.SchemaOrgThing
Bases: BaseModel
One schema.org JSON-LD document (application/vnd.schemaorg.ld+json).
context and type also accept the JSON-LD collection forms: a
@context object or list, and a @type list.
bibliofabric.doi.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
bibliofabric.doi.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.
bibliofabric.doi.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).
bibliofabric.doi.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 its characters
stay under :data:RA_MAX_PATH_CHARS including the /ra/ prefix the
client puts in front of the chunk, so long DOIs form more, smaller
requests. A single DOI that is longer than the budget travels alone.
bibliofabric.doi.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. Whitespace around the DOI name is stripped after the wrapper is
removed, so doi: 10.1038/nature12373 and
https://doi.org/ 10.1038/nature12373 normalize. The /ra/ route
answers malformed strings itself (Invalid DOI), so the lookup sends
whatever it gets after the wrapper is removed.
bibliofabric.doi.parse_locations(response)
Parse the XML of ?action=showurls into :class:RedirectLocation.
The proxy answers <locations><location ... /></locations> with every
URL it could redirect to. Raises :class:APIError with the request and
response attached for a body that is not that document, and
:class:ValidationError for a location without an href.