viapy Code Documentation¶
API¶
- class viapy.api.SRUItem(items=None, sequence_type=<class 'tuple'>)[source]¶
Single item returned by a SRU search, for use with
ViafAPI.search()andSRUResult.The VIAFCluster attribute was added to each property lookup in 2025 to match updates to the /search API’s JSON response.
- property label¶
first main heading for this item
- property nametype¶
type of name (personal, corporate, title, etc)
- property uri¶
VIAF URI for this result
- property viaf_id¶
VIAF numeric identifier
- class viapy.api.SRUResult(data)[source]¶
SRU search result object, for use with
ViafAPI.search().- normalize_record(data)[source]¶
Added in May 2025 to match updates to the /search API records, where the JSON response now uses namespaced keys that increase per result: ns2, ns3, ns4, and so on, applying to most subkeys (ns2:VIAFCluster, ns2:Document, etc). This method strips all nsX: prefixes recursively
- total_results¶
number of records matching the query
- class viapy.api.ViafAPI[source]¶
Wrapper for VIAF API.
https://platform.worldcat.org/api-explorer/apis/VIAF
- api_base = 'https://www.viaf.org/viaf'¶
base url for VIAF API methods
- search(query)[source]¶
Query VIAF search interface. Returns a list of
SRUItem:param query: CQL query in viaf syntax (e.g.,cql.any all "term")
- suggest(term)[source]¶
Query autosuggest API. Returns a list of results, or an empty list if no suggestions are found or if something went wrong
- uri_base = 'http://viaf.org/viaf'¶
base url for VIAF URIs
- class viapy.api.ViafEntity(viaf_id)[source]¶
Object for working with a single VIAF entity.
- Parameters:
viaf_id – viaf identifier (either integer or uri)
- property birthdate¶
schema birthdate as
rdflib.Literal
- property birthyear¶
birth year
- property deathdate¶
schema deathdate as
rdflib.Literal
- property deathyear¶
death year
- rdf¶
VIAF data for this entity as
rdflib.Graph
- property uriref¶
VIAF URI reference as instance of
rdflib.URIRef
Views¶
- class viapy.views.ViafLookup(**kwargs)[source]¶
View to provide VIAF suggestions for autocomplete lookup. Based on
dal.autocompleteSelect2ListView. Expects search term as query string parameter q. Returns viaf URI as identifier and display form as text.