MaxMind GeoIP database updater
Project description
pygeoipupdate
Python client for updating MaxMind GeoIP2 and GeoLite2 databases.
Description
pygeoipupdate is a program that downloads and updates GeoIP2 and GeoLite2
binary MMDB databases from MaxMind. This is a Python port of the
official Go version.
Installation
pip install pygeoipupdate
Or with uv:
uv add pygeoipupdate
Quick Start
-
Get your Account ID and License Key from your MaxMind account page.
-
Create a configuration file or set environment variables:
export GEOIPUPDATE_ACCOUNT_ID=12345 export GEOIPUPDATE_LICENSE_KEY=your_license_key export GEOIPUPDATE_EDITION_IDS="GeoLite2-City GeoLite2-Country"
-
Run pygeoipupdate:
pygeoipupdate
Usage
Command Line
# Using a config file
pygeoipupdate -f /etc/GeoIP.conf
# Using environment variables
pygeoipupdate
# Verbose output
pygeoipupdate -v
# JSON output (for scripting)
pygeoipupdate -o
# Parallel downloads
pygeoipupdate --parallelism 4
Python API
import asyncio
from pathlib import Path
from pygeoipupdate import Config, Updater
config = Config(
account_id=12345,
license_key="your_license_key",
edition_ids=["GeoLite2-City", "GeoLite2-Country"],
database_directory=Path("/var/lib/GeoIP"),
)
async def main():
async with Updater(config) as updater:
results = await updater.run()
for result in results:
if result.was_updated:
print(f"Updated {result.edition_id}")
else:
print(f"{result.edition_id} is up to date")
asyncio.run(main())
Loading Configuration from File
from pathlib import Path
from pygeoipupdate import Config, Updater
config = Config.from_file(config_file=Path("/etc/GeoIP.conf"))
async with Updater(config) as updater:
await updater.run()
Configuration
Configuration can be provided via (in order of precedence):
- CLI arguments
- Environment variables
- Configuration file
- Default values
Configuration File Format
# GeoIP.conf
# Your MaxMind account ID
AccountID 12345
# Your MaxMind license key
LicenseKey your_license_key
# Space-separated list of edition IDs to download
EditionIDs GeoLite2-City GeoLite2-Country GeoLite2-ASN
# Directory to store database files
DatabaseDirectory /var/lib/GeoIP
# Optional: Number of parallel downloads (default: 1)
Parallelism 4
# Optional: Preserve file modification times
PreserveFileTimes 1
# Optional: Retry duration for failed requests (default: 5m)
RetryFor 10m
Environment Variables
| Variable | Description |
|---|---|
GEOIPUPDATE_ACCOUNT_ID |
MaxMind account ID |
GEOIPUPDATE_LICENSE_KEY |
MaxMind license key |
GEOIPUPDATE_ACCOUNT_ID_FILE |
Path to file containing account ID |
GEOIPUPDATE_LICENSE_KEY_FILE |
Path to file containing license key |
GEOIPUPDATE_EDITION_IDS |
Space-separated list of edition IDs |
GEOIPUPDATE_DB_DIR |
Database directory |
GEOIPUPDATE_HOST |
Update server URL |
GEOIPUPDATE_PROXY |
Proxy URL (http, https, or socks5) |
GEOIPUPDATE_PROXY_USER_PASSWORD |
Proxy credentials (user:password) |
GEOIPUPDATE_PRESERVE_FILE_TIMES |
Preserve file times (0 or 1) |
GEOIPUPDATE_LOCK_FILE |
Lock file path |
GEOIPUPDATE_RETRY_FOR |
Retry duration (e.g., "5m", "1h") |
GEOIPUPDATE_PARALLELISM |
Number of parallel downloads |
GEOIPUPDATE_VERBOSE |
Enable verbose output (0 or 1) |
CLI Options
pygeoipupdate [OPTIONS]
Options:
-f, --config-file PATH Path to the configuration file
-d, --database-directory PATH
Directory to store database files
-v, --verbose Enable verbose output
-o, --output Output download results as JSON
--parallelism INTEGER Number of parallel downloads
-V, --version Show the version and exit
-h, --help Show this message and exit
Default Paths
Unix/Linux/macOS
- Configuration file:
/usr/local/etc/GeoIP.conf - Database directory:
/usr/local/share/GeoIP
Windows
- Configuration file:
%SYSTEMDRIVE%\ProgramData\MaxMind\GeoIPUpdate\GeoIP.conf - Database directory:
%SYSTEMDRIVE%\ProgramData\MaxMind\GeoIPUpdate\GeoIP
Error Handling
When using the Python API, pygeoipupdate raises specific exceptions:
GeoIPUpdateError— Base exception for all errors.ConfigError— Invalid configuration.DownloadError— Download failure.AuthenticationError— Invalid account ID or license key.HTTPError— HTTP error with.status_codeand.bodyattributes.
LockError— Could not acquire the lock file.HashMismatchError— Downloaded file hash mismatch (.expected,.actual).
Running as a Cron Job
To keep your databases up to date, we recommend running pygeoipupdate at least twice per week. Here's an example cron entry:
# Run twice a week on Wednesday and Sunday at 3:00 AM
0 3 * * 0,3 /usr/local/bin/pygeoipupdate
Requirements
- Python 3.11+
- A MaxMind account with a license key
Bug Reports
Please report bugs by filing an issue with our GitHub issue tracker.
Versioning
This library uses Semantic Versioning.
Copyright and License
This software is Copyright (c) 2025 - 2026 by MaxMind, Inc.
This is free software, licensed under the Apache License, Version 2.0 or the MIT License, at your option.
Links
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pygeoipupdate-0.1.0.tar.gz.
File metadata
- Download URL: pygeoipupdate-0.1.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae84f14bff52d9d341874abdcc1752fd526f5ec42afdd9f85607baa5d4d1f035
|
|
| MD5 |
583efd36ffcdd91dd58fa12b6d9abf62
|
|
| BLAKE2b-256 |
d974d568aaeb84201fb999e0f8052ddcd7ba150f672c18730a14f2dd47f005b6
|
Provenance
The following attestation bundles were made for pygeoipupdate-0.1.0.tar.gz:
Publisher:
release.yml on maxmind/pygeoipupdate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygeoipupdate-0.1.0.tar.gz -
Subject digest:
ae84f14bff52d9d341874abdcc1752fd526f5ec42afdd9f85607baa5d4d1f035 - Sigstore transparency entry: 938033623
- Sigstore integration time:
-
Permalink:
maxmind/pygeoipupdate@d495e8acce4a53eea37b5437b2b17115d9acf3bd -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/maxmind
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d495e8acce4a53eea37b5437b2b17115d9acf3bd -
Trigger Event:
release
-
Statement type:
File details
Details for the file pygeoipupdate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pygeoipupdate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a22ce28d81e544d003c83b0afada0b3f1f4000706deedd374c7ee747740d7bd
|
|
| MD5 |
fe7167ff60f8465480d8aee003088300
|
|
| BLAKE2b-256 |
11d5e19058eaae24b8daa2aca5c498faa8a61fbe9b39407c53d3f52dde02603b
|
Provenance
The following attestation bundles were made for pygeoipupdate-0.1.0-py3-none-any.whl:
Publisher:
release.yml on maxmind/pygeoipupdate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygeoipupdate-0.1.0-py3-none-any.whl -
Subject digest:
6a22ce28d81e544d003c83b0afada0b3f1f4000706deedd374c7ee747740d7bd - Sigstore transparency entry: 938033634
- Sigstore integration time:
-
Permalink:
maxmind/pygeoipupdate@d495e8acce4a53eea37b5437b2b17115d9acf3bd -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/maxmind
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d495e8acce4a53eea37b5437b2b17115d9acf3bd -
Trigger Event:
release
-
Statement type: