Package: pyramid_geoip
[pyramid_geoip][] integrates the [MaxMind][] GeoIP database with a [Pyramid][]/ SQLAlchemy web application. You can use it to locate incoming requests bytheir IP address:data = request.geoip('89.16.224.130')data['city'], data['country_code']-> 'London', 'GB'data['latitude'], data['longitude']-> 51.514199999999988, -0.093099999999992633Note that [pyramid_geoip][] stores GeoIP data in an *SQL database* (as opposedto storing it on the filesystem) and reads all the data (many MB) into *memory*on application start. This may well *not* be the pattern / setup you want, inwhich case you may find it better to integrate yourself using [pygeoip][].## InstallInstall using [pip][]:pip install pyramid_geoipCreate a `blobs` database table, corresponding to the[pyramid_basemodel.blob.Blob][] model class, e.g.: using [alembic][]:alembic -c $PASTE_CONFIG revision --autogeneratealembic -c $PASTE_CONFIG upgrade head## Configure[Configure your application][] to include the package (n.b.: see the notes inthe update section below before you deploy):config.include('pyramid_geoip')Optionally override the data sources, using your[PasteDeploy configuration file][]:geoip.cities_ip4_url=https://example.com/GeoLiteCity.dat.gzgeoip.cities_ip6_url=https://example.com/GeoLiteCityv6.dat.gzYou can also use locally vendored data files, which will override the urls /read from db machinery if present. The defaults looked for are:geoip.cities_ip4_path=vendor/GeoLiteCity.datgeoip.cities_ip6_path=vendor/GeoLiteCityv6.dat## UseUse the utility provided at `request.geoip` to lookup data by IP address, e.g.in a [view callable][]:data = request.geoip()By default, this will use the ip address for the incoming request (read fromthe `REMOTE_ADDR` in the [WSGI environment][], or from the value of the`X-Forwarded-For` header if provided by a [load balancer or proxy][]). Notealso that it will work for IPv4 and IPv6 addresses.To specify the address yourself, e.g.:data = request.geoip('89.16.224.130')The data contains country, region, city, lat lng, etc.:data['country_code']  # 'GB'data['city']          # 'London'data['latitude']      # 51.514199999999988data['longitude']     # -0.093099999999992633## UpdateMaxMind data loses accuracy over time and consequently MaxMind ship new dataevery month -- specifically on the first Tuesday of each month. You can callthe update module as a script to fetch the latest data:python ./pyramid_geoip/update.pyNote that you may want to:1. run this script before you `config.include` the package in your mainapplication configuration (as it takes time to download the data and yourapplication will hang starting up until the data is available)1. schedule this to run monthly## TestsTo run the tests, `pip install nose coverage mock` and e.g.:$ nosetests pyramid_geoip --with-doctest --with-coverage --cover-tests --cover-package pyramid_geoip......Name                       Stmts   Miss  Cover   Missing--------------------------------------------------------pyramid_geoip                 10      0   100%pyramid_geoip.interfaces       4      0   100%pyramid_geoip.lookup          69      0   100%pyramid_geoip.update          12      0   100%--------------------------------------------------------TOTAL                         95      0   100%----------------------------------------------------------------------Ran 6 tests in 0.041sOK[pyramid_geoip]: https://github.com/thruflo/pyramid_geoip[MaxMind]: http://www.maxmind.com/en/home[Pyramid]: http://pyramid.readthedocs.org[pygeoip]: https://pypi.python.org/pypi/pygeoip[pip]: http://www.pip-installer.org[pyramid_basemodel.blob.Blob]: https://github.com/thruflo/pyramid_basemodel/blob/master/src/pyramid_basemodel/blob.py[alembic]: http://alembic.readthedocs.org/en/latest/tutorial.html#auto-generating-migrations[Configure your application]: http://pyramid.readthedocs.org/en/latest/narr/configuration.html[view callable]: http://pyramid.readthedocs.org/en/latest/narr/views.html[PasteDeploy configuration file]: http://pyramid.readthedocs.org/en/latest/narr/paste.html[WSGI environment]: http://en.wikipedia.org/wiki/Web_Server_Gateway_Interface[load balancer or proxy]: http://en.wikipedia.org/wiki/X-Forwarded-For