Skip to main content

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

PyPI Python

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: libraryapi is taken on PyPI by an unrelated project. The install name is libraryapi-sdk; the Python import name is libraryapi.

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_hoursround(annual_hours / weeks_open)

Links

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

libraryapi_sdk-0.2.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

libraryapi_sdk-0.2.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

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

Hashes for libraryapi_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5cce96b8a3b6400c20089b4b511cf978c1956496469282e10889bfface34d8a0
MD5 ea369249cbc65babdced8741a89f4dda
BLAKE2b-256 1e572c14219d46c1c90596d7b7f839eac6ab38e17c88115bedb698ca1420b1c1

See more details on using hashes here.

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

Hashes for libraryapi_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c9d4ed43e581dff86dbab41f77d44957ed02df64cd31c3c5b085e92d25c1d00
MD5 93a9451f4e1c55a9d7b45bee05a1addf
BLAKE2b-256 02fae21b43aac395cbf256aac5cb4dd97a7b944590d48055a0b5c265bb3c68fb

See more details on using hashes here.

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