Census Research Engine
A research toolkit for US Census data: extract comparable measures across places and years, quantify uncertainty, and carry an analysis through to tables, maps and reproducible study outputs. The engine combines ACS area estimates, PUMS microdata, 2020 Census counts and selected external health outcomes. It offers 80 MCP tools, a Python library and a command-line interface.
Use it to compare counties or neighborhoods, study associations while accounting for noisy ACS predictors and spatial dependence, construct custom population tabulations, measure segregation or income inequality, and evaluate agreement between sources. Statistical methods have different validated ranges; an available method is not automatically suitable for every research design. Each inference method was checked by a simulation whose pass criterion was fixed in advance (90% intervals must cover at least 86% of the time); methods or settings that failed are still available but are marked exploratory in their results (validated: false and a note). STATUS.md records the current release, validation evidence and remaining limitations.
Extraction keeps estimates paired with margins of error, checks variable meanings across releases, converts dollar values to constant dollars, and records provenance. Calculations are checked against Census-published values; inference methods have separate simulation audits.
| Interface |
Entry point |
When to use it |
| MCP server |
mcp_server.py |
An MCP client or research agent selects and runs tools; profiles control which tools it sees |
| Command line |
python -m census / census-acs |
Script extraction and supported analyses; tool <name> exposes a subset of the shared workflows |
| Python library |
census |
Notebooks, custom pipelines and methods without a standalone MCP tool |
| Desktop GUI |
acs_downloader.py (Tkinter) |
Point-and-click extraction; maintenance mode, with a smaller feature surface |
Extraction uses the shared pipeline. Advanced analyses are exposed through the MCP/CLI workflows, manifests or Python; the GUI does not expose the whole research engine.
Start with choosing an analysis, MCP setup and tool inventory, or the research workflow.
Latest release: v0.77.0 (DOI 10.5281/zenodo.24444186):
- disparities between population groups and the Kitagawa decomposition;
- joinpoint trends and ratios of age-adjusted rates;
- difference-in-differences for policies adopted in different years;
- Oaxaca–Blinder and Fairlie decompositions on PUMS;
- small-area estimates for proportions near 0 or 1 and across releases;
- a spatial scan for clusters of high county counts.
CHANGELOG.md lists every round.
Installation
Requires Python 3.11 or later and SciPy 1.16 or later.
git clone https://github.com/cafeTechne/Census-Research-Engine
cd Census-Research-Engine
pip install -r requirements.txt
Or install it as an editable package from the clone (pip install -e ., or pip install -e ".[dev]" for pytest and ruff; the toolkit reads its metadata archive and data files from the repository), which adds the census-acs command (same as python -m census) and census-acs-mcp (the MCP server; census-acs-mcp --profile core). Releases are listed in CHANGELOG.md; each tagged release is archived on Zenodo with a DOI to cite.
Price-index data (R-CPI-U-RS, CPI-U, and C-CPI-U, 2000–2024) ships with the repository, so constant-dollar conversion works out of the box.
Refreshing R-CPI-U-RS (once a year, after BLS publishes a new annual average). BLS publishes the series only as an Excel file and blocks anonymous scripted downloads. Download https://www.bls.gov/cpi/research-series/r-cpi-u-rs-allitems.xlsx in a browser, save it over data/price_indexes/source/r-cpi-u-rs-allitems.xlsx, and run:
python scripts/update_price_indexes.py --r-cpi-u-rs-xlsx data/price_indexes/source/r-cpi-u-rs-allitems.xlsx
Alternatively, set BLS_USER_AGENT to an identifying User-Agent that includes a contact email (BLS's requirement for automated clients) and run the script without arguments. A year the index does not cover fails with PRICE_INDEX_UNAVAILABLE.
Configuration
| Variable |
Purpose |
CENSUS_API_KEY |
Census API key (request one); requests without a key are rate-limited |
CENSUS_CACHE_PATH / CENSUS_CACHE_DISABLED=1 |
SQLite query cache location (default .cache/census_cache.db), or disable it |
CENSUS_METADATA_DIR |
Alternate per-vintage metadata archive (default metadata/) |
CENSUS_CROSSWALK_DIR |
Alternate override directory (default crosswalks/) |
CENSUS_PRICE_INDEX_DIR |
Alternate price-index directory (default data/price_indexes/); not checksum-verified, its CSV's SHA-256 is recorded instead |
CENSUS_PRICE_PARITY_DIR |
Alternate Regional Price Parity directory (default data/price_parities/); same treatment |
BLS_USER_AGENT |
Identifying User-Agent for scripts/update_price_indexes.py |
CENSUS_VRE_DIR |
Cache for downloaded Census Variance Replicate Estimate files (default .cache/vre/) |
CENSUS_WWW2_MIN_INTERVAL / CENSUS_WWW2_ATTEMPTS / CENSUS_WWW2_BACKOFF_BASE / CENSUS_WWW2_REJECTED_RETRY_DELAY |
census.gov file downloads (census/http.py): seconds between requests to one host (default 1), attempts on HTTP 429/5xx or connection errors (4), backoff base in seconds (2; doubled per retry, capped at 60, honours Retry-After), and the wait before the single retry of a firewall "Request Rejected" page (30). A rejection that persists names the cache path where a browser-downloaded copy of the file is picked up; for a rejected (or 404) B01003 VRE file, fetch_vre instead reads the identical B01001 line 1 and records the substitution (attrs["substitution"], with a warning) |
CENSUS_LIVE_TESTS=1 |
Enable live API contract tests and the live validation battery |
CENSUS_MCP_PROFILE |
MCP tool profile (full, core, core_spatial, review, verification); same as --profile |
CENSUS_HEALTH_OFFLINE=1 |
Use only locally cached external health data (no downloads) |
CENSUS_DOTENV |
Explicit .env file. Otherwise the engine loads the first .env found upward from the working directory, then from the package location (an installed engine finds your project's .env); variables already set are never overridden |
CENSUS_PROGRESS=0 |
Silence progress lines (stderr) from long workflows: run_manifest, batch_download, replicate refits |
CENSUS_VERIFICATION_REQUEST |
The locally reviewed proposition pinned for --profile verification |
Exact proposition verification (opt-in). The verification workflow pins a locally reviewed proposition through CENSUS_VERIFICATION_REQUEST before the server starts with --profile verification; model tools cannot approve formalizations. python scripts/verification_eval.py --request request.json prepares prompts and scores transcripts offline and contacts no model service. scripts/verification_live.py --run-model ... tests a chosen local runtime explicitly; the guide lists its settings and raw traces.
Quick start
Python
from census import ResearchOptions, build_entities, plan_extraction, run_batch
entities = build_entities("tract", "48", ["453"]) # all tracts in Travis County, TX
options = ResearchOptions(compute_reliability=True, inflation_base_year=2022, include_codebook=True)
plan = plan_extraction("B19013", entities, range(2015, 2023), "parquet", options,
variables=["B19013_001"]) # name the variables you analyze
print(plan["would_block"], plan["selection"], plan["issues"][:3])
result = run_batch("B19013", entities, range(2015, 2023), "out", "parquet", options,
variables=["B19013_001"])
print(result["success"], result.get("error_code"), result.get("panel_path"))
Results are dictionaries. Failures carry success: False, an error_code, and error; nothing raises on API failure.
Command line
python -m census plan --table DP02 --geo state --state 36 --years 2018-2022 --variables DP02_0016 --json
python -m census extract --table DP02 --geo state --state 36 --years 2018-2022 --variables DP02_0016 --out out --json
python -m census concordance --table B27001 --years 2016-2017 --variables B27001_006 --json
python -m census describe --code DP02_0002PE --year 2018
python -m census extract --table B19013 --geo county --state all --years 2022 --format parquet --out out
python -m census replay out/B19013_extraction_metadata.json --json
python -m census derive proportion --estimates 4500,30000 --moes 400,900 --json
python -m census aggregate --input out/B17001_tract_panel_2023.csv --groups groups.csv --year 2023 \
--derive '[{"name": "poverty_rate", "op": "proportion", "num": "B17001_002E", "den": "B17001_001E"}]'
python -m census validate --offline
Exit codes: 0 success, 2 invalid input, 3 concordance review required, 4 API or data failure.
MCP server
claude mcp add census -- python mcp_server.py
Call get_recipe() to list the 25 task guides, then get_recipe(name="regression_sampling_error") (or another recipe) for the steps and applicable limits. get_recipe is in the core and full profiles. get_research_protocol returns the full protocol in profiles that expose it. Client configuration is in docs/claude_setup.md.
| Profile |
Tools |
Use |
full (default) |
80 |
All registered tools; use this for the complete research workflow |
core |
16 |
A smaller set for discovery, extraction, basic models, group/PUMS tests and outputs; guided results include summary and next_step |
core_spatial |
17 |
Core plus spatial_autocorrelation; advanced tools such as rank_areas still require full |
review |
10 |
Variable concordance and independent review of overrides |
verification |
1 |
The separate operator-pinned proposition workflow; requires its reviewed request |
Select a profile with python mcp_server.py --profile core or CENSUS_MCP_PROFILE=core. Switching profiles changes tool visibility, not the underlying statistical methods. Small local-model setup and evaluations are in docs/local_models.md.
The CLI runs every shared analysis workflow through python -m census tool <name> (Round 64 added compare_groups, test_association, estimate_effect, check_agreement, combine_estimates, rank_areas, build_index, list_health_sources, run_variant and interrupted_series). The MCP tools it does not list are discovery, metadata and review tools with their own CLI subcommands or server-only behaviour. For a supported offline calculation, estimate the difference that two MOEs can detect:
python -m census tool minimum_detectable_difference --arg moe1=2.1 --arg moe2=2.4 --json
All 26 recipes