:globe_with_meridians: A Python wrapper for the Geocodio geolocation service API

Overview

Py-Geocodio

https://travis-ci.org/bennylope/pygeocodio.svg?branch=master

Python wrapper for Geocodio geocoding API.

Full documentation on Read the Docs.

If you are upgrading from a version prior to 0.2.0 please see the changelog in HISTORY.rst. The default coordinate ordering has changed to something a bit more sensible for most users.

Geocodio API Features

  • Geocode an individual address
  • Batch geocode up to 10,000 addresses at a time
  • Parse an address into its identifiable components
  • Reverse geocode an individual geographic point
  • Batch reverse geocode up to 10,000 points at a time
  • Perform operations using the HIPAA API URL

The service is limited to U.S. and Canada addresses for the time being.

Read the complete Geocodio documentation for service documentation.

Installation

pygeocodio requires requests 1.0.0 or greater and will ensure requests is installed:

pip install pygeocodio

Basic usage

Import the API client and ensure you have a valid API key:

>>> from geocodio import GeocodioClient
>>> client = GeocodioClient(YOUR_API_KEY)

Geocoding

Geocoding an individual address:

>>> geocoded_location = client.geocode("42370 Bob Hope Drive, Rancho Mirage CA")
>>> geocoded_location.coords
(33.738987255507, -116.40833849559)

Batch geocoding

You can also geocode a list of addresses:

>>> geocoded_addresses = client.geocode([
        '2 15th St NW, Washington, DC 20024',
        '3101 Patterson Ave, Richmond, VA, 23221'
    ])

Return a list of just the coordinates for the resultant geocoded addresses:

>>> geocoded_addresses.coords
[(38.890083, -76.983822), (37.560446, -77.476008)]
>>> geocoded_addresses[0].coords
(38.890083, -76.983822), (37.560446, -77.476008)

Lookup an address by the queried address:

>>> geocoded_addresses.get('2 15th St NW, Washington, DC 20024').coords
(38.879138, -76.981879))

Address parsing

And if you just want to parse an individual address into its components:

>>> client.parse('1600 Pennsylvania Ave, Washington DC')
  {
      "address_components": {
          "number": "1600",
          "street": "Pennsylvania",
          "suffix": "Ave",
          "city": "Washington",
          "state": "DC"
      },
      "formatted_address": "1600 Pennsylvania Ave, Washington DC"
  }

Reverse geocoding

Reverse geocode a point to find a matching address:

>>> location = client.reverse((33.738987, -116.4083))
>>> location.formatted_address
"42370 Bob Hope Dr, Rancho Mirage CA, 92270"

Batch reverse geocoding

And multiple points at a time:

>>> locations = client.reverse([
        (33.738987, -116.4083),
        (33.738987, -116.4083),
        (38.890083, -76.983822)
    ])

Return the list of formatted addresses:

>>> locations.formatted_addresses
["42370 Bob Hope Dr, Rancho Mirage CA, 92270",  "42370 Bob Hope Dr, Rancho Mirage CA, 92270", "2 15th St NW, Washington, DC 20024"]

Access a specific address by the queried point tuple:

>>> locations.get("38.890083,-76.983822").formatted_address
"2 15th St NW, Washington, DC 20024"

Or by the more natural key of the queried point tuple:

>>> locations.get((38.890083, -76.983822)).formatted_address
"2 15th St NW, Washington, DC 20024"

CLI usage

In the works!

Documentation

For complete documentation see the docs.

License

BSD License

