Census.gov

Government API · US Census Bureau · Demographic & economic data

TL;DR

The US Census Bureau provides free API access to its comprehensive datasets including the Decennial Census (population counts), American Community Survey (economic/demographic estimates), and economic indicators. Query by state, county, city, or zip code to get population totals, race/ethnicity breakdowns, median income, housing units, and more. The API uses a SQL-like syntax with get and for parameters. No API key required for basic queries, though a free key unlocks higher rates.

Quick start: https://api.census.gov/data/2020/dec/pl?get=NAME,P1_001N&for=state:*

Free access — register for a key for higher limits!

How to Use This API

1. Get Population for All States

This query retrieves name and total population for every US state from the 2020 Census:

https://api.census.gov/data/2020/dec/pl?get=NAME,P1_001N&for=state:*

get specifies the columns to return. P1_001N is the total population. for=state:* means all states.

2. Population for a Specific County

https://api.census.gov/data/2020/dec/pl?get=NAME,P1_001N&for=county:037&in=state:06

Returns data for Los Angeles County, California (state FIPS 06, county FIPS 037).

3. JavaScript — State Population Dashboard

fetch('https://api.census.gov/data/2020/dec/pl?get=NAME,P1_001N&for=state:*')
  .then(r => r.json())
  .then(data => {
    // First row is headers
    const headers = data[0];
    const rows = data.slice(1).map(r => ({
      state: r[0],
      population: parseInt(r[1]),
      fips: r[2]
    }));
    rows.sort((a, b) => b.population - a.population);
    console.log('Most populous states:');
    rows.slice(0, 10).forEach(s =>
      console.log(`${s.state}: ${s.population.toLocaleString()}`));
  });

4. Python — ACS Median Income Query

import requests

# American Community Survey 2022 median household income by state
r = requests.get(
  'https://api.census.gov/data/2022/acs/acs1/subject',
  params={'get': 'NAME,S1901_C01_001E', 'for': 'state:*'}
)
if r.status_code == 200:
    rows = r.json()
    for row in rows[1:10]:  # Skip header
        print(f"{row[0]}: ${float(row[1]):,.0f}")
All states population: https://api.census.gov/data/2020/dec/pl?get=NAME,P1_001N&for=state:*

Frequently Asked Questions

Do I need an API key?
Not for basic usage! A DEMO_KEY is available for testing. For 500+ requests per day, register a free key at api.census.gov/key.
What datasets are available?
Decennial Census (2000, 2010, 2020), American Community Survey (1-year and 5-year estimates), Population Estimates, Economic Indicators, and more.
How do I find the right variable codes?
The Census provides variable lists for each dataset. For the 2020 Census, use the 2020 PL Summary File documentation. For ACS, use ACS Subject Tables documentation.
What geographic levels are supported?
US, state, county, tract, block group, block, place (city/town), zip code tabulation area (ZCTA), congressional district, and school district.
What is the rate limit?
Without an API key, you get 500 queries per day per IP. With a free key, 5,000 per day. The key is free and instant.
Can I query historical Census data?
Yes — the 2000 and 2010 Decennial Census are also available. Use the appropriate year in the URL path, e.g., /data/2010/.

API Details

API URL
https://api.census.gov/data/2020/dec/pl
Documentation
census.gov/data/developers
Category
Government
Authentication
Optional free API key (not needed for basics)
Geographic Coverage
United States — all states, counties, cities, and census tracts

What You Can Build