Skip to main content

Python interface to the US Census Bureau API for ACS, Decennial Census, PUMS, population estimates, and migration flows.

Project description

PyPUMS

Python interface to the US Census Bureau API — American Community Survey, Decennial Census, PUMS microdata, population estimates, and migration flows.

PyPI version Python versions License Build status

Quick Start

Get county-level median household income for California:

import pypums

df = pypums.get_acs(
    geography="county",
    variables=["B19013_001"],
    state="CA",
    year=2023,
)
df.head()

Make a map with tract-level data:

df = pypums.get_acs(
    geography="tract",
    variables=["B19013_001"],
    state="CA",
    county="037",
    year=2023,
    geometry=True,  # returns a GeoDataFrame
)
df.plot(column="estimate", legend=True, figsize=(12, 8))

Work with PUMS microdata:

pums = pypums.get_pums(
    variables=["AGEP", "SEX", "WAGP"],
    state="CA",
    year=2023,
    recode=True,  # adds human-readable labels
)
pums.head()

Features

  • get_acs() — American Community Survey data (1-year and 5-year)
  • get_decennial() — Decennial Census data (2000, 2010, 2020)
  • get_pums() — PUMS microdata with replicate weight support
  • get_estimates() — Population Estimates Program data
  • get_flows() — ACS migration flows (county and MSA level)
  • load_variables() — Search and browse Census variable codes
  • MOE functionsmoe_sum(), moe_ratio(), moe_prop(), moe_product(), significance()
  • Spatial support — Attach TIGER/Line geometries, returns GeoDataFrames
  • Survey designSurveyDesign class with successive difference replication
  • Caching — File-based caching with configurable TTL
  • CLI — Command-line access to all data functions

Installation

uv add pypums

For spatial/mapping support:

uv add "pypums[spatial]"

Census API Key

You need a free Census API key. Request one here, then:

export CENSUS_API_KEY="your-key-here"

Or set it in Python:

import pypums
pypums.census_api_key("your-key-here")

Documentation

Full documentation: https://pypums.readthedocs.io

Development

To contribute to this library, first checkout the code. Then install uv and set up the project:

cd pypums
uv sync --extra test

To run the tests:

uv run pytest

To run the linter:

uvx ruff check .
uvx ruff format --check .

Citation

@misc{pypums,
  author = {Sergio Sanchez Zavala},
  title = {PyPUMS: Python interface to the US Census Bureau API},
  year = {2019},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/chekos/pypums}}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypums-0.3.tar.gz (53.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypums-0.3-py3-none-any.whl (65.2 kB view details)

Uploaded Python 3

File details

Details for the file pypums-0.3.tar.gz.

File metadata

  • Download URL: pypums-0.3.tar.gz
  • Upload date:
  • Size: 53.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pypums-0.3.tar.gz
Algorithm Hash digest
SHA256 8e9e9051e434e503eda9bf6c496839bb8d771368b4eb79a8bc51f85ef715bcfa
MD5 50fe3fb84d89fed8a20b968c46246a9a
BLAKE2b-256 4807e90e2b2394ccf74bc8a994a3534ca8b517e62168526fd880afa3687e04ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypums-0.3.tar.gz:

Publisher: publish.yml on chekos/pypums

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypums-0.3-py3-none-any.whl.

File metadata

  • Download URL: pypums-0.3-py3-none-any.whl
  • Upload date:
  • Size: 65.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pypums-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1da7065ce68b9196834b1345897fa0c3a38669145375d233f66b20620a6835cb
MD5 2956f82566090cf3063135a63d3d2093
BLAKE2b-256 e4f417b4ea77e9424171c66b4e540438c0a6ea69377dac8a0eead96d817a7264

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypums-0.3-py3-none-any.whl:

Publisher: publish.yml on chekos/pypums

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page