API

class loc_authorities.api.LocAPI

Wrapper for Library of Congress API.

https://id.loc.gov/

classmethod uri_from_id(loc_id)

Generate a URL for performing initial queries

classmethod dataset_uri_from_id(loc_id)

Generate a URI for RDF triples based on LoC dataset

classmethod rwo_uri_from_id(loc_id)

Generate RWO URI for linked data queries

suggest(query, authority: Literal[None, 'names', 'subjects'] = None)

Query LoC’s suggest service API using left-anchored search. Returns a list of results, or an empty list for no results or an error.

Querying the older Suggest 1.0 is not implemented.

Parameters:
  • query – Search query (string)

  • authority – LoC authority to search. Supports names or subjects

search(query, authority: Literal[None, 'names', 'subjects'])

Query LoC’s suggest service API using keyword search. Returns a list of search results, or an empty list for an error.

Parameters:
  • query – Search query (string)

  • authority – Authority to search (‘names’ or ‘subjects’)

retrieve_label(label)

Query LoC’s label retrieval API to return a URI from a known label

class loc_authorities.api.LocEntity(loc_id)

Object to represent single LoC entity

Parameters:

loc_id – LoC identifier (string)

property uriref

LoC URI reference as instance of rdflib.URIRef

property dataset_uriref

LoC URI reference that includes LCNAF dataset marker as instance of rdflib.URIRef

property rdf

LoC data for this entity as rdflib.Graph

property authoritative_label

Authoritative entity label in English

property scheme_membership

LoC scheme that represents this entity as instance of rdflib.URIRef

property instance_of

Linked Data authorities that describe this entity as list of instances of rdflib.URIRef

class loc_authorities.api.NameEntity(loc_id)

Object to represent single entity from the LoC Name Authority File. Inherits LocEntity.

Parameters:

loc_id – LoC identifier (string)

property rwo_uriref

LoC RWO URI reference as instance of rdflib.URIRef

property birthdate

MADS birthday as rdflib.term.Literal

property deathdate

MADS deathdate as rdflib.term.Literal

property birthyear

birth year as int

property deathyear

death year as int

classmethod year_from_edtf(date)

Return just the year from EDTF date. Expects a string, returns an integer. Normalizes uncertain years. Supports negative dates. No support for partially unknown years.

class loc_authorities.api.SubjectEntity(loc_id)

Object to represent single entity from the LoC Subject Headings authority. Inherits LocEntity.

Parameters:

loc_id – LoC identifier (string)

property components

Components for LoC Complex subjects. If subject is complex, returns a list of SubjectEntity and NameEntity objects. If subject is simple, returns None.

Currently does not support temporal elements.

class loc_authorities.api.SRUResult(data)

SRU search result object, for use with LocAPI.search().

property records

List of results as SRUItem.

class loc_authorities.api.SRUItem(data)

Single item returned by a SRU search, for use with LocAPI.search() and SRUResult.

property uri

LoC URI for this result

property loc_id

LoC ID string for this result

property label

Authoritative label for this result