: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
Isobot is originally made by notsniped. This is a remix of iso.bot by archisha.

iso6.9-1.2beta iso.bot is originally made by notsniped#0002. This is a remix of iso.bot by αrchιshα#5518. iso6.9 is a Discord bot written in Python an

Kamilla Youver 3 Jan 11, 2022
DaProfiler vous permet d'automatiser vos recherches sur des particuliers basés en France uniquement et d'afficher vos résultats sous forme d'arbre.

A but educatif seulement. DaProfiler DaProfiler vous permet de créer un profil sur votre target basé en France uniquement. La particularité de ce prog

Dalunacrobate 73 Dec 21, 2022
Facebook fishing on telegram bot

Facebook-fishing Facebook fishing on telegram bot تثبيت الاداة pkg update -y pkg upgrade -y pkg install git -y pkg install python -y git clone https:/

sadamalsharabi 7 Oct 18, 2022
对hermit 的API进行简单的封装,做成了这个python moudle

hermit-py 对hermit 的API进行简单的封装,做成了这个Python Moudle,推荐通过wheel的方式安装。 目前对点击、滑动、模拟输入、找组件、等支持较好,支持查看页面的实时布局信息,再通过布局信息进行点击滑动等操作。 支持剪贴板相关的操作,支持设置剪贴的任意语言内容。

LookCos 40 Jun 25, 2022
Discord Blogger Integration Using Blogger API

It's a very simple discord bot created in python using blogger api in order to search and send your website articles in your discord chat in form of an embedded message. It's pretty useful for people

Owen Singh 8 Oct 28, 2022
Python3 script to dump employee information from XING API

XingDumper Python 3 script to dump company employees from XING API. Perfect OSINT tool ;-) The results contain firstname, lastname, position, gender,

LRVT 11 Dec 26, 2022
Python bindings for BigML.io

BigML Python Bindings BigML makes machine learning easy by taking care of the details required to add data-driven decisions and predictive power to yo

BigML Inc, Machine Learning made easy 271 Dec 27, 2022
Make WhatsApp ChatBot and use WhatsApp API to send the WhatsApp messages in python .

Ultramsg.com WhatsApp Bot using WhatsApp API and ultramsg Demo WhatsApp API ChatBot using Ultramsg API with python. Opportunities and tasks: The outpu

Ultramsg 64 Dec 29, 2022
A project that automatically sends you a Medium article on a topic of your choosing to your email address daily.

Daily Article from Medium ✏️ About A project that automatically sends you a Medium article on a topic of your choosing to your email address daily. No

Orhan Emre Dikicigil 2 Apr 27, 2022
Alcarin Tengwar - a Tengwar typeface designed to pair well with the Brill typeface

Alcarin Tengwar Alcarin Tengwar is a Tengwar typeface designed to pair well with

Toshi Omagari 23 Nov 02, 2022
Python Client for MLflow Tracking Server

Python Client for MLflow Python client for MLflow REST API. Features: Unlike MLflow Tracking client all REST API methods are exposed to user. All clas

MTS 35 Dec 23, 2022
Discord-Token-Formatter - A simple script to convert discord tokens from email token to token only format

Discord-Token-Formatter A simple script to convert discord tokens from email:pas

2 Oct 23, 2022
API Wrapper for seedr.cc

Seedr Python Client Seedr API built with 💛 by Souvik Pratiher Hit that Star button if you like this kind of SDKs and wants more of similar SDKs for o

Souvik Pratiher 2 Oct 24, 2021
A maintained fork of Danny's discord.py

Nextcord A modern, easy-to-use, feature-rich, and async-ready API wrapper for Discord written in Python. Fork notice This is a fork of discord.py, whi

977 Jan 05, 2023
Whatsapp-APi Wrapper From rzawapi.my.id

Whatsapp-APi Wrapper From rzawapi.my.id

Rezza Priatna 2 Apr 19, 2022
A Telegram Message Manager Bot by @AbirHasan2005

Messages-Manager-Bot A Telegram Message Manager Bot by @AbirHasan2005. This Bot can delete specific type of messages from Group. I specially use for @

Abir Hasan 32 Nov 12, 2022
Create a roles overview page for all Ansible roles/playbooks in Gitlab

ansible-create-roles-overview Overview The script ./create_roles_overview.py queries a Gitlab API for Ansible roles and playbooks. It will iterate ove

2 Oct 11, 2021
数字货币动态趋势网格,随着行情变动。目前实盘月化10%。目前支持币安,未来上线火币、OKEX。

数字货币动态趋势网格,随着行情变动。目前实盘月化10%。目前支持币安,未来上线火币、OKEX。

幸福村的码农 98 Dec 27, 2022
DeleteAllBot - Telegram bot to delete all messages in a group

Delete All Bot A star ⭐ from you means a lot to me ! Telegram bot to delete all

Stark Bots 15 Dec 26, 2022
TuShare is a utility for crawling historical data of China stocks

TuShare Tushare Pro版已发布,请访问新的官网了解和查询数据接口! https://tushare.pro TuShare是实现对股票/期货等金融数据从数据采集、清洗加工 到 数据存储过程的工具,满足金融量化分析师和学习数据分析的人在数据获取方面的需求,它的特点是数据覆盖范围广,接口

挖地兔 11.9k Dec 30, 2022