API reference
Generated from the source with mkdocstrings.
Client
bibliofabric.viaf.ViafClient
Client for the VIAF API at https://viaf.org/viaf.
The API needs no credentials. The client sends
Accept: application/xml on every request, because the cluster and
search routes answer content-negotiated XML; the AutoSuggest resource
overrides that with Accept: application/json per call. Without an
Accept header the routes redirect 307 to the HTML site under
/en/viaf/.
clusters: ClustersResource
cached
property
The cluster resource: lookups by id, LCCN, and source id, plus search.
brief_clusters: BriefClustersResource
cached
property
The BriefVIAF search resource: minified clusters at 100 per page.
suggest: SuggestResource
cached
property
The AutoSuggest resource: fast name lookup.
The sync client ViafSyncClient and its *SyncResource twins mirror the
async classes method for method.
Cluster resource
bibliofabric.viaf.ClustersResource
Client for the cluster routes: lookups by id and full-cluster search.
Every read of this resource answers the full VIAFCluster XML, which the
client validates into :class:bibliofabric.viaf.ViafCluster models.
by_lccn(lccn: str) -> ViafCluster
async
Return the cluster an LCCN resolves to, for example n79032879.
by_source_id(source_code: str, local_id: str) -> ViafCluster
async
Return the cluster one authority file's local id resolves to.
source_code is an authority file code such as LC, DNB,
BNF, or WKP; local_id is that file's own id, for
example by_source_id("LC", "n 78015294"). The pipe between the
two stays unencoded on the wire.
exists(id: str | int) -> bool
async
Return True when the id resolves to a cluster; else False.
The API answers HEAD as the HTML site redirect, so the probe
costs one GET.
explain() -> ViafExplain
async
Return the SRU explain facts of the search service.
get(id: str | int, *, select: Sequence[str] | None = None, params: Mapping[str, Any] | None = None) -> ViafCluster
async
Return one cluster by VIAF id; an unknown id raises NotFoundError.
Accepts the bare number (102333412), a zero-padded number, and
the https://viaf.org/viaf/102333412 URL form. The API answers
404 for a trailing slash after the id.
Brief cluster resource
bibliofabric.viaf.BriefClustersResource
Client for the BriefVIAF search schema.
The brief schema carries only the cluster id, the name type, the
headings, and the titles, at up to 250 records per page. Lookups by id
live on :attr:ViafClient.clusters.
AutoSuggest resource
bibliofabric.viaf.SuggestResource
Client for GET /viaf/AutoSuggest, the fast name lookup.
The route answers JSON regardless of the client's default Accept
header, so this resource sends Accept: application/json per call.
clusters(query: str, *, params: dict[str, str] | None = None) -> list[ViafSuggestion]
async
Return the AutoSuggest hits for one name string.
The route matches on the leading words of a display form, so
"austen" and "Austen, Jane, 1775-1817" match while inverted
or quoted strings answer no hits. The answer carries no total and
is not paged; the list holds at most 10 hits. Each hit's
authority-source ids (lc, dnb, bnf, ...) land in
:attr:ViafSuggestion.source_ids.
CQL helper
bibliofabric.viaf.cql(index: str, relation: str = '=', *terms: str) -> str
Build one CQL search clause such as local.personalNames all "tolkien".
Terms are quoted and joined with spaces inside the quotes, as the SRU
route expects. relation must be one of :data:CQL_RELATIONS.
Raises:
| Type | Description |
|---|---|
ConfigurationError
|
|
Settings
bibliofabric.viaf.ViafSettings
VIAF-specific client settings.
Inherits timeout, max_retries, max_retry_wait,
max_requests_per_second, max_concurrency, user_agent and
mailto from :class:bibliofabric.config.BaseApiSettings. The API
needs no credentials.
Models
bibliofabric.viaf.ViafCluster
One VIAF authority cluster, as GET /viaf/{id} and the full-cluster search answer it.
headings: list[str]
property
Every cluster-wide heading text of the first mainHeadings block.
source_codes: list[str]
property
The codes of the contributing authority files.
url: str | None
property
The canonical VIAF URL of the cluster.
bibliofabric.viaf.ViafBriefCluster
One BriefVIAF record of the minified search schema.
The brief schema carries only viafID, nameType, mainHeadings,
and titles.
headings: list[str]
property
Every cluster-wide heading text of the first main_headings block.
bibliofabric.viaf.ViafSuggestion
One AutoSuggest hit: a display form plus the ids the sources know.
Every authority-source code of the answer (lc, dnb, bnf,
...) lands in :attr:source_ids, keyed by lowercase source code.
viaf_id: str | None
property
The cluster id as the string the route answers with.
bibliofabric.viaf.ViafExplain
The SRU explain facts of the search service.
bibliofabric.viaf.ViafVariant
One alternate or see-also heading (x400 for alternates, x500 for related names).
heading: str | None
property
The a subfield text of the datafield, or None.
bibliofabric.viaf.ViafTitles
The titles wrapper: uniform titles of works (and expressions).
bibliofabric.viaf.ViafSource
One contributing authority file of a cluster, as the cluster's top-level source element carries it.
text reads CODE|local id; :attr:code and :attr:id split it.
code: str | None
property
The authority file code before the pipe, such as LC.
id: str | None
property
The local id after the pipe, such as n 79032879.
bibliofabric.viaf.ViafFixed
The fixed block of coded cluster facts, such as gender.
bibliofabric.viaf.ViafHistoryEntry
One cluster history event (ht): when a source record joined the cluster.
Parsers
bibliofabric.viaf.parse_cluster(root: Element) -> dict[str, Any]
Return one VIAFCluster element as a plain dict.
Works for the full cluster and for the BriefVIAF subset, which carries
only viafID, nameType, mainHeadings, and titles.
bibliofabric.viaf.parse_search_response(root: Element) -> dict[str, Any]
Return one searchRetrieveResponse as a plain dict.
Each record contributes recordPosition, recordSchema, and
the parsed cluster under cluster. The echoed request fields land
under echoed when the answer carries them.
bibliofabric.viaf.parse_explain(root: Element) -> dict[str, Any]
Return the server facts of one SRU explain answer.
Constants
| Name | Value | Meaning |
|---|---|---|
VIAF_API_BASE_URL |
https://viaf.org/viaf |
Base URL of the lookup and search routes |
VIAF_DEFAULT_PAGE_SIZE |
10 | Default and largest page_size of a full cluster search |
VIAF_MAX_PAGE_SIZE |
10 | Server clamp on maximumRecords for the full schema |
VIAF_BRIEF_DEFAULT_PAGE_SIZE |
100 | Default page_size of a BriefVIAF search |
VIAF_BRIEF_MAX_PAGE_SIZE |
250 | Server clamp on maximumRecords for BriefVIAF |
VIAF_SORT_KEY |
holdingscount |
The only sort value the server accepts |