Skip to main content

A wrapper for the US Census Bureau's API

Project description

======
census
======

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
* us


Usage
=====

First, get yourself a `Census API key <http://www.census.gov/developers/>`_.

::

from census import Census
from us import states

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

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

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:

* `ACS <http://www.census.gov/developers/data/2010acs5_variables.xml>`_
* `SF1 <http://www.census.gov/developers/data/sf1.xml>`_


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 <http://thedataweb.rm.census.gov/data/acs5geo.html>`_
and `SF1 <http://thedataweb.rm.census.gov/data/sf1geo.html>`_.

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

This package previously had a `census.states` module, but now uses the
*us* package. ::

>>> from us import states
>>> print states.MD.fips
u'24'

Convert FIPS to state abbreviation using `lookup()`: ::

>>> print states.lookup('24').abbr
u'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.fips})

The same call using the `state_county_tract` convenience method::

c.sf1.state_county_tract('NAME', states.AK.fips, '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)

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

census-0.3.tar.gz (4.6 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for census-0.3.tar.gz
Algorithm Hash digest
SHA256 c2b25dc7aa246f3c3d5d24d32a4c5c30ab8500d68836236d6cb25ae1d14a51c1
MD5 005f937c7780c89b9b3222f63e3388fe
BLAKE2b-256 07087e6446b9574958024cef8e57763b4a516bb74b2a1d277c64f9fe8867ed0c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page