Settings and credentials
Every client reads its settings from a pydantic-settings class. The class
loads environment variables with the client's own prefix and a .env file in
the working directory, so the same code runs with and without credentials.
The overview shows a full constructor example with Crossref.
How a client finds its settings
Calling OpenAlexClient() with no arguments builds an OpenAlexSettings
object from those sources: it reads OPENALEX_-prefixed environment
variables and a .env file in the working directory. Real environment
variables win over .env, and constructor arguments win over both:
from bibliofabric.openalex import OpenAlexClient, OpenAlexSettings
# The environment exports OPENALEX_TIMEOUT=12.5.
settings = OpenAlexSettings()
print(settings.timeout)
client = OpenAlexClient(OpenAlexSettings(timeout=5.0))
print(client.settings.timeout)
12.5
5.0
The settings live on the client as client.settings. Every client
constructor also takes mailto=, and a client with credentials takes each
credential field as a keyword, such as api_key= on OpenAlexClient or
access_token= on OrcidClient. A keyword overrides the settings object
and the environment. There are no constructor keywords for the other
tunables; pass a settings object for those.
Fields every client shares
Every settings class inherits these fields from BaseApiSettings.
The examples name the OpenAlex variables; each client uses its own prefix.
| Field | Controls | Default | For example |
|---|---|---|---|
timeout |
Request timeout in seconds | 30.0 |
OPENALEX_TIMEOUT |
max_retries |
Retries per request | 3 |
OPENALEX_MAX_RETRIES |
max_retry_wait |
Upper bound on one retry wait, in seconds | 60.0 |
OPENALEX_MAX_RETRY_WAIT |
max_requests_per_second |
Client-side rate limit | per API | OPENALEX_MAX_REQUESTS_PER_SECOND |
max_concurrency |
Concurrent requests in flight | per API | OPENALEX_MAX_CONCURRENCY |
user_agent |
The User-Agent header sent with every request |
built from the package name and version | OPENALEX_USER_AGENT |
mailto |
Contact address appended to the User-Agent |
unset | OPENALEX_MAILTO |
The defaults for max_requests_per_second and max_concurrency follow each
API's documented limits, so a client may override the core default; the
client's settings reference states the value. Three more fields exist on the
base class for special cases (connect_timeout, follow_redirects, and
rate_limits); they are documented in the core settings reference.
Retries, rate limits, and the exceptions that these fields govern are covered in Errors and retries.
Every client
The table comes from importing every subpackage and reading each settings
class's model_fields and model_config. No API in the list requires
credentials; the optional ones raise no error when unset, but the API may answer slower
or with lower rate limits.
| Subpackage | Async client | Sync client | Settings class | Prefix | Credentials |
|---|---|---|---|---|---|
bibliofabric.arxiv |
ArxivClient |
ArxivSyncClient |
ArxivSettings |
ARXIV_ |
None |
bibliofabric.crossref |
CrossrefClient |
CrossrefSyncClient |
CrossrefSettings |
CROSSREF_ |
Optional CROSSREF_PLUS_TOKEN |
bibliofabric.datacite |
DataCiteClient |
DataCiteSyncClient |
DataCiteSettings |
DATACITE_ |
None |
bibliofabric.doaj |
DoajClient |
DoajSyncClient |
DoajSettings |
DOAJ_ |
None |
bibliofabric.doi |
DoiClient |
DoiSyncClient |
DoiSettings |
DOI_ |
None |
bibliofabric.europepmc |
EuropePmcClient |
EuropePmcSyncClient |
EuropePmcSettings |
EUROPEPMC_ |
None |
bibliofabric.issn |
IssnClient |
IssnSyncClient |
IssnSettings |
ISSN_ |
None |
bibliofabric.openaire |
OpenAireClient |
OpenAireSyncClient |
OpenAireSettings |
OPENAIRE_ |
Optional OPENAIRE_CLIENT_ID, OPENAIRE_CLIENT_SECRET, OPENAIRE_REFRESH_TOKEN |
bibliofabric.openalex |
OpenAlexClient |
OpenAlexSyncClient |
OpenAlexSettings |
OPENALEX_ |
Optional OPENALEX_API_KEY |
bibliofabric.opencitations |
OpenCitationsClient |
OpenCitationsSyncClient |
OpenCitationsSettings |
OPENCITATIONS_ |
None |
bibliofabric.orcid |
OrcidClient |
OrcidSyncClient |
OrcidSettings |
ORCID_ |
Optional ORCID_ACCESS_TOKEN, ORCID_CLIENT_ID, ORCID_CLIENT_SECRET |
bibliofabric.ror |
RorClient |
RorSyncClient |
RorSettings |
ROR_ |
None |
bibliofabric.rxiv |
RxivClient |
RxivSyncClient |
RxivSettings |
RXIV_ |
None |
bibliofabric.semanticscholar |
SemanticScholarClient |
SemanticScholarSyncClient |
SemanticScholarSettings |
SEMANTICSCHOLAR_ |
Optional SEMANTICSCHOLAR_API_KEY |
bibliofabric.wikidata |
WikidataClient |
WikidataSyncClient |
WikidataSettings |
WIKIDATA_ |
None |
bibliofabric.zenodo |
ZenodoClient |
ZenodoSyncClient |
ZenodoSettings |
ZENODO_ |
Optional ZENODO_API_TOKEN |
Optional credentials raise no error when left unset; what a key changes for one API, such as Semantic Scholar's, is described on that client's page.