citeformer.metadata.crossref¶
Crossref DOI metadata fetcher.
https://api.crossref.org/works/{doi} with Accept: application/vnd.citationstyles.csl+json returns a CSL-JSON dict directly,
saving us a translation hop. The returned dict is suitable for handing
straight to citeformer.render.render_references as Source.metadata.
Polite-pool opt-in: if the CITEFORMER_CROSSREF_MAILTO env var is set,
the outgoing User-Agent carries it so Crossref routes the request through
the polite pool (faster, more reliable rate limits). See
https://www.crossref.org/documentation/retrieve-metadata/rest-api/tips-for-using-the-rest-api/
Module Contents¶
Functions¶
Fetch a Crossref CSL-JSON entry for a DOI. |
API¶
- citeformer.metadata.crossref.fetch_crossref(doi: str, *, timeout: float = _DEFAULT_TIMEOUT, use_cache: bool = True) dict[str, Any]¶
Fetch a Crossref CSL-JSON entry for a DOI.
Args: doi: DOI string. Accepts bare (
"10.1038/s41586-023-06221-2"), URL ("https://doi.org/…"), or"doi:…"prefixed forms. timeout: HTTP timeout in seconds. use_cache: Cache the result under~/.cache/citeformer/metadata/.Returns: CSL-JSON item dict containing
id,type,author,title,container-title,issued,DOI,URL, and other fields Crossref has on file for this DOI.Raises: httpx.HTTPStatusError: If Crossref returns a non-2xx status.