Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ For each dataset, the first year listed is the default.
* 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>`_ (2023, 2022, 2021, 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>`_ (2023, 2022, 2021, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012, 2011, 2010, 2009)
* dhc: `Demographic and Housing Characteristics File <https://www.census.gov/data/tables/2023/dec/2020-census-dhc.html>`_ (2020)
* 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)

Expand Down
81 changes: 81 additions & 0 deletions census/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,86 @@ class ACS1DpClient(ACS1Client):

years = (2023, 2022, 2021, 2019, 2018, 2017, 2016, 2015, 2014, 2013, 2012)

class DHCClient(Client):

default_year = 2020
dataset = 'dhc'

years = (2020)

def _switch_endpoints(self, year):

self.endpoint_url = 'https://api.census.gov/data/%s/dec/%s'
self.definitions_url = 'https://api.census.gov/data/%s/dec/%s/variables.json'
self.definition_url = 'https://api.census.gov/data/%s/dec/%s/variables/%s.json'
self.groups_url = 'https://api.census.gov/data/%s/dec/%s/groups.json'

def tables(self, *args, **kwargs):
self._switch_endpoints(kwargs.get('year', self.default_year))
return super(DHCClient, self).tables(*args, **kwargs)

def get(self, *args, **kwargs):
self._switch_endpoints(kwargs.get('year', self.default_year))

return super(DHCClient, self).get(*args, **kwargs)

@supported_years()
def state_county_subdivision(self, fields, state_fips,
county_fips, subdiv_fips, **kwargs):
return self.get(fields, geo={
'for': 'county subdivision:{}'.format(subdiv_fips),
'in': 'state:{} county:{}'.format(state_fips, county_fips),
}, **kwargs)

@supported_years()
def state_county_tract(self, fields, state_fips,
county_fips, tract, **kwargs):
return self.get(fields, geo={
'for': 'tract:{}'.format(tract),
'in': 'state:{} county:{}'.format(state_fips, county_fips),
}, **kwargs)

@supported_years()
def state_county_blockgroup(self, fields, state_fips, county_fips,
blockgroup, tract=None, **kwargs):
geo = {
'for': 'block group:{}'.format(blockgroup),
'in': 'state:{} county:{}'.format(state_fips, county_fips),
}
if tract:
geo['in'] += ' tract:{}'.format(tract)
return self.get(fields, geo=geo, **kwargs)

@supported_years(2020)
def state_msa(self, fields, state_fips, msa, **kwargs):
return self.get(fields, geo={
'for': ('metropolitan statistical area/' +
'micropolitan statistical area (or part):{}'.format(msa)),
'in': 'state:{}'.format(state_fips),
}, **kwargs)

@supported_years(2020)
def state_csa(self, fields, state_fips, csa, **kwargs):
return self.get(fields, geo={
'for': 'combined statistical area (or part):{}'.format(csa),
'in': 'state:{}'.format(state_fips),
}, **kwargs)

@supported_years(2020)
def state_district_place(self, fields, state_fips,
district, place, **kwargs):
return self.get(fields, geo={
'for': 'place/remainder (or part):{}'.format(place),
'in': 'state:{} congressional district:{}'.format(
state_fips, district),
}, **kwargs)

@supported_years(2020)
def state_zipcode(self, fields, state_fips, zcta, **kwargs):
return self.get(fields, geo={
'for': 'zip code tabulation area (or part):{}'.format(zcta),
'in': 'state:{}'.format(state_fips),
}, **kwargs)

class SF1Client(Client):

Expand Down Expand Up @@ -599,6 +679,7 @@ def __init__(self, key, year=None, session=None):
self.acs5dp = ACS5DpClient(key, year, session)
self.acs3dp = ACS3DpClient(key, year, session)
self.acs1dp = ACS1DpClient(key, year, session)
self.dhc = DHCClient(key, year, session)
self.sf1 = SF1Client(key, year, session)
self.pl = PLClient(key, year, session)

Expand Down