Index
zocrates.discovery.providers ¶
Scholarly literature discovery providers and resolvers.
DEFAULT_USER_AGENT
module-attribute
¶
__all__
module-attribute
¶
__all__ = ['DEFAULT_POLITE_EMAIL', 'DEFAULT_USER_AGENT', 'SearchProvider', 'TokenBucketRateLimiter', 'make_user_agent', 'OpenAlexProvider', 'UnpaywallResolver', 'CrossrefValidator']
CrossrefValidator ¶
Validates DOI metadata and queries bibliographic records via Crossref REST API.
Initialize the Crossref validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Contact email used for polite-pool API identification. |
DEFAULT_POLITE_EMAIL
|
timeout
|
float
|
HTTP request timeout in seconds. |
5.0
|
Source code in zocrates/discovery/providers/crossref.py
validate_doi
async
¶
Validate and retrieve Crossref work metadata for a given DOI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doi
|
str
|
Digital Object Identifier. |
required |
email
|
str | None
|
User or developer email for polite pool identification. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
Dictionary containing Crossref 'message' payload if valid, or None. |
Source code in zocrates/discovery/providers/crossref.py
OpenAlexProvider ¶
Bases: SearchProvider
Primary search provider backed by the OpenAlex REST API. Indexes 250M+ scholarly works, arXiv preprints, and open-access metadata.
Initialize the OpenAlex search provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Contact email for polite-pool API requests. |
DEFAULT_POLITE_EMAIL
|
rate_limiter
|
TokenBucketRateLimiter | None
|
Token bucket rate limiter instance. |
None
|
timeout
|
float
|
HTTP request timeout in seconds. |
15.0
|
api_key
|
str | None
|
Optional OpenAlex premium API key. |
None
|
Source code in zocrates/discovery/providers/openalex.py
extract_arxiv_id_from_work
staticmethod
¶
Extract canonical arXiv ID without version suffix from an OpenAlex work record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
work
|
dict[str, Any]
|
OpenAlex work dictionary. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Canonical lowercase arXiv ID without 'v' suffix (e.g. '2305.12345'), or None. |
Source code in zocrates/discovery/providers/openalex.py
reconstruct_abstract
staticmethod
¶
Reconstruct plain-text abstract from an OpenAlex abstract_inverted_index dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inverted_index
|
dict[str, list[int]] | None
|
Mapping of words to their token position indices. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Coherent, human-readable abstract string, or None if empty/invalid. |
Source code in zocrates/discovery/providers/openalex.py
resolve_identifier
async
¶
Resolve a paper by DOI, arXiv ID, or OpenAlex ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
DOI, arXiv ID, or OpenAlex ID. |
required |
Returns:
| Type | Description |
|---|---|
CandidatePaper | None
|
Resolved CandidatePaper, or None if not found. |
Source code in zocrates/discovery/providers/openalex.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
search
async
¶
Execute free-text or conceptual search against OpenAlex works.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User search query string. |
required |
limit
|
int
|
Maximum candidate works to return. |
10
|
year_from
|
int | None
|
Optional minimum publication year. |
None
|
year_to
|
int | None
|
Optional maximum publication year. |
None
|
is_oa_only
|
bool
|
Restrict to open-access papers. |
False
|
Returns:
| Type | Description |
|---|---|
list[CandidatePaper]
|
List of parsed CandidatePaper instances. |
Source code in zocrates/discovery/providers/openalex.py
SearchProvider ¶
Bases: ABC
Abstract base class for scholarly literature search providers.
resolve_identifier
abstractmethod
async
¶
Resolve a single scholarly paper by DOI, arXiv ID, or provider-specific ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
DOI, arXiv ID, or provider ID string. |
required |
Returns:
| Type | Description |
|---|---|
CandidatePaper | None
|
CandidatePaper if resolved, or None if not found. |
Source code in zocrates/discovery/providers/base.py
search
abstractmethod
async
¶
Search for scholarly literature matching the query and filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Free-text search terms or conceptual query. |
required |
limit
|
int
|
Maximum number of candidate papers to return. |
10
|
year_from
|
int | None
|
Optional minimum publication year (inclusive). |
None
|
year_to
|
int | None
|
Optional maximum publication year (inclusive). |
None
|
is_oa_only
|
bool
|
When True, restrict results to open-access works. |
False
|
Returns:
| Type | Description |
|---|---|
list[CandidatePaper]
|
List of CandidatePaper instances. |
Source code in zocrates/discovery/providers/base.py
TokenBucketRateLimiter ¶
Token-bucket rate limiter for respectful, throttled API consumption. Thread/asyncio safe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Refill rate in tokens per second. |
10.0
|
capacity
|
float
|
Maximum burst capacity in tokens. |
10.0
|
Source code in zocrates/discovery/providers/base.py
acquire
async
¶
Acquire tokens from the bucket, sleeping if necessary until replenished.
Source code in zocrates/discovery/providers/base.py
UnpaywallResolver ¶
Resolves open-access fulltext PDF URLs via the Unpaywall API.
Initialize the Unpaywall resolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Contact email used for polite-pool API requests. |
DEFAULT_POLITE_EMAIL
|
timeout
|
float
|
HTTP request timeout in seconds. |
5.0
|
Source code in zocrates/discovery/providers/unpaywall.py
resolve_pdf
async
¶
Query Unpaywall for a legal, direct Open Access PDF URL for the given DOI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doi
|
str
|
Digital Object Identifier (canonical or raw). |
required |
email
|
str | None
|
User or developer email for polite pool identification. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Direct PDF URL string if available and verified, or None. |
Source code in zocrates/discovery/providers/unpaywall.py
make_user_agent ¶
Build a respectful User-Agent header string adhering to API etiquette.