We’re branching into the U.S. market with our wedding registry website, Gifty. So first we grabbed a
.com domain name, but we also had to make sure the price shows correctly in USD or NZD depending on where you’re from.
There are a number of tools available for geo-locating someone based on their IP address, including some free ones. MaxMind is pretty popular and nice to use, and their free GeoLite Country database did the trick for me.
Gifty runs on Python, so I wanted something I could just use in pure Python. It turns out that pygeoip is a nice Python replacement for MaxMind’s C-based API.
However, I was only interested in the country-code lookup, so I decided to strip it down and release the two-pages-of-Python version I’m using. Just grab MaxMind’s database and put the code in Python’s
And then to use it, simply type:
>>> import geoip >>> geoip.country('22.214.171.124') 'NZ'
10 July 2009 by Ben 7 comments