Get the FREE Ultimate OpenClaw Setup Guide →

us-census-data

npx machina-cli add skill MisterClean/claude-plugins/us-census-data --openclaw
Files (1)
SKILL.md
7.6 KB

US Census Data Skill

Query demographic, economic, housing, and population data from the US Census Bureau API. Supports American Community Survey (ACS), Decennial Census, and Population Estimates.

Prerequisites

Before querying, check if the user has an API key:

  1. Look for CENSUS_API_KEY in the user's .env file
  2. If found, append to requests: &key=<api_key>
  3. If not found, instruct the user to:

The API works without a key for testing but is rate-limited and may block requests.

Quick Start

The Census API is at api.census.gov. Queries require:

  1. Dataset path: /data/{year}/{dataset} (e.g., /data/2022/acs/acs5)
  2. Variables: ?get=NAME,B01001_001E (variable codes)
  3. Geography: &for=county:*&in=state:17 (FIPS codes)
  4. API Key: &key=YOUR_KEY (required for production use)

Workflow

Step 1: Clarify the Data Need

Ask the user:

  • Topic: What data? (population, income, housing, education, poverty, etc.)
  • Geography: What level? (nation, state, county, tract, block group, ZCTA?)
  • Time period: Which year(s)?
  • Dataset: ACS 5-year (most common), ACS 1-year, or Decennial Census?

Step 2: Choose the Dataset

NeedDatasetEndpointNotes
Detailed demographics (small areas)ACS 5-Year/data/{year}/acs/acs5Block group+, most reliable
Recent data (large areas only)ACS 1-Year/data/{year}/acs/acs165k+ population areas only
Exact population countsDecennial/data/2020/dec/dhcEvery 10 years, block level
Annual population changePop Estimates/data/{year}/pep/populationCounty+, intercensal

See references/datasets.md for complete dataset documentation.

Step 3: Find Variables

Census variables use codes like B19013_001E (median household income). The E suffix = estimate, M suffix = margin of error.

Option A - Popular Variables Reference: See references/popular-variables.md for curated list of common variables.

Option B - Variable Search API:

GET https://api.census.gov/data/2022/acs/acs5/variables.json

Option C - Groups (Tables) API:

GET https://api.census.gov/data/2022/acs/acs5/groups.json

See references/datasets.md for common table prefixes and naming conventions.

Step 4: Build the Query

Basic structure:

https://api.census.gov/data/{year}/{dataset}?get={variables}&for={geography}&key={api_key}

Example - Median income by county in Illinois:

https://api.census.gov/data/2022/acs/acs5?get=NAME,B19013_001E&for=county:*&in=state:17&key=YOUR_KEY

Geography predicates:

  • for=state:* - All states
  • for=county:*&in=state:17 - All counties in Illinois
  • for=tract:*&in=state:17&in=county:031 - All tracts in Cook County, IL
  • for=block%20group:*&in=state:17&in=county:031&in=tract:010100 - Block groups in tract

See references/geographies.md for complete geography hierarchy and FIPS codes.

Step 5: Handle Response

Census API returns JSON array where first row is column headers:

[
  ["NAME", "B19013_001E", "state", "county"],
  ["Cook County, Illinois", "62088", "17", "031"],
  ["DuPage County, Illinois", "99007", "17", "043"]
]

For large queries, the API has no built-in pagination. Request specific geographies or use &in= filters.

Query Syntax Reference

Parameters

ParameterPurposeExample
getVariables to returnget=NAME,B01001_001E,B19013_001E
forTarget geographyfor=county:* or for=county:031
inParent geography filterin=state:17
keyAPI keykey=abc123

Variable Syntax

  • Request multiple: get=NAME,B01001_001E,B19013_001E (comma-separated)
  • Request table: get=group(B19013) (all variables in table)
  • Include MOE: get=B19013_001E,B19013_001M

Geography Wildcards

Use * for "all" at that level:

  • for=state:* - All 50 states + DC + territories
  • for=county:*&in=state:06 - All counties in California
  • for=tract:*&in=state:06&in=county:037 - All tracts in LA County

Common Query Patterns

State-level totals:

curl "https://api.census.gov/data/2022/acs/acs5?get=NAME,B01001_001E&for=state:*&key=$CENSUS_API_KEY"

County-level within a state:

curl "https://api.census.gov/data/2022/acs/acs5?get=NAME,B19013_001E&for=county:*&in=state:17&key=$CENSUS_API_KEY"

Tract-level (requires state + county):

