skip to navigation
skip to content

geocoder 0.5.9

A simplistic Python Geocoder (Google, Bing, OSM & more)

Latest Version: 1.38.0


A simplistic Python Geocoder.

Geocoder is an Apache2 Licensed Geocoding library, written in Python.

>>> import geocoder
>>> g ='Moscone Center')
>>> g.latlng
(37.784173, -122.401557)
'San Francisco'


You can install, upgrade, uninstall Geocoder with these commands:

$ pip install geocoder
$ pip install --upgrade geocoder
$ pip uninstall geocoder


Search with Google

Using the Geocoder API from Google, this is a simplistic approach to return you all the same results that Google would provide.

>>> import geocoder
>>> g ='1600 Amphitheatre Pkwy, Mountain View, CA')
>>> g.latlng
(37.784173, -122.401557)
>>> g.postal
'Mountain View'
'United States'

Long names with Google

When using Google, the default results are using the short names, here is how you would retrieve the long names as the results.

>>> g =<address>, short_name=False)

Getting JSON

The web uses JSON and GeoJSON, here is how to return your Geocoded address into this format.

>>> g ='1600 Amphitheatre Parkway, Mountain View, CA')
>>> g.json
{'address': '1600 Amphitheatre Parkway, Mountain View, CA 94043, USA',
'bbox': {'northeast': {'lat': 37.4233474802915, 'lng': -122.0826054197085},
'southwest': {'lat': 37.4206495197085, 'lng': -122.0853033802915}},
'city': 'Mountain View',
'country': 'United States',
'lat': 37.4219985,
'lng': -122.0839544,
'location': '1600 Amphitheatre Parkway, Mountain View, CA 94043, USA',
'ok': True,
'postal': '94043',
'provider': 'Google',
'quality': 'ROOFTOP',
'status': 'OK'}

GeoJSON is a widely used, open format for encoding geographic data, and is supported by a number of popular applications.

>>> import simplejson as json
>>> g ='Ottawa, ON')
>>> json.dumps(g.geojson, indent=4)
"geometry": {
    "type": "Point",
    "coordinates": [
"crs": {
    "type": "name",
    "properties": {
        "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
"type": "Feature",
"properties": {
    "status": "OK",
    "city": "Ottawa",
    "ok": true,
    "country": "Canada",

Using Proxies & Timeout

There many obvious reasons why you would need to use proxies, here is the basic syntax on how to successfully use them.

Timeouts are used to stop the connection if it reaches a certain time.

>>> proxies = ''
>>> g ='Ottawa', proxies=proxies, timeout=5.0)
<[OK] Geocoder Google [Ottawa, ON, Canada]>

Reverse Geocoding

Using Google’s reverse geocoding API, you are able to input a set of coordinates and geocode its location.

>>> latlng = (48.85837, 2.2944813)
>>> g = geocoder.reverse(latlng)
<[OK] Geocoder Google [Eiffel Tower, Paris, France]>

Bounding Box (Extent)

>>> g = geocoder.osm('1600 Amphitheatre Pkwy, Mountain View, CA')
>>> g.bbox
{'northeast': {'lat': 37.4233474802915, 'lng': -122.0826054197085},
'southwest': {'lat': 37.4206495197085, 'lng': -122.0853033802915}}
>>> g.southwest
{'lat': 37.4206495197085, 'lng': -122.0853033802915}
>>> g.south

Geocoding IP Address

Retrieves geocoding data from MaxMind’s GeoIP2 services

>>> g = geocoder.ip('')
>>> g.address
'Mountain View, California United States'
>>> g.latlng
(37.4192, -122.0574)

Geocoding your current IP address, simply use me as the input.

>>> g = geocoder.ip('me')
>>> g.address
'Ottawa, Ontario Canada'
>>> g.latlng
(45.4805, -75.5237)

Population Data from City

Retrieves population data from Geonames’s Web Service API.

>>> pop = geocoder.population('Springfield, Virginia')
>>> pop

Geocoder Attributes

  • address
  • location
  • city
  • state
  • country
  • postal
  • quality
  • status
  • population (integer)
  • ok (boolean)
  • x, lng, longitude (float)
  • y, lat, latitude (float)
  • latlng, xy (tuple)
  • bbox {southwest, northeast}
  • southwest {lat, lng}
  • northeast {lat, lng}
  • south, west, north, east (float)

Geocoding Providers

## Priority Geocoders
>>> geocoder.reverse(<latlng>)
>>> geocoder.ip(<ip>)

## Secondary Geocoders
>>> geocoder.osm(<location>)
>>> geocoder.mapquest(<location>)
>>> geocoder.arcgis(<location>)
>>> geocoder.geonames(<location>, username='XXXXX')
>>><location>, key='XXXXX')
>>><location>, app_id='XXXXX', app_code='XXXXX')
>>> geocoder.tomtom(<location>, key='XXXXX')


This project is free & open source, it would help greatly for you guys reading this to contribute, here are some of the ways that you can help make this Python Geocoder better.


Please feel free to give any feedback on this module. If you find any bugs or any enhancements to recommend please send some of your comments/suggestions to the Github Issues Page.

File Type Py Version Uploaded on Size
geocoder-0.5.9.tar.gz (md5) Source 2014-06-05 13KB
  • Author: Denis Carriere
  • Home Page:
  • Download URL:
  • Keywords: geocoder google lat lng location addxy
  • License:
    Copyright 2014 Denis Carriere
       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at
       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
  • Package Index Owner: addxy
  • DOAP record: geocoder-0.5.9.xml