census-us


Namecensus-us JSON
Version 0.1.2 PyPI version JSON
download
home_page
SummaryFork of a wrapper for the US Census Bureau's API
upload_time2022-12-10 02:17:07
maintainer
docs_urlNone
author
requires_python
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ======
census
======
.. image:: https://github.com/datamade/census/workflows/Python%20package/badge.svg
 

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

Provides access to ACS and SF1 data sets.

Install
=======

::

    pip install census

You may also want to install a complementary library, `us <https://pypi.python.org/pypi/us>`_, which help you figure out the
`FIPS <https://en.wikipedia.org/wiki/Federal_Information_Processing_Standard_state_code>`_ codes for many geographies. We use it in the examples below.

::

   pip install us

Usage
=====

First, get yourself a `Census API key <https://api.census.gov/data/key_signup.html>`_.

::

    from census import Census
    from us import states

    c = Census("MY_API_KEY")
    c.acs5.get(('NAME', 'B25034_010E'),
              {'for': 'state:{}'.format(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.acs5.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.

By default, the year for a dataset is the most recent year available. To access earlier data,
pass a year parameter to the API call::

    c.acs5.state(('NAME', 'B25034_010E'), states.MD.fips, year=2010)

The default year may also be set client-wide::

    c = Census("MY_API_KEY", year=2010)


Detailed information about the API can be found at the `Census Data API User Guide <https://www.census.gov/data/developers/guidance/api-user-guide.html>`_.

Datasets
========

For each dataset, the first year listed is the default.

* acs5: `ACS 5 Year Estimates <https://www.census.gov/data/developers/data-sets/acs-5year.html>`_ (2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009)
* acs3: `ACS 3 Year Estimates <https://www.census.gov/data/developers/data-sets/acs-3year.html>`_ (2013, 2012)
* acs1: `ACS 1 Year Estimates <https://www.census.gov/data/developers/data-sets/acs-1year.html>`_ (2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011)
* acs5dp: `ACS 5 Year Estimates, Data Profiles  <https://www.census.gov/data/developers/data-sets/acs-5year.html>`_ (2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009)
* acs3dp: `ACS 3 Year Estimates, Data Profiles <https://www.census.gov/data/developers/data-sets/acs-3year.html>`_ (2013, 2012)
* acs1dp: `ACS 1 Year Estimates, Data Profiles <https://www.census.gov/data/developers/data-sets/acs-1year.html>`_ (2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011)
* acs5st: `ACS 5 Year Estimates, Subject Tables <https://www.census.gov/data/developers/data-sets/acs-5year.html>`_ (2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009)
* sf1: `Census Summary File 1 <https://www.census.gov/data/datasets/2010/dec/summary-file-1.html>`_ (2010)
* pl: `Redistricting Data Summary File <https://www.census.gov/programs-surveys/decennial-census/about/rdo/summary-files.2020.html>`_ (2020, 2010, 2000) 


Geographies
===========

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. Refer to the `Census API documentation <https://www.census.gov/data/developers/guidance/api-user-guide.html>`_
for more geographies beyond the convenience methods.

*Not all geographies are supported in all years. Calling a convenience method
with a year that is not supported will raise census.UnsupportedYearException.*

`Geographic relationship files <https://www.census.gov/geo/maps-data/data/relationship.html>`_ are provided on the Census developer site as a tool to help users compare the geographies from the 1990, 2000 and 2010 Censuses. From these files, data users may determine how geographies from one Census relate to those from the prior Census.

ACS5 Geographies
----------------

* state(fields, state_fips)
* state_county(fields, state_fips, county_fips)
* state_county_blockgroup(fields, state_fips, county_fips, blockgroup)
* 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_congressional_district(fields, state_fips, congressional_district)
* state_legislative_district_upper(fields, state_fips, legislative_district)
* state_legislative_district_lower(fields, state_fips, legislative_district)
* us(fields)
* state_zipcode(fields, state_fips, zip5)

ACS1 Geographies
----------------

* state(fields, state_fips)
* state_congressional_district(fields, state_fips, district)
* us(fields)

SF1 Geographies
---------------

* 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_congressional_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_zipcode(fields, state_fips, zip5)

PL Geographies
--------------

* 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_county_blockgroup(fields, state_fips, county_fips, blockgroup)
* state_place(fields, state_fips, place)
* state_congressional_district(fields, state_fips, district)
* state_legislative_district_upper(fields, state_fips, legislative_district)
* state_legislative_district_lower(fields, state_fips, legislative_district)

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'


BYOS - Bring Your Own Session
=============================

If you'd prefer to use a custom configured requests.Session, you can pass it
to the Census constructor::

    s = requests.session()
    s.headers.update({'User-Agent': 'census-demo/0.0'})

    c = Census("MY_API_KEY", session=s)

You can also replace the session used by a specific data set::

    c.sf1.session = s


Examples
========

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

    c.sf1.get('NAME', geo={'for': 'tract:*',
                           'in': 'state:{} county:170'.format(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.acs5.get('B01001_004E', {'for': 'state:*'})

The same call using the state convenience method::

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

Don't know the list of tables in a survey, try this:

    c.acs5.tables()

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "census-us",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/65/c8/c547057e542891a90fd720811186385c37269fff29db3db6310abd5a5b93/census-us-0.1.2.tar.gz",
    "platform": "any",
    "description": "======\ncensus\n======\n.. image:: https://github.com/datamade/census/workflows/Python%20package/badge.svg\n \n\nA simple wrapper for the United States Census Bureau's API.\n\nProvides access to ACS and SF1 data sets.\n\nInstall\n=======\n\n::\n\n    pip install census\n\nYou may also want to install a complementary library, `us <https://pypi.python.org/pypi/us>`_, which help you figure out the\n`FIPS <https://en.wikipedia.org/wiki/Federal_Information_Processing_Standard_state_code>`_ codes for many geographies. We use it in the examples below.\n\n::\n\n   pip install us\n\nUsage\n=====\n\nFirst, get yourself a `Census API key <https://api.census.gov/data/key_signup.html>`_.\n\n::\n\n    from census import Census\n    from us import states\n\n    c = Census(\"MY_API_KEY\")\n    c.acs5.get(('NAME', 'B25034_010E'),\n              {'for': 'state:{}'.format(states.MD.fips)})\n\nThe call above will return the name of the geographic area and the number of\nhomes that were built before 1939 for the state of Maryland. Helper methods have\nbeen created to simplify common geometry calls::\n\n    c.acs5.state(('NAME', 'B25034_010E'), states.MD.fips)\n\nFull details on geometries and the states module can be found below.\n\nThe get method is the core data access method on both the ACS and SF1 data sets.\nThe first parameter is either a single string column or a tuple of columns. The\nsecond parameter is a geoemtry dict with a `for` key and on option `in` key. The\n`for` argument accepts a `\"*\"` wildcard character or `Census.ALL`. The wildcard\nis not valid for the `in` parameter.\n\nBy default, the year for a dataset is the most recent year available. To access earlier data,\npass a year parameter to the API call::\n\n    c.acs5.state(('NAME', 'B25034_010E'), states.MD.fips, year=2010)\n\nThe default year may also be set client-wide::\n\n    c = Census(\"MY_API_KEY\", year=2010)\n\n\nDetailed information about the API can be found at the `Census Data API User Guide <https://www.census.gov/data/developers/guidance/api-user-guide.html>`_.\n\nDatasets\n========\n\nFor each dataset, the first year listed is the default.\n\n* acs5: `ACS 5 Year Estimates <https://www.census.gov/data/developers/data-sets/acs-5year.html>`_ (2020, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009)\n* acs3: `ACS 3 Year Estimates <https://www.census.gov/data/developers/data-sets/acs-3year.html>`_ (2013, 2012)\n* acs1: `ACS 1 Year Estimates <https://www.census.gov/data/developers/data-sets/acs-1year.html>`_ (2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011)\n* acs5dp: `ACS 5 Year Estimates, Data Profiles  <https://www.census.gov/data/developers/data-sets/acs-5year.html>`_ (2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009)\n* acs3dp: `ACS 3 Year Estimates, Data Profiles <https://www.census.gov/data/developers/data-sets/acs-3year.html>`_ (2013, 2012)\n* acs1dp: `ACS 1 Year Estimates, Data Profiles <https://www.census.gov/data/developers/data-sets/acs-1year.html>`_ (2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011)\n* acs5st: `ACS 5 Year Estimates, Subject Tables <https://www.census.gov/data/developers/data-sets/acs-5year.html>`_ (2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009)\n* sf1: `Census Summary File 1 <https://www.census.gov/data/datasets/2010/dec/summary-file-1.html>`_ (2010)\n* pl: `Redistricting Data Summary File <https://www.census.gov/programs-surveys/decennial-census/about/rdo/summary-files.2020.html>`_ (2020, 2010, 2000) \n\n\nGeographies\n===========\n\nThe API supports a wide range of geographic regions. The specification of these\ncan be quite complicated so a number of convenience methods are provided. Refer to the `Census API documentation <https://www.census.gov/data/developers/guidance/api-user-guide.html>`_\nfor more geographies beyond the convenience methods.\n\n*Not all geographies are supported in all years. Calling a convenience method\nwith a year that is not supported will raise census.UnsupportedYearException.*\n\n`Geographic relationship files <https://www.census.gov/geo/maps-data/data/relationship.html>`_ are provided on the Census developer site as a tool to help users compare the geographies from the 1990, 2000 and 2010 Censuses. From these files, data users may determine how geographies from one Census relate to those from the prior Census.\n\nACS5 Geographies\n----------------\n\n* state(fields, state_fips)\n* state_county(fields, state_fips, county_fips)\n* state_county_blockgroup(fields, state_fips, county_fips, blockgroup)\n* state_county_subdivision(fields, state_fips, county_fips, subdiv_fips)\n* state_county_tract(fields, state_fips, county_fips, tract)\n* state_place(fields, state_fips, place)\n* state_congressional_district(fields, state_fips, congressional_district)\n* state_legislative_district_upper(fields, state_fips, legislative_district)\n* state_legislative_district_lower(fields, state_fips, legislative_district)\n* us(fields)\n* state_zipcode(fields, state_fips, zip5)\n\nACS1 Geographies\n----------------\n\n* state(fields, state_fips)\n* state_congressional_district(fields, state_fips, district)\n* us(fields)\n\nSF1 Geographies\n---------------\n\n* state(fields, state_fips)\n* state_county(fields, state_fips, county_fips)\n* state_county_subdivision(fields, state_fips, county_fips, subdiv_fips)\n* state_county_tract(fields, state_fips, county_fips, tract)\n* state_place(fields, state_fips, place)\n* state_congressional_district(fields, state_fips, district)\n* state_msa(fields, state_fips, msa)\n* state_csa(fields, state_fips, csa)\n* state_district_place(fields, state_fips, district, place)\n* state_zipcode(fields, state_fips, zip5)\n\nPL Geographies\n--------------\n\n* state(fields, state_fips)\n* state_county(fields, state_fips, county_fips)\n* state_county_subdivision(fields, state_fips, county_fips, subdiv_fips)\n* state_county_tract(fields, state_fips, county_fips, tract)\n* state_county_blockgroup(fields, state_fips, county_fips, blockgroup)\n* state_place(fields, state_fips, place)\n* state_congressional_district(fields, state_fips, district)\n* state_legislative_district_upper(fields, state_fips, legislative_district)\n* state_legislative_district_lower(fields, state_fips, legislative_district)\n\nStates\n======\n\nThis package previously had a `census.states` module, but now uses the\n*us* package. ::\n\n    >>> from us import states\n    >>> print states.MD.fips\n    u'24'\n\nConvert FIPS to state abbreviation using `lookup()`: ::\n\n    >>> print states.lookup('24').abbr\n    u'MD'\n\n\nBYOS - Bring Your Own Session\n=============================\n\nIf you'd prefer to use a custom configured requests.Session, you can pass it\nto the Census constructor::\n\n    s = requests.session()\n    s.headers.update({'User-Agent': 'census-demo/0.0'})\n\n    c = Census(\"MY_API_KEY\", session=s)\n\nYou can also replace the session used by a specific data set::\n\n    c.sf1.session = s\n\n\nExamples\n========\n\nThe geographic name for all census tracts for county 170 in Alaska::\n\n    c.sf1.get('NAME', geo={'for': 'tract:*',\n                           'in': 'state:{} county:170'.format(states.AK.fips)})\n\nThe same call using the `state_county_tract` convenience method::\n\n    c.sf1.state_county_tract('NAME', states.AK.fips, '170', Census.ALL)\n\nTotal number of males age 5 - 9 for all states::\n\n    c.acs5.get('B01001_004E', {'for': 'state:*'})\n\nThe same call using the state convenience method::\n\n    c.acs5.state('B01001_004E', Census.ALL)\n\nDon't know the list of tables in a survey, try this:\n\n    c.acs5.tables()\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Fork of a wrapper for the US Census Bureau's API",
    "version": "0.1.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "71ff38fef6a603a2458c67ec717e5ecd",
                "sha256": "f3fc33a2b560d8238921fd7b742de247af8f6d616f8c38e23b3672d61a8e2e87"
            },
            "downloads": -1,
            "filename": "census_us-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "71ff38fef6a603a2458c67ec717e5ecd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 11142,
            "upload_time": "2022-12-10T02:17:05",
            "upload_time_iso_8601": "2022-12-10T02:17:05.572767Z",
            "url": "https://files.pythonhosted.org/packages/ca/1f/bc921a8a0f6bfbe60267df20e9a28d0f0c42183f6a28c0d647301bc2991b/census_us-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "2fa25fd1368e8e77c85cba2eb48b6202",
                "sha256": "27a0bf68181fe8945e3c66a1fe2ca27fa52a6cffcb127cdf6c4f4c501dfd7411"
            },
            "downloads": -1,
            "filename": "census-us-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "2fa25fd1368e8e77c85cba2eb48b6202",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12670,
            "upload_time": "2022-12-10T02:17:07",
            "upload_time_iso_8601": "2022-12-10T02:17:07.793890Z",
            "url": "https://files.pythonhosted.org/packages/65/c8/c547057e542891a90fd720811186385c37269fff29db3db6310abd5a5b93/census-us-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-10 02:17:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "census-us"
}
        
Elapsed time: 0.01583s