Skip to main content

Python bindings for the NYC Geoclient REST API

Project description

# NYC Geoclient Python Bindings

Python bindings for the REST [NYC Geoclient API][api].

[api]: http://developer.cityofnewyork.us/api/geoclient-api-beta

### Usage

First, you will need to register an application with the [NYC Developer Portal][portal], and make sure that you check off access to the Geoclient API for the application. Take note of the Application’s ID and key. You will not be able to use the ID and key until [DoITT][] approves you – this could take several days, and you will receive an email when this happens. There isn’t any indication of your status on the dashboard, but all requests will return a 403.

[portal]: https://developer.cityofnewyork.us/ [DoITT]: http://www.nyc.gov/html/doitt/html/home/home.shtml

You can pip install nyc-geoclient. It depends upon the [requests][] library.

[requests]: http://docs.python-requests.org/en/latest/index.html

$ pip install nyc_geoclient

Once your app has been approved by DoITT, using the API is simple:

>>> from nyc_geoclient import Geoclient
>>> g = Geoclient('my app ID', 'my app key')

All of the REST endpoints are supported.

>>> g.address('1500', 'Madison Ave', 'Manhattan')
{u'assemblyDistrict': u'68',
 u'boardOfElectionsPreferredLgc': u'1',
 u'boePreferredStreetName': u'MADISON AVENUE',
 u'boePreferredstreetCode': u'12539001',
 u'boroughCode1In': u'1',
 u'censusBlock2000': u'2000',
 u'censusBlock2010': u'3003',
 u'censusTract1990': u' 168  ',
 u'censusTract2000': u' 168  ',
 u'censusTract2010': u' 168  ',
 u'cityCouncilDistrict': u'08',
 u'civilCourtDistrict': u'06',
 u'coincidentSegmentCount': u'1',
...
>>> g.intersection('atlantic ave', 'nevins st', 'Brooklyn')
{u'assemblyDistrict': u'52',
 u'boroughCode1In': u'3',
 u'censusTract1990': u'  39  ',
 u'censusTract2000': u'  39  ',
 u'censusTract2010': u'  39  ',
 u'cityCouncilDistrict': u'33',
 u'civilCourtDistrict': u'01',
 u'communityDistrict': u'302',
 u'communityDistrictBoroughCode': u'3',
 u'communityDistrictNumber': u'02',
 u'communitySchoolDistrict': u'15',
 u'congressionalDistrict': u'08',
 u'crossStreetNamesFlagIn': u'E',
 u'dcpPreferredLgcForStreet1': u'01',
 u'dcpPreferredLgcForStreet2': u'01',
 u'dotStreetLightContractorArea': u'3',
...

##### Errors

In cases where the geocoder does not work, it will still return a dict. You must look at the value for message to see what happened.

>>> g.intersection('atlantic ave', 'nevins st', 'manhattan')
{u'boroughCode1In': u'1',
u'censusTract1990': u'      ',
u'censusTract2000': u'      ',
u'censusTract2010': u'      ',
u'crossStreetNamesFlagIn': u'E',
u'firstBoroughName': u'MANHATTAN',
u'firstStreetNameNormalized': u'ATLANTIC AVENUE',
u'geosupportFunctionCode': u'2',
u'geosupportReturnCode': u'11',
u'message': u"'ATLANTIC AVE' NOT RECOGNIZED. THERE ARE NO SIMILAR NAMES",
u'secondStreetNameNormalized': u'NEVINS ST',
u'streetName1In': u'ATLANTIC AVE',
u'streetName2In': u'NEVINS ST',
u'workAreaFormatIndicatorIn': u'C'}

The messages are generally very helpful.

### Documentation

Take a look at the [Python documentation][] for details on using the bindings, which closely follows the [DoITT documentation][] (requires account/login).

[Python documentation]: https://nyc-geoclient.readthedocs.org/ [DoITT documentation]: http://developer.cityofnewyork.us/api/geoclient-api-beta

### License

BSD.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nyc_geoclient-0.0.2.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file nyc_geoclient-0.0.2.tar.gz.

File metadata

File hashes

Hashes for nyc_geoclient-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d4c664908bc80e3b7a6dc49b3c96624eb25420734346e7d768fde97bf66738cf
MD5 96d7b8d9945afa65d28cec8919dd9d67
BLAKE2b-256 48bc26cf7e4a139f1b319a9328e0a769a680f248d8ee11ba018c47263fc2c8e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page