utils
Helpers exposed for advanced workflows.
pypaperretriever.utils
entrez_efetch
Fetch a record from the Entrez API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Email address required by the Entrez API. |
required |
id
|
str
|
PubMed identifier to fetch. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Parsed record returned by the Entrez API. |
Source code in pypaperretriever/utils.py
pmid_to_doi
Convert a PMID to a DOI using the Entrez API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pmid
|
str
|
PubMed identifier to convert. |
required |
email
|
str
|
Email address required by the Entrez API. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: DOI if found, otherwise |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no DOI is associated with the PMID. |
Source code in pypaperretriever/utils.py
doi_to_pmid
Convert a DOI to a PMID.
The function first queries the Entrez API. If that fails, the PMC ID converter service is used as a fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doi
|
str
|
Digital Object Identifier to convert. |
required |
email
|
str
|
Email address required by the Entrez API. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: PMID if found, otherwise |
Source code in pypaperretriever/utils.py
encode_doi
Encode a DOI for safe inclusion in file names.
This function encodes all special characters in a DOI to make it safe for use in file paths and URLs. It uses URL encoding (percent-encoding) for all characters except alphanumeric ones, ensuring compatibility across different operating systems and contexts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doi
|
str
|
DOI to encode. It may include a |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
URL-encoded DOI suitable for use in file paths. |
Source code in pypaperretriever/utils.py
decode_doi
Decode a previously encoded DOI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_doi
|
str
|
DOI encoded with :func: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The decoded DOI. |