Skip to main content

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) 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

morpc-census depends on morpc-py, a private MORPC utility package that is not on PyPI. Install it manually before installing morpc-census:

# 1. Install the private morpc dependency first
git clone https://github.com/morpc/morpc-py.git
pip install /path/to/morpc-py/

# 2. Install morpc-census
pip install morpc-census

Dev Install

To install an editable version for development:

# 1. Install the private morpc dependency
git clone https://github.com/morpc/morpc-py.git
pip install /path/to/morpc-py/

# 2. Clone and install morpc-census in editable mode
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_cache with @functools.cache
  • Avoid double-computing wide() inside percent()
  • Rename DimensionTable.variable_typevalue_cols
  • Rename map parameter in find_replace_variable_maplabel_map
  • Split CensusAPI.melt() into focused private helpers
  • Pin numpy as an explicit dependency
  • Add minimum version pins to all dependencies
  • Add module docstrings to geos.py and tigerweb.py
  • Validate or auto-fetch tigerweb.py current_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.toml classifier from Development Status :: 1 - Planning to 4 - Beta
  • Add a CHANGELOG.md
  • Add a py.typed marker file

Phase 2 — Dependency audit

  • Assess whether morpc can be published to PyPI or replaced
  • Document installation order if morpc remains a private dependency
  • Pin morpc to a minimum version in pyproject.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.0 and 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.md with 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


Download files

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

Source Distribution

morpc_census-0.1.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

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

morpc_census-0.1.0-py3-none-any.whl (54.8 kB view details)

Uploaded Python 3

File details

Details for the file morpc_census-0.1.0.tar.gz.

File metadata

  • Download URL: morpc_census-0.1.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

Hashes for morpc_census-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c0f25fb60d42eca8dc8f6d992e09a6fd48c0078f6d5e44a331ffc51233a235c2
MD5 b24ac2a30141e10fcd8621bf34eea686
BLAKE2b-256 e60fc27a85a143a72a3e20ed959f989f14985eb131c5fe0ad2277d59e6d88c57

See more details on using hashes here.

Provenance

The following attestation bundles were made for morpc_census-0.1.0.tar.gz:

Publisher: publish.yml on jinskeep-morpc/morpc-census

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

File details

Details for the file morpc_census-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: morpc_census-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 54.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for morpc_census-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ba8814c0092c4d3be1fb389897a77bdcdf14e50844e4260a9fbec32aacc9837
MD5 bae301396995529f871a2dd2e0b3483b
BLAKE2b-256 f485748fdc6a8d64bef6542c3013aa8f714eeb27cf7afcf761fce2ab9309c7ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for morpc_census-0.1.0-py3-none-any.whl:

Publisher: publish.yml on jinskeep-morpc/morpc-census

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