curl "https://api.census.gov/data/2022/acs/acs5?get=NAME,B01001_001E&for=tract:*&in=state:17&in=county:031&key=$CENSUS_API_KEY"

Multiple variables:

curl "https://api.census.gov/data/2022/acs/acs5?get=NAME,B01001_001E,B19013_001E,B25001_001E&for=county:*&in=state:17&key=$CENSUS_API_KEY"

Output Format

Provide the user with:

  1. Dataset: Name + endpoint + year
  2. Variables: Code + label for each
  3. Geography: Level + filters
  4. Query: Full URL or curl command
  5. Caveats: MOE notes, update frequency, limitations

Example Response Format

Dataset: ACS 5-Year 2022
Endpoint: https://api.census.gov/data/2022/acs/acs5

Variables:
- NAME: Geography name
- B19013_001E: Median Household Income (estimate)
- B19013_001M: Median Household Income (margin of error)

Geography: All counties in Illinois (state FIPS 17)

Query:
curl "https://api.census.gov/data/2022/acs/acs5?get=NAME,B19013_001E,B19013_001M&for=county:*&in=state:17&key=$CENSUS_API_KEY"

Note: ACS data are estimates with margins of error. 5-year estimates are most reliable for small geographies.

Troubleshooting

IssueCauseFix
400 Bad RequestInvalid variable or geographyCheck variable exists for that dataset/year
204 No ContentValid query, no matching dataGeography may not exist or have data
Empty array []No data for that geographyTry different year or geography level
"error: unknown variable"Variable doesn't existUse variables.json endpoint to verify
Missing data for small areasACS 1-year limitationUse ACS 5-year for areas <65k population

Margins of Error (ACS Data)

ACS estimates have sampling error. Always consider:

  • E suffix = estimate, M suffix = margin of error (90% confidence)
  • Small geographies have larger MOEs
  • 5-year estimates are more reliable than 1-year
  • Decennial Census has no MOE (100% count)

See references/datasets.md for MOE calculation guidance.

Geometry (TIGERweb)

Census data API returns tabular data only. For geographic boundaries, use TIGERweb:

See references/tigerweb.md for geometry retrieval and data joining.

Additional Resources

Reference Files

  • references/datasets.md - Complete dataset documentation (ACS, Decennial, PEP)
  • references/popular-variables.md - Curated list of common variables by topic
  • references/geographies.md - Geography hierarchy, FIPS codes, nesting rules
  • references/tigerweb.md - Boundary/geometry retrieval via TIGERweb API

Example Files

  • examples/python-query.py - Python code with requests library
  • examples/curl-examples.sh - curl command templates

Source

git clone https://github.com/MisterClean/claude-plugins/blob/main/skills/us-census-data/SKILL.mdView on GitHub

Overview

This skill fetches demographic, economic, housing, and population data from the US Census Bureau API, including ACS, Decennial Census, and Population Estimates. It enables precise queries by year, dataset, geography, and variables to support analytics and planning.

How This Skill Works

The skill constructs requests to api.census.gov using the /data/{year}/{dataset} path, specifying variables with ?get and geo filters with for and in. It checks for a CENSUS_API_KEY in the environment and appends &key=<api_key> when available, guiding the user to obtain one if missing. Responses are returned as JSON for easy parsing and analysis.

When to Use It

  • Get population estimates by state or county
  • Pull median income or other demographics from ACS
  • Query Decennial Census counts for a region
  • Download housing or poverty statistics for planning
  • Perform a Census API query for a specific geography and year

Quick Start

  1. Step 1: Ensure CENSUS_API_KEY is set in your .env or obtain one from the Census API signup page
  2. Step 2: Build a sample request URL, e.g. https://api.census.gov/data/2022/acs/acs5?get=NAME,B19013_001E&for=county:*&in=state:17&key=YOUR_KEY
  3. Step 3: Run the request and parse the JSON response (header row plus data rows)

Best Practices

  • Verify API key exists in your environment as CENSUS_API_KEY before querying
  • Choose the right dataset: ACS 5-year for detailed small-area data, ACS 1-year for larger areas, Decennial for exact counts
  • Clarify geography with precise for and in parameters (state, county, tract, etc.)
  • Test requests with example URLs to validate variables and geography before full runs
  • Be mindful of rate limits; use a key for production queries and cache results when possible

Example Use Cases

  • Median household income by county in Illinois using ACS 5-year
  • Population by state from Population Estimates for 2020
  • Housing units by state from ACS data
  • Poverty status by tract in a metropolitan area
  • List of variables for a custom table to compare education levels across counties

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers