Skip to main content

Python module for interacting with Library of Congress Linked Data Service and API endpoint

Project description

loc-authorities

unit tests

Python library for querying and representing LoC ID APIs. The library provides connectors for the Library of Congress Linked Data Authority.

loc-authorities uses the python library rdflib to query Library of Congress entities and represent them as python classes.

Supported search interfaces:

Fully supported authorities:

Partially supported authorities:

There are no plans to support further authorities at this point in time, but pull requests for implementations of other authorities are welcome!

Installation

Via pip into virtual environment

Clone the repo, then in the base directory, run:

$ pip install loc-authorities

Usage

# construct URIs

>>>
>>> from loc_authorities.api import LocAPI
>>> LocAPI.uri_from_id('n79043402')
'http://id.loc.gov/authorities/n79043402'

>>>
>>> LocAPI.dataset_uri_from_id('n79043402')
'http://id.loc.gov/authorities/names/n79043402'

# Query LoC search endpoints

>>>
>>> loc = LocAPI()
>>> loc.retrieve_label('Franklin, Benjamin, 1706-1790')
'n79043402'

# query the left-anchored search through the method "suggest"
# returns list of top ten results from API
>>>
>>> suggest = loc.suggest('Franklin, Benjamin')
>>> suggest[0].uri
'http://id.loc.gov/authorities/names/n2015067702'
>>> suggest[0].label
'Franklin Benjamin'

# method LocAPI.search() queries the keyword search method in the same manner

# Represent a single entity
>>>
>>> from loc_authorities.api import LocEntity
>>> entity = LocEntity('mp2013015202')
>>> entity.authoritative_label
rdflib.term.Literal('dancer', lang='en')
>>> entity.dataset_uri
'http://id.loc.gov/authorities/performanceMediums/mp2013015202'
>>> entity.instance_of
[
    rdflib.term.URIRef('http://www.loc.gov/mads/rdf/v1#Medium'),
    rdflib.term.URIRef('http://www.loc.gov/mads/rdf/v1#Authority'),
    rdflib.term.URIRef('http://www.w3.org/2004/02/skos/core#Concept')
]

# Represent an entity from the Name Authority
>>>
>>> from loc_authorities.api import NameEntity
>>> name = NameEntity('n79043402')
>>> name.authoritative_label
rdflib.term.Literal('Franklin, Benjamin, 1706-1790') # inherits all properties of LocEntity
>>> name.birthdate
rdflib.term.Literal('1706-01-17', datatype=rdflib.term.URIRef('http://id.loc.gov/datatypes/edtf/EDTF'))
>>> name.birthyear
1706
>>> name.deathdate
rdflib.term.Literal('1790-04-17', datatype=rdflib.term.URIRef('http://id.loc.gov/datatypes/edtf/EDTF'))
>>> name.deathyear
1790

# Represent an entity from the Subject Authority
>>>
>>> from loc_authorities.api import SubjectEntity
>>> subject = SubjectEntity('sh85054401')
>>> subject.authoritative_label
rdflib.term.Literal('German literature--Germany (East)', lang='en') # inherits all properties of LocEntity
# for complex subjects, components instances of either NameEntity or SubjectEntity
>>> subject.components
[<loc_authorities.api.SubjectEntity object at 0x0000025AF492B810>, <loc_authorities.api.NameEntity object at 0x0000025AF492A990>]

Running tests

Install development requirements
$ pip install . --group dev

Run tests with pytest
$ python -m pytest --cov --cov-report=html:calc_cov

Run tests and produce HTML coverage report

## Build documentation

Install development requirements
```$ pip install . --group dev```

Run doctest to make sure the code examples work
```$ make -C docs doctest```

Build documentation with Sphinx
```$ sphinx-build ./docs/source ./docs/build```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loc_authorities-0.2.0.tar.gz (63.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loc_authorities-0.2.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file loc_authorities-0.2.0.tar.gz.

File metadata

  • Download URL: loc_authorities-0.2.0.tar.gz
  • Upload date:
  • Size: 63.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for loc_authorities-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8230671e6f20942aa1bbb7e439953c424a3317516f1e890812c2a43b96628be1
MD5 2a117f29ba68e9beea8259fb6cf38036
BLAKE2b-256 ef2473d7fb8941f40b274ccedd668f23b6e3735669ef7ee86b6d54bad476740d

See more details on using hashes here.

Provenance

The following attestation bundles were made for loc_authorities-0.2.0.tar.gz:

Publisher: python-publish.yml on AmericanPhilosophicalSociety/loc-authorities

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file loc_authorities-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for loc_authorities-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc55a80b42383a99c0cac45eb7a149a817d2587d938a4853ad71970d768666e3
MD5 c168bd3ba888a4c197bfd0b973454274
BLAKE2b-256 41eb542a815d066245b53a04f2daa88c1d4f6c250f09e60be13872afea56f329

See more details on using hashes here.

Provenance

The following attestation bundles were made for loc_authorities-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on AmericanPhilosophicalSociety/loc-authorities

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page