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
- Docs: districtapi.dev/docs
- Dashboard: districtapi.dev/dashboard
- Pricing: districtapi.dev/pricing
- GitHub: github.com/districtapi/districtapi-python
- Issues: github.com/districtapi/districtapi-python/issues
Release files for districtapi 0.3.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 | |
|---|---|---|---|
| districtapi-0.3.0.tar.gz | 11.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| districtapi-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.3 kB
Release files / districtapi-0.3.0.tar.gz
| Download URL | districtapi-0.3.0.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a1842f2568539a9c7b30f009c233a3b90cfd614aca7a7aa4f87686118e86291
|
|
BLAKE2b-256 checksum How to use checksums |
d849ccf78d2fc0dcf2b3ccb96d941034bc3a2a63b19ac4a6dfbae1e0687484ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Release files / districtapi-0.3.0-py3-none-any.whl
| Download URL | districtapi-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
35f02d105ee654ec0ebfc1ebca88f32fde211b5cdf76618205b9789d73a3c624
|
|
BLAKE2b-256 checksum How to use checksums |
ae2c0513a68a3670f8cc6445ce21793f501d1388d024aa2bb00651eaf92c0146
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|