geoip2
MaxMind GeoIP API
What it is and what it does
geoip2 is the official Python client library for MaxMind's GeoIP and GeoLite services. It provides both synchronous and asynchronous interfaces to query IP geolocation data from MaxMind's web services or from local MaxMind database files. The library handles authentication, request formatting, error handling, and response parsing, returning structured objects with country codes, city names, subdivisions, postal codes, latitude/longitude, and network information.
The package is designed for developers who need to determine the geographic location or network details of an IP address in their application. It supports both real-time web service queries (with optional Sandbox or GeoLite endpoints) and offline database lookups using local .mmdb files. The library abstracts away HTTP communication (via requests or aiohttp) and binary database parsing (via maxminddb), making it straightforward to integrate IP geolocation into web services, analytics pipelines, or security workflows.
Use it for:
- Determine user location for content localization or regional compliance in web applications.
- Detect suspicious login attempts by comparing user IP location against historical patterns.
- Analyze traffic sources and geographic distribution of website visitors.
- Implement geo-blocking or geo-routing logic based on IP address origin.
- Enrich server logs or analytics data with geographic and network metadata.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Queries MaxMind's GeoIP web services and databases to look up geographic and network information for IP addresses, returning country, city, subdivision, postal, and location data.
Yes. geoip2 is the official, actively maintained client for MaxMind's geolocation services, with low install friction, permissive licensing, no known vulnerabilities, and broad Python version support. Install it if you need to look up IP geolocation data; it is the standard choice for this task. Verify you have a MaxMind account and license key (or a local database file) before relying on it in production.
Install
geoip2 on PyPI
pip
pip install geoip2uv
uv add geoip2poetry
poetry add geoip2Installing geoip2
Before you install
Low install friction; pure Python wheel with three runtime dependencies (aiohttp, maxminddb, requests). Actively maintained with a release 29 days ago and last commit on 2026-08-10. Supports modern Python versions (3.10–3.14).
License in practice
Licensed under Apache-2.0 (permissive). You may use, modify, and distribute this package freely in commercial or private projects, provided you include a copy of the license and state any material changes.
Quickstart
import geoip2.webservice
with geoip2.webservice.Client(account_id, 'license_key') as client:
response = client.city('203.0.113.0')
print(response.country.iso_code) # 'US'
print(response.city.name) # 'Minneapolis'
Requires a MaxMind account ID and license key for web service use, or a local GeoIP/GeoLite database file for database reader mode. Optional C extension for database reader requires libmaxminddb system library.
Verify before relying
- Whether the C extension for database reader significantly improves performance over pure Python mode.
- Accuracy and freshness guarantees for GeoIP data returned by the web service or databases.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — aiohttp, maxminddb, requests |
| Maintenance | actively maintained — 29 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 18,029,953/month — #1,089 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: geoip2-5.3.0-py3-none-any.whl
Tags
More Internet packages
Botocore provides low-level, data-driven access…
permissive · top 100 on PyPI
aiobotocoreProvides an async client for AWS services using…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
filelockProvides a platform-independent file locking…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
googleapis-common-protosProvides common Protocol Buffer message…
permissive · top 100 on PyPI
maxminddb-geolite2Provides geolocation lookups by IP address…
unclear · top 15,000 on PyPI
minfraudPython client library for MaxMind's minFraud…
permissive · top 15,000 on PyPI
geoip2fastGeoIP2Fast performs fast geolocation lookups…
permissive · top 15,000 on PyPI
geoip2-toolsAutomates downloading and updating of MaxMind…
permissive · top 15,000 on PyPI
maxminddbReads MaxMind DB files to look up geolocation…
permissive · top 5,000 on PyPI
mmdb-writerGenerates MaxMind DB (MMDB) format files from…
permissive · top 15,000 on PyPI
IP2LocationLooks up geolocation data (country, region,…
permissive · top 15,000 on PyPI
ip3countryLooks up the ISO 3166-1 alpha-2 country code…
permissive · top 5,000 on PyPI
ipinfoQueries the IPinfo.io API to retrieve…
permissive · top 15,000 on PyPI