Skip to main content

A simple wrapper for the United States Census Bureau’s API.

Provides access to both the ACS and SF1 data sets.

Requirements

  • python 2.6 or 2.7

  • requests

Usage

First, get yourself a Census API key.

from census import Census, states

c = Census("MY_API_KEY")
c.acs.get(('NAME', 'B25034_010E'), {'for': 'state:%s' % states.MD})

The call above will return the name of the geographic area and the number of homes that were built before 1939 for the state of Maryland. Helper methods have been created to simplify common geometry calls:

c.acs.state(('NAME', 'B25034_010E'), states.MD)

Full details on geometries and the states module can be found below.

The get method is the core data access method on both the ACS and SF1 data sets. The first parameter is either a single string column or a tuple of columns. The second parameter is a geoemtry dict with a for key and on option in key. The for argument accepts a “*” wildcard character or Census.ALL. The wildcard is not valid for the in parameter.

Valid columns by data set:

Geometries

The API supports a wide range of geographic regions. The specification of these can be quite complicated so a number of convenience methods are provided.

Full geometry specifications are available for ACS and SF1.

ACS Geometries

  • state(fields, state_fips)

  • state_county(fields, state_fips, county_fips)

  • state_county_subdivision(fields, state_fips, county_fips, subdiv_fips)

  • state_county_tract(fields, state_fips, county_fips, tract)

  • state_place(fields, state_fips, place)

  • state_district(fields, state_fips, district)

  • us(fields)

SF1 Geometries

  • state(fields, state_fips)

  • state_county(fields, state_fips, county_fips)

  • state_county_subdivision(fields, state_fips, county_fips, subdiv_fips)

  • state_county_tract(fields, state_fips, county_fips, tract)

  • state_place(fields, state_fips, place)

  • state_district(fields, state_fips, district)

  • state_msa(fields, state_fips, msa)

  • state_csa(fields, state_fips, csa)

  • state_district_place(fields, state_fips, district, place)

  • state_zip(fields, state_fips, zip)

States

The states module makes it easy to convert between state abbreviations and FIPS codes. Access attributes by state abbreviation to get the corresponding FIPS code:

>>> from census import states
>>> print states.MD
24

Convert FIPS to state abbreviation using the FIPS dict:

>>> print states.FIPS['24']
MD

Examples

The geographic name for all census tracts for county 170 in Alaska:

c.sf1.get('NAME', geo={'for': 'tract:*', 'in': 'state:%s county:170' % states.AK})

The same call using the state_county_tract convenience method:

c.sf1.state_county_tract('NAME', states.AK, '170', Census.ALL)

Total number of males age 5 - 9 for all states:

c.acs.get('B01001_004E', {'for': 'state:*'})

The same call using the state convenience method:

c.acs.state('B01001_004E', Census.ALL)

Download files

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

Source Distribution

census-0.2.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file census-0.2.tar.gz.

File metadata

  • Download URL: census-0.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for census-0.2.tar.gz
Algorithm Hash digest
SHA256 11248a45f9c71ad901368cd014ed7589bd067a5fd8ddb8c02bd56b6a3149b35b
MD5 e716449254a7981684dc59f1d952fe74
BLAKE2b-256 ce192d80d321fd26200f5bab671dd8f03489beeb197895f443d6d90c95fa0bbc

See more details on using hashes here.

Release history Release notifications | RSS feed

0.8.27

2 files

0.8.26

2 files

0.8.25

2 files

0.8.24

2 files

0.8.23

2 files

0.8.22

2 files

0.8.21

2 files

0.8.20

2 files

0.8.19

1 file

0.8.18

1 file

0.8.17

2 files

0.8.16

2 files

0.8.15

2 files

0.8.14

2 files

0.8.13

2 files

0.8.12

2 files

0.8.11

2 files

0.8.10

2 files

0.8.9

2 files

0.8.8

2 files

0.8.7

2 files

0.8.6

2 files

0.8.5

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

1 file

0.8

1 file

0.7

1 file

0.6

1 file

0.5

1 file

0.4

1 file

0.3

1 file

This release

0.2 This release

1 file

0.1

1 file

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