Thin Python wrapper for the US Census Geocoder
Maintained. Last release 10 months ago, commits in 1 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install censusgeocodeCensus Geocode
Census Geocode is a light weight Python wrapper for the US Census Geocoder API, compatible with Python 3. It comes packaged with a simple command line tool for geocoding an address to a longitude and latitude, or a batch file into a parsed address and coordinates.
It's strongly recommended to review the Census Geocoder docs before using this module.
Basic example:
import censusgeocode as cg
cg.coordinates(x=-76, y=41)
cg.onelineaddress('1600 Pennsylvania Avenue, Washington, DC')
cg.address('1600 Pennsylvania Avenue', city='Washington', state='DC', zip='20006')
cg.addressbatch('data/addresses.csv')
Use the returntype keyword to specify 'locations' or 'geographies'. 'Locations' yields structured information about the address, and 'geographies' yields information about the Census geographies. Geographies is the default.
cg.onelineaddress('1600 Pennsylvania Avenue, Washington, DC', returntype='locations')
Queries return a CensusResult object, which is basically a Python list with an extra 'input' property, which the Census returns to tell you how they interpreted your request.
>>> result = cg.coordinates(x=-76, y=41)
>>> result.input
{
u'vintage': {
u'vintageName': u'Current_Current',
u'id': u'4',
u'vintageDescription': u'Current Vintage - Current Benchmark',
u'isDefault': True
},
u'benchmark': {
u'benchmarkName': u'Public_AR_Current',
u'id': u'4',
u'isDefault': False,
u'benchmarkDescription': u'Public Address Ranges - Current Benchmark'
},
u'location': {
u'y': 41.0,
u'x': -76.0
}
}
>>> result
[{
'2010 Census Blocks': [{
'AREALAND': 1409023,
'AREAWATER': 0,
'BASENAME': '1045',
'BLKGRP': '1',
'BLOCK': '1045',
'CENTLAT': '+40.9957436',
'CENTLON': '-076.0089338',
'COUNTY': '079',
'FUNCSTAT': 'S',
'GEOID': '420792166001045',
'INTPTLAT': '+40.9957436',
'INTPTLON': '-076.0089338',
'LSADC': 'BK',
'LWBLKTYP': 'L',
'MTFCC': 'G5040',
'NAME': 'Block 1045',
'OBJECTID': 9940449,
'OID': 210404020212114,
'STATE': '42',
'SUFFIX': '',
'TRACT': '216600'
}],
'Census Tracts': [{
# snip
'NAME': 'Census Tract 2166',
'OBJECTID': 61245,
'OID': 20790277158250,
'STATE': '42',
'TRACT': '216600'
}],
'Counties': [{
# snip
'NAME': 'Luzerne County',
'OBJECTID': 866,
'OID': 27590277115518,
'STATE': '42'
}],
'States': [{
# snip
'NAME': 'Pennsylvania',
'REGION': '1',
'STATE': '42',
'STATENS': '01779798',
'STUSAB': 'PA'
}]
}]