Skip to main content

Python SDK for the districtapi.dev API — US school district and school data

Project description

districtapi

Python SDK for districtapi.dev — US school district and school data from NCES federal datasets.

The killer feature: look up any US address and get back the school district serving it, with full enrollment, demographics, finances, school list, and GeoJSON boundary — all in one call.

Install

pip install districtapi

Quick start

Get a free API key at districtapi.dev/dashboard — no credit card, 250 requests/month free forever.

from districtapi import DistrictAPI

client = DistrictAPI(api_key="sk_live_...")

# Address → district (the killer feature)
district = client.districts.get(address="123 Main St, Apple Valley, CA")
print(district.name)                           # Apple Valley Unified School District
print(district.enrollment.total)               # 17432
print(district.finance.per_pupil_expenditure)  # 9823.45
print(district.geo.boundary)                   # GeoJSON MultiPolygon

# Lat/lng lookup
district = client.districts.get(lat=34.4988, lng=-117.1858)

# By NCES ID
district = client.districts.fetch("0600017")

# Search by name/state
results = client.districts.search(name="Apple Valley", state="CA")
for d in results:
    print(d.nces_id, d.name, d.enrollment_total)

# Schools in a district
schools = client.districts.schools("0600017")
for school in schools:
    print(school.name, school.grades.low, school.grades.high)

# Schools near an address
nearby = client.schools.near(address="123 Main St, Apple Valley, CA", radius_miles=3.0)

# A specific school
school = client.schools.fetch("060001700123")
print(school.name, school.flags.is_charter)

# School → district
district = client.schools.district("060001700123")

Async support

import asyncio
from districtapi import AsyncDistrictAPI

async def main():
    async with AsyncDistrictAPI(api_key="sk_live_...") as client:
        district = await client.districts.get(address="123 Main St, Apple Valley, CA")
        print(district.name)

asyncio.run(main())

Context manager

with DistrictAPI(api_key="sk_live_...") as client:
    district = client.districts.get(address="1600 Pennsylvania Ave, Washington, DC")

Error handling

from districtapi import DistrictAPI, NotFoundError, AuthenticationError, RateLimitError

client = DistrictAPI(api_key="sk_live_...")

try:
    district = client.districts.get(address="123 Nowhere St")
except NotFoundError:
    print("No district found for that address")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError:
    print("Rate limit exceeded — upgrade at districtapi.dev/pricing")

Response types

All methods return typed dataclasses. Key types:

Type Fields
District nces_id, name, state, county, enrollment, finance, students, geo, schools_count
DistrictSummary nces_id, name, state, county, enrollment_total, lat, lng
School nces_id, nces_district_id, name, state, grades, flags, enrollment, address, geo
DistrictEnrollment total, year, demographics
DistrictFinance per_pupil_expenditure, total_revenue, federal_revenue_pct, fiscal_year
GeoPoint lat, lng, boundary (GeoJSON)

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

districtapi-0.2.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

districtapi-0.2.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file districtapi-0.2.0.tar.gz.

File metadata

  • Download URL: districtapi-0.2.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for districtapi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1c4455d4b87cc3fce8dffd68ffafb62013c12b311f71fe9c8684401f5160f0fe
MD5 7700430520eb2e64bcdf4ebf15ef793f
BLAKE2b-256 6c199ed7039f1a0758139721c19e6b3dde3f7b027a0144a8b1da381e8abf62d3

See more details on using hashes here.

File details

Details for the file districtapi-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: districtapi-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for districtapi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72fcae1d3972a95f0bd6dca9c7dd4ae63c93286ba0eb35f926397de525321a08
MD5 86351bbd1e310bcfd2e559cdc237f6a3
BLAKE2b-256 f4e48ba13084dfe0c5bca512b017a82f01017a1552e491b101515ae7f79428a8

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