Census API Wrapper

raw JSON →
0.8.26 verified Fri May 01 auth: no python

A Python wrapper for the US Census Bureau's API, providing simple access to ACS, Decennial Census, and other datasets. Current version 0.8.26, with yearly updates for new data years.

pip install census
error NoAuthHandlerError: No API key provided
cause Missing or empty API key string passed to Census constructor.
fix
Set your Census API key before creating instance: c = Census('your_key_here')
error census.core.CensusUnavailable: 400 Client Error: Bad Request for url
cause Invalid variable code, year, or geography specification.
fix
Verify variable codes and geography parameters (e.g., state FIPS code) via Census API documentation.
gotcha Variable names come from Census API, not library; ensure you use valid codes (e.g., 'B01001_001E').
fix Check Census API documentation for available variables per dataset and year.
deprecated Support for ACS 1-year estimates may be dropped in future; always specify year to avoid surprises.
fix Explicitly pass year parameter to ACS methods (e.g., .acs5.state(..., year=2023)).

Initialize with API key, then call endpoint methods (e.g., acs5.state) with variables and location.

from census import Census

# Get your API key from https://api.census.gov/data/key_signup.html
api_key = os.environ.get('CENSUS_API_KEY', '')
c = Census(api_key)

# Fetch ACS5 2023 data for a state
result = c.acs5.state(('NAME', 'B01001_001E'), 'Illinois')
print(result)