by danstiner
GitHub Readme.md
This is an unofficial Heroku buildpack that installs the latest GeoLite2 City and Country free IP geolocation databases from MaxMind along with the libmaxminddb C library for fast lookups in the databases.
Note an older version of the Country database is available in any Heroku deploy via the packages geoip-bin
, geoip-database
, and libgeoip1
listed on https://devcenter.heroku.com/articles/stack-packages
The GeoLite2 databases are distributed under the Creative Commons Attribution-ShareAlike 4.0 International License. The official download page suggests the attribution requirement may be met by including the following in all advertising and documentation mentioning features of or use of the databases:
This product includes GeoLite2 data created by MaxMind, available from
<a href="http://www.maxmind.com">http://www.maxmind.com</a>.
As of 30-Dev-2019, Maxmind has withdrawn unauthenticated downloads of their free GeoLite2 databases. Read more here.
From Jan-2020 users need a Maxmind account, and a valid license key. This buildpack uses the "direct download" method described in the Maxmind developer documentation (https://dev.maxmind.com/geoip/geoipupdate/#Direct_Downloads).
$ heroku buildpacks:add https://github.com/danstiner/heroku-buildpack-geoip-geolite2.git
In order to download the Maxmind databases, you will need a valid Maxmind license (register with Maxmind and click on "My License Key" in the left-hand menu). You must add this key as an environment variable (setting) called MAXMIND_LICENSE_KEY
.
Add to your settings.py
file:
GEOIP_PATH=os.environ['GEOIP_GEOLITE2_PATH']
GEOIP_CITY=os.environ['GEOIP_GEOLITE2_CITY_FILENAME']
GEOIP_COUNTRY=os.environ['GEOIP_GEOLITE2_COUNTRY_FILENAME']
See https://docs.djangoproject.com/en/1.11/ref/contrib/gis/geoip2/ for installing the geoip2
Python library and usage examples.
Copy the snippet above into CLI.