Automatic updates and administration of MaxMind GeoIP2 databases.
Project description
Automatic updates and administration of MaxMind GeoIP2 databases.
To install geoip2-tools, run this command in your terminal:
$ pip install geoip2-tools
This is the preferred method to install geoip2-tools, as it will always install the most recent stable release.
Usage
To use this library you must first obtain a license from Maxmind. It is free for the geolite2 version of the database.
In the menu on the left, navigate to Services > My License Key.
Click Generate new license key.
Save your license key in a secure site.
geoip2-tools downloads the latest version of the database and keeps it updated for you. By default every 7 days it is downloaded from the Maxmind servers.
from geoip2_tools.manager import Geoip2DataBaseManager
geoip2_manager = Geoip2DataBaseManager('<license key>')
print(geoip2_manager['country'].reader.country('1.1.1.1').country.name) # Australia
Geoip2-tools has aliases for the city, country, and asn Geolite2 databases. The country database is smaller than city. The city database also contains the countries:
city = geoip2_manager['country'].reader.city('<ip address>')
print(city.city.name)
print(city.country.name)
To obtain the ASN you must use the asn database:
asn = geoip2_manager['country'].reader.asn('<ip address>')
print(asn.autonomous_system_number)
print(asn.autonomous_system_organization)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for geoip2_tools-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a064e42841c6f944278853ec75792104c24c1257f0dbd133cf84e6d0d391a193 |
|
MD5 | 266088c2ece45ceb3403273eaf9a2bc3 |
|
BLAKE2b-256 | 2dbfef436b7c617f05d1e31df2b5c7a8d46a57b1d925ed9b03495221bb90d01e |