Skip to main content

idloc

Build Status

idloc is a command line utility and small function library for getting JSON-LD from the Library of Congress Linked Data service at https://id.loc.gov.

Ideally idloc would not be needed at all because you could just use curl or whatever HTTP library you want to fetch the JSON-LD directly. But at the moment the JSON-LD that is returned, while valid, isn't exactly usable and needs to be framed. idloc uses pyld internally to do the framing that makes the JSON usable by someone who just wants to use the data as JSON without the cognitive overhead of using RDF processing tools.

Install

This will install idloc and its dependencies:

pip install idloc

CLI

Once installed you should also have a idloc command line utility available. There are four commands get, lucky, search, concept-schemes.

Get

Get will fetch the id.loc.gov entity by URI and print out the framed JSON-LD:

$ idloc get https://id.loc.gov/authorities/subjects/sh2002000569

To see the output of this command see this file since it's really too long to include inline here in the docs.

Compare that to the JSON that is being made available at https://id.loc.gov/authorities/subjects/sh85021262.json and you will probably see why framing the JSON-LD is currently needed if you want to work with the data as JSON.

Lucky

If you want to roll the dice and see the JSON-LD for first entity that matches a given string:

$ idloc lucky "Semantic Web"

If you want to limit to particular concept schemes like subject-headings you can:

$idloc lucky --concept-scheme subject-headings "Semantic Web"

Search

You can search for entities:

$ idloc search "Semantic Web" --limit 5

International Semantic Web Conference (6th : 2007 : Pusan, Korea) Semantic Web : 6th International Semantic Web Conference, 2nd Asian Semantic Web Conference, ISWC 2007 + ASWC 2007, Busan, Korea, November 11-15, 2007 : proceedings
<http://id.loc.gov/resources/works/15024802>

International Semantic Web Conference (6th : 2007 : Pusan, Korea) The Semantic Web : 6th International Semantic Web Conference, 2nd Asian Semantic Web Conference, ISWC 2007 + ASWC 2007, Busan, Korea, November 11-15, 2007 : proceedings Berlin ; New York : Springer, 2007.
<http://id.loc.gov/resources/instances/15024802>

IFIP WG 12.5 Working Conference on Industrial Applications of Semantic Web (1st : 2005 : Jyväskylä, Finland) Industrial applications of semantic Web : proceedings of the 1st IFIP WG12.5 Working Conference on Industrial Applications of Semantic Web, August 25-27, 2005, Jyväskylä, Finland New York : Springer, c2005.
<http://id.loc.gov/resources/instances/14054943>

International Semantic Web Conference (1st : 2002 : Sardinia, Italy) semantic Web-ISWC 2002 : First International Semantic Web Conference, Sardinia, Italy, June 9-12, 2002 : proceedings
<http://id.loc.gov/resources/works/12761651>

International Semantic Web Conference (1st : 2002 : Sardinia, Italy) The semantic Web-ISWC 2002 : First International Semantic Web Conference, Sardinia, Italy, June 9-12, 2002 : proceedings Berlin ; New York : Springer, c2002.
<http://id.loc.gov/resources/instances/12761651>

Notice how the top 5 were taken up with bibframe instances? Similar to get you can limit a search to one or more concept schemes. For example if we want to search for "Semantic Web" only in the subject-headings and name-authority concept schemes:

$ idloc search --concept-scheme subject-headings --concept-scheme name-authority "Semantic Web" 

Concept Schemes

You may be wondering what concept schemes are available. To see a list of them:

$ idloc concept-schemes

Use as a Library

The idloc Python library can be used in your Python programs.

Get

You can get the JSON-LD for a given id.loc.gov URI:

import idloc

concept = idloc.get('http://id.loc.gov/authorities/subjects/sh2002000569')

Search

You can search for entities:

for result in idloc.search('Semantic Web'):
    print(result['title'], result['uri']

Similarly you can limit to particular concept schemes:

for result in idloc.search('Semantic Web', concept_schemes=['subject-headings', 'name-authority']):
    print(result['title'], result['uri'])

By default you get the first 20 results, but you can use the limit parameter to get more. If you set limit to 0 it will page through all the results.

Concept Schemes

A mapping of concept scheme names and their corresponding URIs is available in:

idloc.CONCEPT_SCHEMES

There are 130 of them! There is also a function idloc.concept_schemes() which will scrape the search interface at https://id.loc.gov/search to determine what the latest group of concept schemes is.

Metadata

Release files for idloc 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for idloc 0.2.0
File Size Uploaded
idloc-0.2.0.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for idloc 0.2.0
File Interpreter ABI Platform
idloc-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.2 kB

Release files / idloc-0.2.0.tar.gz

Download URL idloc-0.2.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fea7b9b00f2c87ab7ce6fcccdee32d61d0e93679cf9ac489976b26f5afcf794f
BLAKE2b-256 checksum
How to use checksums
7ba447d35535a4f2c5e6b1257b9dcdb6f2448fd9ad382623247c8446c6367064
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release files / idloc-0.2.0-py3-none-any.whl

Download URL idloc-0.2.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
422c13e42610584d6a1021594a35466deb4357d3049115d0c263b0b487586738
BLAKE2b-256 checksum
How to use checksums
e8029522c1a239c9588b7d8179304baafb557db55c747c900a1ecca4e7fbd32a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page