Comments
  • Getting more than one field to return information

    Getting more than one field to return information

    In playing around with this wrapper, I tried to pull all of the fields available when geocoding an address. Heres my code:

    r = '42370 Bob Hope Dr, Rancho Mirage CA' geocoded_location = client.geocode(r, fields=['cd','school'] )

    This returns the 'school' attribute of fields, but not the 'cd'. I'd like to be able to pass more than one field and this doesn't not support this capability.

    I would try to fix this myself, but I am not skilled enough in python.

    Thanks.

    opened by ccdpowell 7
  • Updated batch_geocode for dictionaries

    Updated batch_geocode for dictionaries

    This addresses #27

    This is admittedly a very blunt approach to the problem: LocationCollectionDict is a version of LocationCollection that inherits from dictionary instead of list.

    The batch geocoder endpoint for geocod.io accepts a JSON object. Currently batch_geocode only accepts lists of addresses. When a python dictionary of keys and addresses is passed to batch_geocode, the geocod.io interprets it as a JSON object and returns a JSON object in its response. The results field is now a JSON object rather than an array, which python interprets as a dictionary.

    LocationCollection expects a list from response.json()["results"] and understandably breaks. If the response is instead a dictionary, it gets rerouted to LocationCollectionDict to create a comparable dictionary object. LocationCollectionDict changes the list methods in LocationCollection to dictionary methods

    opened by liufran1 3
  • KeyError

    KeyError

    I get KeyErrors when I run the last two examples in the README https://github.com/bennylope/pygeocodio

    locations.get("33.738987, -116.4083").formatted_address and locations.get((33.738987, -116.4083)).formatted_address

    help-wanted documentation 
    opened by mroswell 3
  • No longer keeping client-side field whitelist

    No longer keeping client-side field whitelist

    This moves the responsibility of validating field names to the server instead of the client.

    In practice, this lets users request newer fields such as census2010, and ensures that the list in the library will not need to be continuously updated.

    opened by MiniCodeMonkey 2
  • Feature/add components search

    Feature/add components search

    Related to: #30

    Changes:

    • Give geocode(...) 2 parameters: address_data + components_data
      • If both are populated or both are empty, nothing happens
      • If addres_data is provided (default first parameter), searching behaves like previusly
      • If comonents_data is a single dict or list of dicts populated with the supported fields here, geocoding occurs with components as the parameters instead of the freeform address string
    • You can lookup a result based on the address components geocoded
    opened by Unix-Code 2
  • Including a reference key in batch encoding

    Including a reference key in batch encoding

    Geocodio batch encoding allows for a reference key to be included if the request is submitted as a JSON object rather than a JSON array. See https://www.geocod.io/docs/#batch-geocoding

    Can this functionality be added?

    enhancement 
    opened by arashrez 2
  • Update to API v1.3

    Update to API v1.3

    • Update client
    • Update test client

    v1.3 (Released on March 12th, 2018)

    timezone appends:

    Breaking: name property has been renamed to abbreviation name is now the full timezone name in a tzdb-compatible format.

    opened by joshgeller 2
  • Broken __init__.py and client.py in pip package manager

    Broken __init__.py and client.py in pip package manager

    Hello there,

    It looks like this commit did not make it to the pip package manager. geocodio/init.py is still using the outdated format and client.py is still using version 1 of the Geocodio API: https://github.com/bennylope/pygeocodio/commit/9631d11da62f6e9a205a3b7430e34c556c601592

    I am more than happy to do any testing, George

    bash-3.2$ pip install geocodio Collecting geocodio Requirement already satisfied: Requests>=2.2.0 in ./anaconda/lib/python3.6/site-packages (from geocodio) Requirement already satisfied: idna<2.7,>=2.5 in ./anaconda/lib/python3.6/site-packages (from Requests>=2.2.0->geocodio) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./anaconda/lib/python3.6/site-packages (from Requests>=2.2.0->geocodio) Requirement already satisfied: urllib3<1.23,>=1.21.1 in ./anaconda/lib/python3.6/site-packages (from Requests>=2.2.0->geocodio) Requirement already satisfied: certifi>=2017.4.17 in ./anaconda/lib/python3.6/site-packages (from Requests>=2.2.0->geocodio) Installing collected packages: geocodio Successfully installed geocodio-1.0.1

    bash-3.2$ python3.6 Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information.

    from geocodio import GeocodioClient Traceback (most recent call last): File "", line 1, in File "anaconda/lib/python3.6/site-packages/geocodio/init.py", line 8, in from client import Client ModuleNotFoundError: No module named 'client'

    exit()

    cat anaconda/lib/python3.6/site-packages/geocodio/init.py

    !/usr/bin/env python
    -*- coding: utf-8 -*-
    
    __author__ = 'David Stanley'
    __email__ = '[email protected]'
    __version__ = '1.0.0'
    
    from client import Client
    
    __all__ = [Client]
    

    bash-3.2$ head anaconda/lib/python3.6/site-packages/geocodio/client.py

    import requests, json
    
    class Client:
        url = 'http://api.geocod.io/v1'
        api_key = ''
    
        def __init__(self, api_key):
            """ Initialize the class, setting the api_key to the class property """
            self.api_key = api_key
    
    opened by georgezoto 2
  • How to extract LAT and LON separately from geocoded_location.coords?

    How to extract LAT and LON separately from geocoded_location.coords?

    Hopefully an easy question, but is it possible to get a separate value for LON/X AND LAT/Y from the geocoded_location.coords object?

    We're testing how, using python, the output coordinates can be dumped into a PostGIS database and assembled into a geometry object.

    Thanks!

    opened by dpsspatial 2
  • README errors

    README errors

    The README example uses the coordinate (33.738987, -116.408) and mis-states the results in various places as '1600 Pennsylvania Ave, Washington, DC' or '100 Main St, Springfield, USA'

    Someone needs to review the README pretty carefully. (I'm hoping that a careful proofing will also yield an answer to #9 )

    help-wanted documentation 
    opened by mroswell 2
  • Field name

    Field name "census" raises a ValueError

    "census" is one of the available fields: https://geocod.io/docs/#census-block-tract-amp-fips-codes, but calling client.geocode(address, fields=['census']) raises a ValueError ("census' is not a valid field value"). I fixed this locally by adding 'census' to ALLOWED_FIELDS on line 15 of client.py.

    opened by ndingwall 2
Releases(v1.0.1)
Owner
Ben Lopatin
I leverage synergies.
Ben Lopatin
A python bot that will allow you to have maximum luck during Veve drops.

VeveBot You can follow me here Github | Twitter Features: - Click on the purchase at the time of the drop. - Be able to choose to do more than one tes

Rodz 1 Dec 04, 2021
Temperature Monitoring and Prediction Using a Modified Lambda Architecture

Temperature Monitoring and Prediction Using a Modified Lambda Architecture A more detailed write up can be seen in this paper. Original Lambda Archite

Parsa Yousefi 2 Jun 27, 2022
A Python wrapper for the Dogehouse API.

Python wrapper for the dogehouse API Installation pip install dogehouse Example from dogehouse import DogeClient, event, command from dogehouse.entiti

Arthur 36 Jun 15, 2022
An youtube videos thumbnail downloader telegram bot.

YouTube-Thumbnail-Downloader An youtube videos thumbnail downloader telegram bot. Made with Python3 (C) @FayasNoushad Copyright permission under MIT L

Fayas Noushad 40 Oct 21, 2022
An Async Bot/API wrapper for Twitch made in Python.

TwitchIO is an asynchronous Python wrapper around the Twitch API and IRC, with a powerful command extension for creating Twitch Chat Bots. TwitchIO co

TwitchIO 590 Jan 03, 2023
A modern,feature-rich, and async ready API wrapper for Discord written in Python

discord.io A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. Key Features Modern Pythonic API using asyn

Vincent 18 Jan 02, 2023
Trust-minimized Bitcoin wallet

coldcore Trust-minimized, airgapped Bitcoin management This is experimental software. Wait for a formal release before use with real funds. A trust-mi

James O'Beirne 121 Jan 01, 2023
The scope of this project will be to build a data ware house on Google Cloud Platform that will help answer common business questions as well as powering dashboards

The scope of this project will be to build a data ware house on Google Cloud Platform that will help answer common business questions as well as powering dashboards.

Shweta_kumawat 2 Jan 20, 2022
Bender: A Markov Babbler Slack Bot

See the Digital Ocean tutorial for instructions on how to get the basic bot structure in place. Once you have that, set the gunicorn command to run as

Andrew Howard 1 Dec 04, 2021
Stream Telegram files to web

Telegram File Stream Bot A Telegram bot to stream files to web Demo Bot » Report a Bug | Request Feature Table of Contents About this Bot Original Rep

Wrench 572 Jan 09, 2023
Easy Discord Webhook Token Grabber!

Easy Discord Webhook Token Grabber!

†† 27 Jun 01, 2022
A Python Jupyter Kernel in Slack. Just send Python code as a message.

Slack IPython bot 🤯 One Slack bot to rule them all. PyBot. Just send Python code as a message. Install pip install slack-ipython To start the bot, si

Rick Lamers 44 May 23, 2022
For specific function. For my own convenience. Remind owner to share data to another DITO user.

For specific function. For my own convenience. Remind owner to share data to another DITO user.

Meigo 1 Dec 14, 2021
A Telegram Bot written in Python for mirroring files on the Internet to Google Drive

No support is going to be provided of any kind, only maintaining this for vps user on request. This is a Telegram Bot written in Python for mirroring

0 Dec 26, 2021
Schedule Twitter updates with easy

coo: schedule Twitter updates with easy Coo is an easy to use Python library for scheduling Twitter updates. To use it, you need to first apply for a

wilfredinni 46 Nov 03, 2022
GroupMenter : New Telegram Group Manager Bot🔸Fast 🔸Python🔸Pyrogram 🔸

GroupMenter An PowerFull Group Manager Bot. Written In Pytelethon. Info • A modular Telegram Python bot running on python3. • Can be found on telegram

Group Menter 24 Jun 28, 2022
A Python API For Questionnaire

Инструкция по разворачиванию приложения Окружение проекта: python 3.8 Django 2.2.10 djangorestframework Склонируйте репозиторий с помощью git: git clo

2 Feb 14, 2022
Набор утилит для Discord с использованием языка программирования Python.

Discord Tools v0.1 Functions: WebHook spamer Spotify account generator (What?) QR Code Token stealer Token generator Discord nitro gen/check Discor to

Максим Скризов 3 Aug 23, 2022
Transcript-Extractor-Bot - Yet another Telegram Voice Recognition bot but using vosk and supports 20+ languages

transcript extractor Yet another Telegram Voice Recognition bot but using vosk a

6 Oct 21, 2022