Skip to main content

Lightweight, open‑source Python client designed to resolve IPv4 and IPv6 addresses into their corresponding country codes with minimal overhead. Built specifically for users of the db‑geoip geolocation service, the package provides a clean, predictable interface that abstracts away network handling, request formatting, and error management.

Project description

db‑geoip — Lightweight Country‑Level IP Resolver for Python

db‑geoip is a lightweight, open‑source Python client designed to resolve IPv4 and IPv6 addresses into their corresponding country codes with minimal overhead. Built specifically for users of the db‑geoip geolocation service, the package provides a clean, predictable interface that abstracts away network handling, request formatting, and error management. Instead of maintaining large local databases or integrating heavy geolocation libraries, developers can rely on a simple, efficient API call that returns accurate country‑level information in milliseconds. This makes db‑geoip ideal for applications where geolocation is needed but full city‑level or ASN‑level data would be unnecessary or too resource‑intensive.


✨ Why db‑geoip?

  • Lightweight by design — no bundled datasets, no complex dependencies
  • Open‑source and transparent — easy to audit, extend, or integrate
  • Consistent API — one function, one purpose, predictable output
  • Optimized for production — minimal latency, minimal memory footprint
  • Built for the db‑geoip ecosystem — seamless integration with the hosted resolver

🔍 What It Does

The package sends a small, authenticated request to the db‑geoip resolver service and returns a structured response containing:

- ISO‑compliant country code
- Additional metadata provided by the service (if available)
- Clear error messages for invalid keys or unresolvable IPs

This makes it suitable for a wide range of real‑world scenarios where country‑level attribution is enough to drive logic or analytics.

🧭 Use Cases

  • Security and access control (e.g., blocking or allowing traffic by region)
  • Lightweight analytics and traffic segmentation
  • Content localization and regional feature toggles
  • Network utilities, monitoring tools, and diagnostic scripts
  • Fraud detection heuristics based on country‑level signals

🎯 Who This Package Is For

This client is intended for developers who already use or plan to use the db‑geoip service and want a minimal, reliable way to integrate country‑level IP resolution into Python applications without unnecessary complexity.

🚀 Installation

Install the package from PyPI:

pip install db-geoip

Or add it to your project’s requirements.txt:

db-geoip>=1.0.0

🔧 Usage Example

from db_geoip import resolve_ip

result = resolve_ip("8.8.8.8", api_key="YOUR_API_KEY")
print(result["country_code"])  # e.g., "US"

📘 API Documentation

resolve_ip(ip_address: str, api_key: str) -> dict

Resolves an IPv4 or IPv6 address to its associated country information using the db‑geoip resolver service.

Parameters

Parameter Type Description
ip_address str The IPv4 or IPv6 address to resolve.
api_key bool Your db‑geoip API key. Required for authentication.

Returns

A Python dictionary containing structured geolocation data. Typical fields include:

{
    "ip": "8.8.8.8",
    "iso_code": "US",
    "country_name": "United States"
}

Exceptions

Parameter Description
Exception("Invalid API key") The IPv4 or IPv6 address to resolve.
Exception("Unable to resolve geolocation for this IP") The IP address cannot be resolved.
requests.exceptions.RequestException Network or connection issues.
ValueError Response is not valid JSON.

Behavior

  • Sends a POST request to the db‑geoip resolver endpoint
  • Validates response status codes
  • Parses JSON into a Python dictionary
  • Raises clear, predictable exceptions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db_geoip-1.3.23.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

db_geoip-1.3.23-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file db_geoip-1.3.23.tar.gz.

File metadata

  • Download URL: db_geoip-1.3.23.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for db_geoip-1.3.23.tar.gz
Algorithm Hash digest
SHA256 35ed7a54fe9599746a29fa7f00373e8d4d83867ca04f6340bdad573a8c88cdf6
MD5 2bba3a1fbafb0ee9c6cb4f8715093367
BLAKE2b-256 7877312e8d1cb8af5306af891c1eafcff82a842131d5f32606afd3881136d8c7

See more details on using hashes here.

File details

Details for the file db_geoip-1.3.23-py3-none-any.whl.

File metadata

  • Download URL: db_geoip-1.3.23-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for db_geoip-1.3.23-py3-none-any.whl
Algorithm Hash digest
SHA256 0dfd3beb6da8cac9fa2d2560bef21b6109950efcf973660261f3e9a6fa9c1ff5
MD5 56820d359acd0fa25bcba9b5b5033372
BLAKE2b-256 29edb1d47e0a905ca99fc9275111689bf4b82f672cee7c0696dd92f8f79f8632

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page