Skip to main content

Python extension for reading the MaxMind DB format

Project description

Beta Note

This is a beta release. The API may change before the first production release.

Description

This is a Python extension for reading MaxMind DB files. MaxMind DB is a binary file format that stores data indexed by IP address subnets (IPv4 or IPv6).

Installation

You must have the libmaxminddb C library installed before installing this extension.

To install the MaxMind DB extension, type:

$ pip install maxminddb

If you are not able to use pip, you may also use easy_install from the source directory:

$ easy_install .

Usage

To use this module, you must first download or create a MaxMind DB file. We provide free GeoLite2 databases. These files must be decompressed with gunzip.

After you have obtained a database and importing the module, you must create a Reader object, providing the path to the file as the first argument to the constructor. After doing this, you may call the get method with an IP address on the object. This method will return the corresponding values for the IP address from the database (e.g., a dictionary for GeoIP2/GeoLite2 databases). If the database does not contain a record for that IP address, the method will return None.

Example

>>> import maxminddb
>>>
>>> reader = maxminddb.Reader('GeoLite2-City.mmdb')
>>> reader.get('1.1.1.1')
{'country': ... }
>>>
>>> # The optional 'close' method will release the resources to the
>>> # system immediately.
>>> reader.close()

Exceptions

The module will return an InvalidDatabaseError if the database is corrupt or otherwise invalid. A ValueError will be thrown if you look up an invalid IP address or an IPv6 address in an IPv4 database.

Requirements

This code requires CPython 2.6+ or 3.3+. Older versions are not supported.

Versioning

The MaxMind DB Python extension uses Semantic Versioning.

Support

Please report all issues with this code using the GitHub issue tracker

If you are having an issue with a MaxMind service that is not specific to this API, please contact MaxMind support for assistance.

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

maxminddb-0.2.0.tar.gz (1.2 MB view details)

Uploaded Source

File details

Details for the file maxminddb-0.2.0.tar.gz.

File metadata

  • Download URL: maxminddb-0.2.0.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for maxminddb-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9b82e9ee5efc703be65967e8cfed77c4c18242e3e59b5ce60a8c24c25e79bd8b
MD5 03a863a4ec5026ad079512d2c81506a8
BLAKE2b-256 639d6ad9b9fc5751c4270e4f633f9c9b86e761fefa1df61a557d60d145dd3e9a

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