Python SDK for libraryapi.dev — US public library facility, hours, services, and statistics data. Install: pip install libraryapi-sdk · Import: from libraryapi import LibraryAPI
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file libraryapi_sdk-0.2.0.tar.gz.
File metadata
- Download URL: libraryapi_sdk-0.2.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cce96b8a3b6400c20089b4b511cf978c1956496469282e10889bfface34d8a0
|
|
| MD5 |
ea369249cbc65babdced8741a89f4dda
|
|
| BLAKE2b-256 |
1e572c14219d46c1c90596d7b7f839eac6ab38e17c88115bedb698ca1420b1c1
|
File details
Details for the file libraryapi_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: libraryapi_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c9d4ed43e581dff86dbab41f77d44957ed02df64cd31c3c5b085e92d25c1d00
|
|
| MD5 |
93a9451f4e1c55a9d7b45bee05a1addf
|
|
| BLAKE2b-256 |
02fae21b43aac395cbf256aac5cb4dd97a7b944590d48055a0b5c265bb3c68fb
|