@@ -442,6 +442,86 @@ class ACS1DpClient(ACS1Client):
442442
443443 years = (2023 , 2022 , 2021 , 2019 , 2018 , 2017 , 2016 , 2015 , 2014 , 2013 , 2012 )
444444
445+ class DHCClient (Client ):
446+
447+ default_year = 2020
448+ dataset = 'dhc'
449+
450+ years = (2020 )
451+
452+ def _switch_endpoints (self , year ):
453+
454+ self .endpoint_url = 'https://api.census.gov/data/%s/dec/%s'
455+ self .definitions_url = 'https://api.census.gov/data/%s/dec/%s/variables.json'
456+ self .definition_url = 'https://api.census.gov/data/%s/dec/%s/variables/%s.json'
457+ self .groups_url = 'https://api.census.gov/data/%s/dec/%s/groups.json'
458+
459+ def tables (self , * args , ** kwargs ):
460+ self ._switch_endpoints (kwargs .get ('year' , self .default_year ))
461+ return super (DHCClient , self ).tables (* args , ** kwargs )
462+
463+ def get (self , * args , ** kwargs ):
464+ self ._switch_endpoints (kwargs .get ('year' , self .default_year ))
465+
466+ return super (DHCClient , self ).get (* args , ** kwargs )
467+
468+ @supported_years ()
469+ def state_county_subdivision (self , fields , state_fips ,
470+ county_fips , subdiv_fips , ** kwargs ):
471+ return self .get (fields , geo = {
472+ 'for' : 'county subdivision:{}' .format (subdiv_fips ),
473+ 'in' : 'state:{} county:{}' .format (state_fips , county_fips ),
474+ }, ** kwargs )
475+
476+ @supported_years ()
477+ def state_county_tract (self , fields , state_fips ,
478+ county_fips , tract , ** kwargs ):
479+ return self .get (fields , geo = {
480+ 'for' : 'tract:{}' .format (tract ),
481+ 'in' : 'state:{} county:{}' .format (state_fips , county_fips ),
482+ }, ** kwargs )
483+
484+ @supported_years ()
485+ def state_county_blockgroup (self , fields , state_fips , county_fips ,
486+ blockgroup , tract = None , ** kwargs ):
487+ geo = {
488+ 'for' : 'block group:{}' .format (blockgroup ),
489+ 'in' : 'state:{} county:{}' .format (state_fips , county_fips ),
490+ }
491+ if tract :
492+ geo ['in' ] += ' tract:{}' .format (tract )
493+ return self .get (fields , geo = geo , ** kwargs )
494+
495+ @supported_years (2020 )
496+ def state_msa (self , fields , state_fips , msa , ** kwargs ):
497+ return self .get (fields , geo = {
498+ 'for' : ('metropolitan statistical area/' +
499+ 'micropolitan statistical area (or part):{}' .format (msa )),
500+ 'in' : 'state:{}' .format (state_fips ),
501+ }, ** kwargs )
502+
503+ @supported_years (2020 )
504+ def state_csa (self , fields , state_fips , csa , ** kwargs ):
505+ return self .get (fields , geo = {
506+ 'for' : 'combined statistical area (or part):{}' .format (csa ),
507+ 'in' : 'state:{}' .format (state_fips ),
508+ }, ** kwargs )
509+
510+ @supported_years (2020 )
511+ def state_district_place (self , fields , state_fips ,
512+ district , place , ** kwargs ):
513+ return self .get (fields , geo = {
514+ 'for' : 'place/remainder (or part):{}' .format (place ),
515+ 'in' : 'state:{} congressional district:{}' .format (
516+ state_fips , district ),
517+ }, ** kwargs )
518+
519+ @supported_years (2020 )
520+ def state_zipcode (self , fields , state_fips , zcta , ** kwargs ):
521+ return self .get (fields , geo = {
522+ 'for' : 'zip code tabulation area (or part):{}' .format (zcta ),
523+ 'in' : 'state:{}' .format (state_fips ),
524+ }, ** kwargs )
445525
446526class SF1Client (Client ):
447527
@@ -601,6 +681,7 @@ def __init__(self, key, year=None, session=None):
601681 self .acs1dp = ACS1DpClient (key , year , session )
602682 self .sf1 = SF1Client (key , year , session )
603683 self .pl = PLClient (key , year , session )
684+ self .dhc = DHCClient (key , year , session )
604685
605686 @property
606687 def acs (self ):
0 commit comments