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
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Licensed under the General Public License (version 3)
# http://opensource.org/licenses/LGPL-3.0
# Copyright (c) 2015-7, Neil Freeman <contact@fakeisthenewreal.org>
# Copyright (c) 2015-2026, Neil Freeman <contact@fakeisthenewreal.org>
name: Publish to PyPi

on:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Licensed under the General Public License (version 3)
# http://opensource.org/licenses/LGPL-3.0
# Copyright (c) 2015-7, Neil Freeman <contact@fakeisthenewreal.org>
# Copyright (c) 2015-2026, Neil Freeman <contact@fakeisthenewreal.org>

name: Test package

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Licensed under the General Public License (version 3)
# http://opensource.org/licenses/LGPL-3.0
# Copyright (c) 2015-7, Neil Freeman <contact@fakeisthenewreal.org>
# Copyright (c) 2015-2026, Neil Freeman <contact@fakeisthenewreal.org>

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

# Licensed under the General Public License (version 3)
# http://opensource.org/licenses/LGPL-3.0
# Copyright (c) 2015-9, Neil Freeman <contact@fakeisthenewreal.org>
# Copyright (c) 2015-2026, Neil Freeman <contact@fakeisthenewreal.org>

.PHONY: install build upload clean deploy test

install: ; pip install .

test: ; python -m unittest tests/test_*.py
test: ; python -m pytest tests

deploy: build
twine upload dist/*
Expand Down
177 changes: 97 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,92 +17,101 @@ 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.
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:

```python
import censusgeocode as cg

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.
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:

```python
>>> 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'
}]
}]
import censusgeocode as cg

result = cg.coordinates(x=-76, y=41)

print(result.input)
# {
# 'vintage': {
# 'vintageName': 'Current_Current',
# 'id': '4',
# 'vintageDescription': 'Current Vintage - Current Benchmark',
# 'isDefault': True
# },
# 'benchmark': {
# 'benchmarkName': 'Public_AR_Current',
# 'id': '4',
# 'isDefault': False,
# 'benchmarkDescription': 'Public Address Ranges - Current Benchmark'
# },
# 'location': {
# 'y': 41.0,
# 'x': -76.0
# }
# }

print(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'
# }]
# }]
```

## Advanced

By default, the geocoder uses the "Current" vintage and benchmarks. To use another vintage or benchmark, use the `CensusGeocode` class:

````python
from censusgeocode import CensusGeocode

cg = CensusGeocode(benchmark='Public_AR_Current', vintage='Census2020_Current')
cg.onelineaddress(foobar)
cg.onelineaddress("foobar")
````

The Census may update the available benchmarks and vintages. Review the Census Geocoder docs for the currently available [benchmarks](https://geocoding.geo.census.gov/geocoder/benchmarks) and [vintages](https://geocoding.geo.census.gov/geocoder/vintages?form).
Expand All @@ -111,7 +120,8 @@ The Census may update the available benchmarks and vintages. Review the Census G

The `censusgeocode` tool has two settings.

At the simplest, it takes one argument, an address, and returns a comma-delimited longitude, latitude pair.
At the simplest, it takes one argument, an address, and returns a comma-delimited longitude, latitude pair:

````bash
censusgeocode '100 Fifth Avenue, New York, NY'
-73.992195,40.73797
Expand All @@ -120,31 +130,37 @@ censusgeocode '1600 Pennsylvania Avenue, Washington DC'
-77.03535,38.898754
````

The Census geocoder is reasonably good at recognizing non-standard addresses.
The Census geocoder is reasonably good at recognizing non-standard addresses:

````bash
censusgeocode 'Hollywood & Vine, LA, CA'
-118.32668,34.101624
````

It can also use the Census Geocoder's batch function to process an entire file. The file must be comma-delimited, have no header, and include the following columns:
````

````csv
unique id, street address, state, city, zip code
````

The geocoder can read from a file:
````

```bash
censusgeocode --csv tests/fixtures/batch.csv
````
```

([example file](https://github.com/fitnr/censusgeocode/blob/master/tests/fixtures/batch.csv))

Or from stdin, using `-` as the filename:
````

```bash
head tests/fixtures/batch.csv | censusgeocode --csv -
````
```

According to the Census docs, the batch geocoder is limited to 10,000 rows.

The output will be a CSV file (with a header) and the columns:

* id
* address
* match
Expand All @@ -156,7 +172,8 @@ The output will be a CSV file (with a header) and the columns:
* lon

If your data doesn't have a unique id, try adding line numbers with the Unix command line utility `nl`:
```

```bash
nl -s , input.csv | censusgeocode --csv - > output.csv
```

Expand Down
8 changes: 6 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ install_requires =
python_requires = >=3.8,<4

[options.extras_require]
test = vcrpy>=4.1
tests = vcrpy>=4.1
test =
pytest>=6
vcrpy>=4.1
tests =
pytest>=6
vcrpy>=4.1

[options.packages.find]
where = src
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# This file is part of censusgeocode.
# https://github.com/fitnr/censusgeocode

# Licensed under the General Public License (version 3)
# http://opensource.org/licenses/LGPL-3.0
# Copyright (c) 2015-9, Neil Freeman <contact@fakeisthenewreal.org>
# Copyright (c) 2015-2026, Neil Freeman <contact@fakeisthenewreal.org>

from setuptools import setup

Expand Down
6 changes: 2 additions & 4 deletions src/censusgeocode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-

# This file is part of censusgeocode.
# https://github.com/fitnr/censusgeocode

# Licensed under the General Public License (version 3)
# http://opensource.org/licenses/LGPL-3.0
# Copyright (c) 2015-9, Neil Freeman <contact@fakeisthenewreal.org>
# Copyright (c) 2015-2026, Neil Freeman <contact@fakeisthenewreal.org>

from .censusgeocode import CensusGeocode

__version__ = '0.5.3'
__version__ = "0.5.3"

cg = CensusGeocode()

Expand Down
Loading