Installation¶
Requirements¶
- Python 3.10 or newer
- A Census API key (free, instructions below)
Install PyPUMS¶
This installs PyPUMS and its core dependencies:
| Package | Purpose |
|---|---|
httpx |
HTTP client for Census API requests |
pandas |
DataFrames for tabular data |
pyarrow |
Parquet support and fast columnar storage |
rich |
Pretty terminal output |
typer |
CLI framework |
us |
US state abbreviations and FIPS codes |
Spatial extras¶
If you plan to work with shapefiles, choropleths, or any geometry (the geometry=True parameter), install the spatial extras:
This adds geopandas and pygris (plus their dependencies), enabling geometry=True to return GeoDataFrame objects. pygris handles shapefile downloads with automatic local caching — files are only downloaded once.
Get a Census API key¶
The Census Bureau requires a free API key for most data requests. Getting one takes about 30 seconds:
- Go to https://api.census.gov/data/key_signup.html
- Fill in your name and email address
- Check your inbox and click the activation link
- Copy the key from the confirmation email
No key needed for small tests
The Census API allows a limited number of unauthenticated requests. For anything beyond quick exploration, you will want a key.
Configure your API key¶
PyPUMS looks for your Census API key in this order:
- Explicit
keyparameter passed to any function call CENSUS_API_KEYenvironment variable- Session key set via
census_api_key()in Python
Choose whichever method fits your workflow.
Option 1: Environment variable (recommended)¶
Set the CENSUS_API_KEY environment variable so every tool on your system can find it.
Option 2: CLI command¶
Use the built-in pypums config command to set the key for the current session:
Note
This stores the key in the CENSUS_API_KEY environment variable for the
duration of your shell session. It does not persist across terminal restarts.
For permanent storage, use Option 1.
Option 3: Python¶
Set the key at the top of your script or notebook:
This stores the key in the CENSUS_API_KEY environment variable for the current process. All subsequent PyPUMS calls will use it automatically.
You can also pass the key directly to any function:
Verify your installation¶
Run this in your terminal to confirm PyPUMS is installed:
You should see the version number printed (e.g. 0.3).
To verify the CLI is available:
To confirm your API key is configured correctly:
If this prints your key without raising an error, you are ready to go.
Troubleshooting¶
I get ModuleNotFoundError: No module named 'pypums'
Make sure you installed PyPUMS in the same Python environment you are running. Check with:
If nothing is printed, install it again:
I get ValueError: No Census API key found
PyPUMS could not locate your key. Double-check that the environment variable is set:
If empty, follow the configuration steps above.
I get ImportError: geopandas or ImportError: pygris when using geometry=True
You need the spatial extras. Install them with:
Next steps¶
- Quick Start – run your first three queries
- Census 101 – learn which dataset to use