Project Summary

  Analyzed 1 day ago based on code collected 1 day ago.

This is a native GeoIP.dat reader for Python. It allows the use of GeoIP without an external service, or Datastore, from Google App Engine.

Cold start takes about 5ms to open the database. Warm lookups are so fast they can't reliably be measured (an urlfetch will cost ~100 ms, a single Datastore get ~20ms).

Note that the returned CIDR prefixes aren't reliable. Suggest not using them for abuse prevention!

The database is cached in memory. This adds 1.1mb to your interpreter size!

ExampleEnsure GeoIP.dat (download) and pygeoip.py (download) are in your AppEngine project directory.

Simple example:

from google.appengine.ext import webapp

import pygeoip

# Load the database once and store it globally in interpreter memory.
GEOIP = pygeoip.Database('GeoIP.dat')

class LookupHandler(webapp.RequestHandler):
def get(self):
info = GEOIP.lookup(self.request.remote_addr)
if not info.country:
msg = 'Could not locate country for ' + self.request.remote_addr
else:
msg = 'Country for %s is %s' % (self.request.remote_addr, info.country)

self.response.out.write(msg)

Share

In a Nutshell, python-geoip...

 

Activity

30 Day Summary Apr 17 2013 — May 17 2013

12 Month Summary May 17 2012 — May 17 2013

Community

 
 
 

Creative Commons License Copyright © 2013 Black Duck Software, Inc. and its contributors, Some Rights Reserved. Unless otherwise marked, this work is licensed under a Creative Commons Attribution 3.0 Unported License . Ohloh ® and the Ohloh logo are trademarks of Black Duck Software, Inc. in the United States and/or other jurisdictions. All other trademarks are the property of their respective holders.