TL;DR
The US Census Bureau API provides programmatic access to a vast collection of data from the Decennial Census, American Community Survey (ACS) 1-year and 5-year estimates, Population Estimates Program, and economic surveys. You can query population counts by state, county, city, ZIP code; demographic breakdowns (age, race, income, housing); and economic indicators. The API returns JSON responses with a comma-separated variable format — the first row is headers, subsequent rows are data. No API key is required for basic usage, though registering for a key raises query limits.
Quick start: https://api.census.gov/data/2020/dec/pl?get=NAME,P1_001N&for=state:*
No API key needed — just make a request!
How to Use This API
1. 2020 Census Population by State
https://api.census.gov/data/2020/dec/pl?get=NAME,P1_001N&for=state:*
Returns name and total population for all 50 states plus DC and Puerto Rico.
2. ACS Population by County in California
https://api.census.gov/data/2021/acs/acs1?get=NAME,B01001_001E&for=county:*&in=state:06
B01001_001E is the total population variable. state:06 is California's FIPS code.
3. Median Household Income by ZIP Code
https://api.census.gov/data/2021/acs/acs5?get=NAME,B19013_001E&for=zip%20code%20tabulation%20area:*
B19013_001E is median household income. Available in ACS 5-year estimates for finer geography.
4. Population by Age Breakdown
https://api.census.gov/data/2021/acs/acs1?get=NAME,B01001_001E,B01001_002E,B01001_003E,B01001_020E,B01001_021E,B01001_022E,B01001_023E,B01001_024E,B01001_025E&for=state:*
Age variables: B01001_003E=under 5, B01001_020E through B01001_025E=65+.
5. Find Variable Names
https://api.census.gov/data/2020/dec/pl/variables.json
https://api.census.gov/data/2021/acs/acs5/variables.json
Use the /variables.json endpoint to discover available variable codes and their descriptions.
6. Response Format
[
["NAME", "P1_001N", "state"],
["California", "39538223", "06"],
["Texas", "29145505", "48"],
["Florida", "21538187", "12"],
...
]
The first array is headers; subsequent arrays are data rows. Parse by index.
7. JavaScript — Get State Populations
fetch('https://api.census.gov/data/2020/dec/pl?get=NAME,P1_001N&for=state:*')
.then(r => r.json())
.then(data => {
const [headers, ...rows] = data;
rows.forEach(r => {
console.log(`${r[0]}: ${parseInt(r[1]).toLocaleString()}`);
});
});
8. Python — Query by County
import requests
params = {
'get': 'NAME,B01001_001E,B19013_001E',
'for': 'county:*',
'in': 'state:06'
}
resp = requests.get(
'https://api.census.gov/data/2021/acs/acs5', params=params
)
headers, *rows = resp.json()
for row in rows:
print(f"{row[0]}: Pop={row[1]}, MedInc=${row[2]}")
9. Python — Top 10 Most Populous States
import requests
resp = requests.get(
'https://api.census.gov/data/2020/dec/pl',
params={'get': 'NAME,P1_001N', 'for': 'state:*'}
)
headers, *rows = resp.json()
rows.sort(key=lambda r: int(r[1]), reverse=True)
for state in rows[:10]:
print(f"{state[0]}: {int(state[1]):,}")
https://api.census.gov/data/2020/dec/pl?get=NAME,P1_001N&for=state:*
Frequently Asked Questions
- What survey datasets are available through the API?
- Decennial Census (2000, 2010, 2020), ACS 1-year estimates (most current), ACS 5-year estimates (best for small geographies), Population Estimates, Economic Census, and more. The full list is at
https://api.census.gov/data.html. - How do I find the right variable codes?
- Use the
/variables.jsonendpoint for any dataset. For example,https://api.census.gov/data/2020/dec/pl/variables.jsonshows all available variables with labels and descriptions. - What geographic levels are supported?
- US, region, division, state, county, tract, block group, block, place (city/town), ZIP code tabulation area (ZCTA), congressional district, state legislative district, school district, and more.
- Is there a rate limit or do I need an API key?
- No API key is needed for basic access. Without a key you get lower rate limits (approximately 500 queries per day). With a free key from the Census Bureau, limits increase to approximately 5,000 queries per day.
- What's the difference between ACS1 and ACS5?
- ACS 1-year estimates cover areas with populations over 65,000 and are more current. ACS 5-year estimates cover all areas including rural and small towns but represent a 5-year average. Use ACS5 for block group and ZIP-level data.
- Can I filter by multiple geographic levels?
- Yes, use the
inparameter for hierarchy. For example,for=tract:*&in=state:06+county:037gets all tracts in Los Angeles County, California.
What You Can Build
- Population dashboard showing state-by-state census counts with ranking
- Demographic analysis tool — compare income, age, and race across counties
- Real estate market analyzer overlaying census income data with map coordinates
- School district planner using ACS5 data for demographic projections
- Political districting tool working with block-level population data
- Economic research combining census income data with BLS employment data