libraryapi
Official Python SDK for libraryapi.dev — US public library facility, hours, services, and statistics data from the federal IMLS Public Libraries Survey. 9,252 systems · 17,586 outlets · FY 2023.
Install
pip install libraryapi-sdk
Note on naming:
libraryapiis taken on PyPI by an unrelated project. The install name islibraryapi-sdk; the Python import name islibraryapi.
Requires Python 3.9+. Only dependency is httpx.
Quickstart
from libraryapi import LibraryAPI
client = LibraryAPI(api_key="sk_live_...") # https://libraryapi.dev/pricing
# Nearest outlets to an address
outlets = client.outlets.near(
address="14901 Dale Evans Pkwy, Apple Valley, CA",
radius_miles=10,
)
for o in outlets:
print(f"{o.distance_miles:.2f} mi {o.name} ({o.weekly_hours} hrs/wk)")
# Full parent-system profile (collections, usage, programs, finance)
system = client.libraries.fetch(outlets[0].fscs_id)
print(system.name) # San Bernardino County Library
print(system.service_area.population) # 1,263,869
print(system.finance.total_revenue) # 28,327,522
print(system.usage.programs.attendance_total) # 166,411
# State-level rollup
ca = client.states.summary("CA")
print(ca.totals.library_systems, ca.totals.outlets) # 186 1192
Async
import asyncio
from libraryapi import AsyncLibraryAPI
async def main():
async with AsyncLibraryAPI(api_key="sk_live_...") as client:
outlets = await client.outlets.near(address="350 Fifth Ave, New York, NY")
for o in outlets:
print(o.name)
asyncio.run(main())
Errors
from libraryapi import LibraryAPI, NotFoundError, RateLimitError, QuotaExceededError
try:
client.libraries.fetch("ZZ9999")
except NotFoundError:
print("library system not found")
except QuotaExceededError:
print("monthly quota reached")
except RateLimitError:
print("slow down — too many requests per minute")
Exception hierarchy: LibraryAPIError → {AuthenticationError, InvalidParamsError, QuotaExceededError, NotFoundError, RateLimitError}.
API surface
| Method | Returns |
|---|---|
client.outlets.near(address=..., radius_miles=..., limit=...) |
list[Outlet] |
client.outlets.near(lat=..., lng=..., radius_miles=..., limit=...) |
list[Outlet] |
client.outlets.fetch(outlet_id) |
Outlet |
client.libraries.fetch(fscs_id) |
LibrarySystem |
client.libraries.search(name=..., state=..., city=..., limit=..., offset=...) |
list[LibrarySystem] |
client.states.summary(code) |
StateSummary |
client.health() |
dict |
Convenience properties
Outlet.weekly_hours—round(annual_hours / weeks_open)
Links
Release files for libraryapi-sdk 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| libraryapi_sdk-0.2.0.tar.gz | 8.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| libraryapi_sdk-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.0 kB
Release files / libraryapi_sdk-0.2.0.tar.gz
| Download URL | libraryapi_sdk-0.2.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5cce96b8a3b6400c20089b4b511cf978c1956496469282e10889bfface34d8a0
|
|
BLAKE2b-256 checksum How to use checksums |
1e572c14219d46c1c90596d7b7f839eac6ab38e17c88115bedb698ca1420b1c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / libraryapi_sdk-0.2.0-py3-none-any.whl
| Download URL | libraryapi_sdk-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c9d4ed43e581dff86dbab41f77d44957ed02df64cd31c3c5b085e92d25c1d00
|
|
BLAKE2b-256 checksum How to use checksums |
02fae21b43aac395cbf256aac5cb4dd97a7b944590d48055a0b5c265bb3c68fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|