bascet
bascet = BASic CEnsus Tables.
A way to easily grab some pre-formatted tables from the American Community Survey.
Examples with the Decennial Census and CPS forthcoming.
Install
pip install bascet
Census API key
bascet downloads data from the Census Bureau API, which needs a free API key. If you don't have one, request it here: https://api.census.gov/data/key_signup.html
Save your key once with save_api_key():
import bascet
bascet.save_api_key("your-census-api-key")
This does two things:
- Writes
CENSUS_API_KEY="your-census-api-key"to a.envfile in your current working directory (creating the file if needed, or updating the key if it is already there). - Sets the
CENSUS_API_KEYenvironment variable for the current Python session, so you can start downloading right away.
It returns the path of the .env file it wrote.
In later sessions you don't need to call it again: every download function looks up the key automatically (via get_api_key()), first from the CENSUS_API_KEY environment variable, then from a .env file in the current working directory or any of its parent folders. So run your scripts or notebooks from the folder where you saved the key (or one below it). If no key is found, you'll get a KeyError asking you to run save_api_key().
Other ways to provide the key:
- Set the
CENSUS_API_KEYenvironment variable yourself. - Copy .env.example to
.envand replace the placeholder with your key. - Pass it directly to any download function with
api_key="...".
Keep your key private. Don't commit your
.envfile. Add.envto your.gitignoreif your project is in a git repository.
Examples
Simple:
from bascet import make_basics_tables, acs2csv, acs2spat
from censusdis.states import STATE_RI
basics = make_basics_tables(state=STATE_RI)
acs2csv(basics, "ri_basics.csv")
acs2spat(basics, "ri_basics.gpkg")
acs2spat(basics, "ri_basics.shp") # short column names
Combination / Advanced:
See the demo notebook,
or create your own tables with dwnld_acs5().
Exporting
Every table can be saved with one of the export helpers. If out_path has no file
extension, the default one is added. The folder you save into must already exist.
| Function | Output | Notes |
|---|---|---|
acs2csv(tab, out_path) |
.csv |
Drops the geometry column first. |
acs2parquet(tab, out_path) |
.parquet |
Keeps geometry when given a GeoDataFrame. |
acs2spat(tab, out_path, vint=2024) |
.gpkg (default) or .shp |
Needs a GeoDataFrame. For .shp, columns are renamed to 10 characters (shapefile limit) using ten_char_names(). Set vint to your data's year so the median income column is renamed correctly. |
ten_char_names(vintage=2024) |
dict |
The full-name → 10-character column mapping used for shapefiles. |
Tables
Every function below returns a geopandas.GeoDataFrame (one row per geography, with
geometry). All share the same arguments (state, county, geo, vintage,
dataset, api_key), and every table also includes these ID columns:
GEOID, STATE, COUNTY, PLACE, TRACT, NAME, geometry.
ID columns that don't apply to the chosen geo are left empty (e.g. TRACT for
geo="county").
All % return values are between 0 and 1.
| Function | What it returns | Key columns |
|---|---|---|
dwnld_acs5(cols, ...) |
Any ACS variables you choose (build your own table). | Your requested cols |
make_basics_tables() |
Universe counts: total population, households, and housing units. | total_population_universe, total_households_universe, total_housing_units_universe |
make_age_sex_tables() |
% of population that is female and in three policy-relevant age groups. | sex_female_percent, age_under_5_percent, age_under_18_percent, age_over_64_percent |
make_race_tables() |
% of population by race and Hispanic/Latino origin. | race_not_hispanic_{white,black,aian,asian,nhpi,otherrace}_alone_percent, race_not_hispanic_percent, race_hispanic_percent, race_personofcolor_percent |
make_pov_limit_tables() |
% of population by income relative to the federal poverty threshold. | federal_poverty_limit_below_percent, federal_poverty_limit_between_100_149_percent, federal_poverty_limit_above_150_percent |
make_med_inc_tables() |
Median household income, in dollars of the vintage year. |
median_household_income_{vintage}$ (e.g. median_household_income_2024$) |
make_civ_emp_tables() |
% of population 16+ in/out of the civilian labor force, and % of the civilian labor force employed/unemployed. | employment_civilian_labor_force_percent, employment_civilian_labor_force_employed_percent, employment_civilian_labor_force_unemployed_percent, employment_not_in_labor_force_percent |
make_tenure_tables() |
% of households in owner- vs. renter-occupied housing. | tenure_owner_occupied_percent, tenure_renter_occupied_percent, tenure_total_hh |
make_occupancy_tables() |
% of housing units that are occupied vs. vacant. | total_housing_units_universe, occupied_housing_units_percent, vacant_housing_units_percent |
make_units_in_struct_tables() |
% of occupied housing units by number of units in the building. | units_in_struct_occupied_housing_units (total), then units_in_struct_occupied_housing_units_{1_detached,1_attached,2,3_4,5_9,10_19,20_49,50_more,mobile_home,boat_rv_van_etc}_percent |
make_year_built_tables() |
% of buildings by decade built. | year_struct_built_{2020_later,2010_2019,2000_2009,...,1940_1949,pre_1940}_percent, year_struct_built_total_struct |
For full details on any function, use help(), e.g. help(bascet.make_race_tables).
Metadata
Release files for bascet 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bascet-0.0.1.tar.gz | 10.7 kB | With provenance | Details for bascet-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bascet-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for bascet-0.0.1-py3-none-any.whl |
Total release size: 22.8 kB
Release files / bascet-0.0.1.tar.gz
| Download URL | bascet-0.0.1.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e0837867d06f853e757dc399febbd7146186cb2a2f81608ec6b8eceba80f8bb
|
|
BLAKE2b-256 checksum How to use checksums |
0a7ff72a43a2538df15376db6f13966e05a9229fb4bd036a748434f2dec0dc4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logRelease files / bascet-0.0.1-py3-none-any.whl
| Download URL | bascet-0.0.1-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fae752db9c423fcb665bf1f1527eb87bf35c73ab8a1414ca85945844d16e812a
|
|
BLAKE2b-256 checksum How to use checksums |
0582fded3c0feaf56fcc2c6da9cda9a9139ee20dbff48fa2b7b7a1305493363c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logSecurity for bascet 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for bascet-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.