Skip to main content

CensusForge

[!IMPORTANT]
Project development has moved to Codeberg

[!WARNING]
This project is still in development and may change very quickly. I will add more functionality in the future but this contains the bare minimum to support the needs of the project.

CensusForge is a Python toolkit for retrieving data from the U.S. Census API while also leveraging a local SQLite metadata database for fast lookups, the SQLite database creation repo can be found in this link in GitHub. It simplifies working with Census datasets by providing a unified interface for:

  • Downloading and caching geographic files
  • Querying the Census API
  • Looking up dataset, variable, year, and geography metadata
  • Returning results as Polars or GeoPandas objects

CensusForge consists of two main classes:

  • DataPull – Handles local metadata queries and file downloads
  • CensusAPI – Extends DataPull and adds direct Census API querying

Installation

pip install CensusForge

Quick Start Example

The following example shows how to query the Census API using the CensusAPI class.

from CensusForge import CensusAPI

def main():
    ca = CensusAPI()
    print(
        ca.query(
            dataset="acs-acs1-pumspr",
            year=2019,
            params_list=["AGEP", "SCH", "SCHL", "HINCP", "PWGTP", "PUMA"],
        )
    )

if __name__ == "__main__":
    main()

Running the above will:

  1. Look up the dataset in the local metadata database
  2. Construct the correct Census API URL
  3. Fetch the API response
  4. Convert it to a Polars DataFrame

Project Structure

CensusForge/
│
├── CensusAPI.py       # CensusAPI and DataPull classes
├── database.db        # Local SQLite metadata database
├── jp_tools/          # Utility functions (e.g., file download helper)
│
├── data/              # Output directory for downloaded/cached files
└── README.md          # Project documentation

API Overview

CensusAPI

query(dataset, params_list, year, extra="") → pl.DataFrame

Query a Census dataset using any set of variables or geography parameters.

Example

ca.query(
    dataset="acs-acs1-pumspr",
    year=2019,
    params_list=["AGEP", "HINCP", "PUMA"],
    extra="&for=state:*"
)

Metadata Helpers (inherited from DataPull)

Method Description
get_database(id) Returns dataset name for ID
get_database_id(name) Returns dataset ID
get_year(id) Returns year for ID
get_year_id(year) Returns year ID
get_variable_id(name) Returns variable ID
get_geo_id(name) Returns geography type ID
get_geo_years(dataset_id, geo_id) Returns valid years for a dataset+geography

Geospatial Tools

pull_geos(url, filename) → gpd.GeoDataFrame

Downloads a geographic file (if missing), caches it as Parquet, and returns a GeoDataFrame.


Requirements

  • Python 3.9+
  • DuckDB
  • GeoPandas
  • Polars
  • Requests
  • jp_tools (for download helper)

Install dependencies:

pip install -r requirements.txt

Development

To run tests or modify the project:

git clone https://github.com/yourusername/CensusForge.git
cd CensusForge
pip install -e .

Cite

@software{ouslan2026censusforge,
    author       = {Ouslan, Alejandro},
    title        = {CensusForge},
    month        = jan,
    year         = 2026,
    publisher    = {Zenodo},
    version      = {0.5.0},
    doi          = {10.5281/zenodo.18121581},
    url          = {https://doi.org/10.5281/zenodo.18121581}
}

License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0).

You may copy, modify, and distribute this software only under the terms of the GPL-3.0 license.

Full license text: https://www.gnu.org/licenses/gpl-3.0.en.html

Download files

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

Source Distribution

censusforge-1.2.2.tar.gz (193.6 kB view details)

Uploaded Source

Built Distribution

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

censusforge-1.2.2-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file censusforge-1.2.2.tar.gz.

File metadata

  • Download URL: censusforge-1.2.2.tar.gz
  • Upload date:
  • Size: 193.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for censusforge-1.2.2.tar.gz
Algorithm Hash digest
SHA256 c8f3230bd4b58a0bab252b378fe6dd535ea5221508d5669dc0252d34418a238a
MD5 7de7f27ce551fd4ac286c8c198d5be67
BLAKE2b-256 7b3c5a239c0f3672ea0ee05e0abd0d2db53b9cdcaa2b7a4f6e2155e5bbec2520

See more details on using hashes here.

File details

Details for the file censusforge-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: censusforge-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for censusforge-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8151aa6f495bbf3ea726903d68219bc846a818266afc82a77916c5b513efa76e
MD5 3dc5322288beed636d27805ee4931713
BLAKE2b-256 13395f1ce696fea33d5e9aa55e429ebe6d9057058f808894a2f85024d660e486

See more details on using hashes here.

Release history Release notifications | RSS feed

1.2.4

2 files

1.2.3

2 files

This release

1.2.2 This release

2 files

1.2.0

2 files

1.0.0

2 files

0.7.1

2 files

0.7.0

2 files

0.6.1

2 files

0.5.1

2 files

0.5.0

2 files

0.4.2

2 files

0.4.0

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page