Converts an IP to country name (Google App Engine module)
PHP Python
Latest commit cae9951 Jul 24, 2011 @andris9 Edited via GitHub

NB! No need to use this module anymore

Since SDK 1.5.1 you can use X-AppEngine-country request header (returns a two letter country code or ZZ for unknow locations) to retriev the country of the visitor, no need for external modules anymore.

IP to Country

IP to Country is a Google App Engine module (Python) to convert IP addresses into country names and country codes.


This module is provided FREE under the terms of the GENERAL PUBLIC LICENSE, June 1991


sys.path.insert(0, '')
from iptocountry import convert as iptolocation, country as iptocountry

location = iptolocation()
country = iptocountry()

print "You are from %s (country code - %s)" % (country, location)


To update the database, upzip the PHP files from to /src/ip_files. Then run parser.php which generates new .PY files to src/iptocountry. Zip the directory src/iptocountry to and use the file instead of the old one in your projects.


IP to Country does not use database but a collection of files to find the country for a particular IP address. Google App Engine has a limit of 1000 files per application so it is highly encouraged to ZIP all the module files into one bigger file. See build for an example.