Census data tools used by MORPC
Project description
morpc-census
Introduction
morpc-census is a Python package maintained by the MORPC data team for working with US Census Bureau data. It provides tools for connecting to the Census API, retrieving survey data, and structuring results as long-format tables with frictionless metadata.
This package depends on morpc-py for shared MORPC utilities.
Modules
- morpc_census.api — Census API client (
Endpoint,Group,CensusAPI) and data structuring classes (DimensionTable,RaceDimensionTable,TimeSeries,RaceTable) for reshaping results into long- and wide-format DataFrames with frictionless metadata. - morpc_census.geos — Geography utilities:
Scope(named query extents),SumLevel(summary level codes),GeoIDFQ(GEOID parser/builder), and functions for translating between Census GEOIDs and MORPC geography definitions. - morpc_census.tigerweb — Fetches GeoDataFrames from the Census TIGERweb REST API.
- morpc_census.constants — Domain lookup tables for age groups, race, education, income-to-poverty, and NTD categories.
Installation
pip install morpc-census
Dev Install
To install an editable version for development:
git clone https://github.com/jinskeep-morpc/morpc-census.git
pip install -e /path/to/morpc-census/
Then import as:
import morpc_census
Usage
from morpc_census import Endpoint, Group, CensusAPI, DimensionTable, RaceDimensionTable, SCOPES, SumLevel
ep = Endpoint('acs/acs5', 2023)
grp = Group(ep, 'B01001')
# Fetch ACS 5-year age/sex data for counties in the 15-county region
api = CensusAPI(ep, SCOPES['region15'], group=grp, sumlevel=SumLevel('county'))
# Long-format DataFrame
print(api.long.head())
# Reshape into wide MultiIndex table and compute percentages
table = DimensionTable(api.long)
wide = table.wide()
pct = table.percent()
# Save data + frictionless schema + resource to disk
api.save('./output')
Demos and Documentation
See demos for examples and documentation.
Roadmap — Code Improvements
- Fix Python 3.10/3.11 syntax bug in
geos.py - Cache
_get_api_key() - Replace global
_avail_endpoints_cachewith@functools.cache - Avoid double-computing
wide()insidepercent() - Rename
DimensionTable.variable_type→value_cols - Rename
mapparameter infind_replace_variable_map→label_map - Split
CensusAPI.melt()into focused private helpers - Pin
numpyas an explicit dependency - Add minimum version pins to all dependencies
- Add module docstrings to
geos.pyandtigerweb.py - Validate or auto-fetch
tigerweb.pycurrent_endpoints
Roadmap — Production Readiness & PyPI Release
Phase 1 — Pre-release cleanup
- Apply all code improvement items above
- Fix the README usage example
- Expand test coverage for offline paths (
wide(),percent(),remap(),drop(),melt()) - Update
pyproject.tomlclassifier fromDevelopment Status :: 1 - Planningto4 - Beta - Add a
CHANGELOG.md - Add a
py.typedmarker file
Phase 2 — Dependency audit
- Assess whether
morpccan be published to PyPI or replaced - Document installation order if
morpcremains a private dependency - Pin
morpcto a minimum version inpyproject.toml
Phase 3 — CI/CD
- Add GitHub Actions CI workflow (
pytest -m "not network"on push/PR, Python 3.10–3.12) - Add build verification step (
python -m build+twine check) - Add publish workflow triggered on release tags
Phase 4 — Versioning & release
- Switch to dynamic versioning via
setuptools-scm - Tag
v0.1.0and publish first release - Document versioning policy and breaking-change rules in
CONTRIBUTING.md
Phase 5 — Documentation
- Auto-generate API reference docs from docstrings
- Add
CONTRIBUTING.mdwith setup instructions and PR process - Add usage examples to docstrings for commonly called functions
This product uses the Census Bureau Data API but is not endorsed or certified by the Census Bureau.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file morpc_census-0.3.0.tar.gz.
File metadata
- Download URL: morpc_census-0.3.0.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f1260004483e293a2546a132751122f5d494e8c53968d47f0545bbc4bf70687
|
|
| MD5 |
548e6ec4e273b3dc8dfb492de7df85ee
|
|
| BLAKE2b-256 |
9a99fed8ff0f6a45ca7a9781ecd2b5787ab583b6d00166ee80b41ea67ba394bb
|
Provenance
The following attestation bundles were made for morpc_census-0.3.0.tar.gz:
Publisher:
publish.yml on jinskeep-morpc/morpc-census
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morpc_census-0.3.0.tar.gz -
Subject digest:
6f1260004483e293a2546a132751122f5d494e8c53968d47f0545bbc4bf70687 - Sigstore transparency entry: 1645970055
- Sigstore integration time:
-
Permalink:
jinskeep-morpc/morpc-census@74c190d30f8a1f163444fa3a52bef9e285922fdf -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/jinskeep-morpc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@74c190d30f8a1f163444fa3a52bef9e285922fdf -
Trigger Event:
release
-
Statement type:
File details
Details for the file morpc_census-0.3.0-py3-none-any.whl.
File metadata
- Download URL: morpc_census-0.3.0-py3-none-any.whl
- Upload date:
- Size: 68.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
338865f86882166d0486d4d6ad640be6bffbe44242c8bb88445eecd8b21e0a63
|
|
| MD5 |
f86be2c6ab7ff83385120c00b2d22315
|
|
| BLAKE2b-256 |
8fc602d7d87b3e3f32612dc2d9656858d6a4cba58cb8bb1d8086402eaec5932c
|
Provenance
The following attestation bundles were made for morpc_census-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on jinskeep-morpc/morpc-census
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morpc_census-0.3.0-py3-none-any.whl -
Subject digest:
338865f86882166d0486d4d6ad640be6bffbe44242c8bb88445eecd8b21e0a63 - Sigstore transparency entry: 1645970162
- Sigstore integration time:
-
Permalink:
jinskeep-morpc/morpc-census@74c190d30f8a1f163444fa3a52bef9e285922fdf -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/jinskeep-morpc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@74c190d30f8a1f163444fa3a52bef9e285922fdf -
Trigger Event:
release
-
Statement type: