APIs for LoC.gov
The Library of Congress' website, loc.gov, provides access to LC digital content available online. It differs from the Library of Congress catalog, which includes materials that are not digital or have more restrictions, such as needing to come onsite. If you're looking for digital materials available online, both the Guide to Digital Scholarship at the Library of Congress and the Using the Library of Congress Online Guide for Middle and High School Students go into detail about strategies for narrowing search results.
This informational site describes how the Library also makes information available via a series of application programming interfaces (APIs). Specifically, it includes technical documentation of the Library's loc.gov JSON API, its sitemaps, and suite of microservices. Thanks for checking it out and please contact LC-Labs@loc.gov if you don't see your question answered here or want to talk more.
Why might you want to use an API to obtain information about the Library's online content instead of searching the website?
- First, an API enables automation. It returns information in a more machine-readable form than the loc.gov website does. So, for example, if you are a software developer, computer programmer, or computational researcher building an application or pulling down a lot of information at one time, an API may be more useful than scraping the website.
- Second, machine-readable information makes data available in a structured format. So, as another example, if you are a student or an educator who wants to compile a spreadsheet of LC collections related to "cats" you could more easily convert the API response (which in the case of the loc.gov API comes in the form of JSON data) into a csv file. You could then open this csv in any spreadsheet viewing program like Excel.
- Third, JSON data also makes it easy to page through the data made available by the API. Once you have the results of an API query, you can more easily iterate through the responses to see which match the attributes you're looking for. It's important to know that, sometimes, you can sort by attributes that are not available as facets (such as "original format," "online format," "date, or "location") on the loc.gov website.
- Finally, an API query provides more flexibility with faceting, filtering, and organizing your results while you're actively searching. So, if you can't find what you're looking for as a facet on the left-hand side of a search result, consider checking out the JSON API's query parameters to see if they better suit your needs.
Available APIsThe Library of Congress makes three different loc.gov APIs available to the public:
- JSON/YAML for loc.gov: The loc.gov API provides structured data about Library of Congress collections. The API was originally designed to power the loc.gov website, but in addition to providing HTML for the website it can provide a wealth of information in JSON format.
- Sitemaps: A sitemap provides information on the relationships between the pages, videos, images and other resources on a website. They are primarily used to inform search engines about the pages that are available for crawling. It is expressed as an XML file listing URLs and their associated metadata. Conventionally, sitemaps are not described as APIs but it's convenient to discuss them in relationship to other LC APIs since they are also used for automated interactions, especially by web crawlers.
- Microservices: A microservice is a limited-purpose
computer system written to carry out a specific role and using a
lightweight API. The three microservices described on this page fall
into three categories: Text Services, Image Services, and Streaming
- Text Services provides an API for accessing full text OCR, word coordinates and context snippets on loc.gov.
- Image Services provides an IIIF-compliant API for accessing and manipulating images from the Library of Congress.
- Streaming Services provides an audio and video (A/V) delivery API for the Library of Congress.
- The Chronicling America API is maintained separately from the other loc.gov APIs. Documentation can be found on the Chronicling America site (https://chroniclingamerica.loc.gov/about/api/).