Skip to main content

us_census_api_extract

This package makes it easy to extract US census data by inputting a list of demographic variables and US state codes. The results are returned as pandas DataFrame. As it extracts the data it keeps track of the progress and stores the batches in a temp folder. If the process gets interrupted, you can run it again and it will continue where it left off (ie. it is idempotent).

Install

pip install us_census_api_extract

Usage

Go to the US census page to get an api key. In the example below I am using the American 5-year Community Survey (2018) but you could use any api by changing the 'request_url_pre'.

request_url_pre = "https://api.census.gov/data/2018/acs/acs5/subject?get=NAME,"
request_url_post_1 = "&for=tract:*&in=state:"
request_url_post_2 = "&in=county:*&key="
api_key = your-api-key

state_codes = ['48',  # TX
               '36',  # NY
               '06']  # CA

vars = ['S0101_C01_001E', 'S0101_C01_002E', 'S0101_C01_003E',
       'S0101_C01_004E', 'S0101_C01_005E', 'S0101_C01_006E',
       'S0101_C01_007E', 'S0101_C01_008E', 'S0101_C01_009E',
       'S0101_C01_010E', 'S0101_C01_011E', 'S0101_C01_012E']

tmp_path = your-temp-filepath  # this is where the temp files extracted will be stored.

# extract census demographics from US Census API for all census tracts that are in Texas
df_demo = cenx.extract_by_var(vars, state_codes,
                              request_url_pre, request_url_post_1, request_url_post_2, api_key, 
                              tmp_path)

Metadata

Release files for us-census-api-extract 0.2.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for us-census-api-extract 0.2.8
File Size Uploaded
us_census_api_extract-0.2.8.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for us-census-api-extract 0.2.8
File Interpreter ABI Platform
us_census_api_extract-0.2.8-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / us_census_api_extract-0.2.8.tar.gz

Download URL us_census_api_extract-0.2.8.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
60bbe520eb7e68a002e940c24ca52a61879ea6d6fcd38e8b6ba22478cf5f7472
BLAKE2b-256 checksum
How to use checksums
1cb48d86fb0786829c841c3797e6d4fb28ae5ffd748a5e4740c9e073a2ffb719
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3

Release files / us_census_api_extract-0.2.8-py3-none-any.whl

Download URL us_census_api_extract-0.2.8-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a94e0c6cbe8b70a64f9fff4bc2eab77a43108d8dac0ecf37f22a6e74e15aa3b6
BLAKE2b-256 checksum
How to use checksums
6476bcfc4d774f3a33fae5927f6769fc3355fe25ea4c3074b34858f8b5b90907
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.2.8 This release

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release 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