geoip2-tools
geoip2-tools provides command-line utilities for the automatic update and administration of MaxMind GeoIP2 databases. It simplifies the process of downloading and managing the GeoLite2 or GeoIP2 databases. The current version is 0.1.1, and the project appears to be in a stable state with a slow release cadence, primarily focusing on bug fixes.
Common errors
-
Command 'geoip2-tools' not found
cause The `geoip2-tools` package is not installed or the executable is not in your system's PATH.fixEnsure the package is installed: `pip install geoip2-tools`. If installed in a virtual environment, ensure the environment is activated. If installed globally, verify your PATH. -
Neither GEOIP2_ACCOUNT_ID nor GEOIP2_LICENSE_KEY were provided.
cause The MaxMind credentials required for downloading database updates are missing.fixSet your MaxMind Account ID and License Key as environment variables: `export GEOIP2_ACCOUNT_ID="YOUR_ACCOUNT_ID"` and `export GEOIP2_LICENSE_KEY="YOUR_LICENSE_KEY"`. Replace placeholders with your actual credentials. Alternatively, configure them in a `geoip2-tools.yaml` file. -
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: ...
cause Your MaxMind Account ID or License Key are incorrect or have expired, leading to an authentication failure when trying to download databases.fixDouble-check your `GEOIP2_ACCOUNT_ID` and `GEOIP2_LICENSE_KEY` values for correctness. Verify them on your MaxMind account page. Ensure your license key is still active.
Warnings
- gotcha This library is designed for *managing* GeoIP2 databases (downloading, updating). It is not for performing GeoIP lookups within Python code. For that, you should use the `geoip2` library directly (e.g., `from geoip2.database import Reader`).
- gotcha To download or update GeoIP2 databases, you *must* provide your MaxMind Account ID and License Key. These can be set via `GEOIP2_ACCOUNT_ID` and `GEOIP2_LICENSE_KEY` environment variables, or through a configuration file.
- gotcha The default database download location might not be suitable for your production environment. Databases are typically stored in `/usr/local/share/GeoIP` (Linux) or a user's data directory. Consider configuring a custom path if needed.
Install
-
pip install geoip2-tools
Imports
- Manager
from geoip2_tools.manager import Manager
Quickstart
# 1. Set your MaxMind account ID and license key as environment variables # (Replace 'YOUR_ACCOUNT_ID' and 'YOUR_LICENSE_KEY' with your actual credentials) export GEOIP2_ACCOUNT_ID="YOUR_ACCOUNT_ID" export GEOIP2_LICENSE_KEY="YOUR_LICENSE_KEY" # 2. Run the update command to download/update databases geoip2-tools update # 3. Check the status of your databases geoip2-tools status