Skip to main content

Reader for the MaxMind DB format

Project description

Description

This is a Python module for reading MaxMind DB files. The module includes both a pure Python reader and an optional C extension.

MaxMind DB is a binary file format that stores data indexed by IP address subnets (IPv4 or IPv6).

Installation

To install maxminddb, type:

$ pip install maxminddb

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

$ easy_install .

The installer will attempt to build the C extension. If this fails, the module will fall-back to the pure Python implementation.

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 imported the module, call open_database with a path, or file descriptor (in the case of MODE_FD), to the database as the first argument. Optionally, you may pass a mode as the second argument. The modes are exported from maxminddb. Valid modes are:

  • MODE_MMAP_EXT - use the C extension with memory map.

  • MODE_MMAP - read from memory map. Pure Python.

  • MODE_FILE - read database as standard file. Pure Python.

  • MODE_MEMORY - load database into memory. Pure Python.

  • MODE_FD - load database into memory from a file descriptor. Pure Python.

  • MODE_AUTO - try MODE_MMAP_EXT, MODE_MMAP, MODE_FILE in that order. Default.

NOTE: When using MODE_FD, it is the caller’s responsibility to be sure that the file descriptor gets closed properly. The caller may close the file descriptor immediately after the Reader object is created.

The open_database function returns a Reader object. To look up an IP address, use the get method on this object. The 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.

If you wish to also retrieve the prefix length for the record, use the get_with_prefix_len method. This returns a tuple containing the record followed by the network prefix length associated with the record.

You may also iterate over the whole database. The Reader class implements the __iter__ method that returns an iterator. This iterator yields a tuple containing the network and the record.

Example

>>> import maxminddb
>>>
>>> with maxminddb.open_database('GeoLite2-City.mmdb') as reader:
>>>
>>>     reader.get('152.216.7.110')
{'country': ... }
>>>
>>>     reader.get_with_prefix_len('152.216.7.110')
({'country': ... }, 24)
>>>
>>>     for network, record in reader:
>>>         ...

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 Python 3.8+. Older versions are not supported. The C extension requires CPython.

Versioning

The MaxMind DB Python module 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-2.6.2.tar.gz (181.3 kB view hashes)

Uploaded Source

Built Distributions

maxminddb-2.6.2-pp310-pypy310_pp73-win_amd64.whl (36.5 kB view hashes)

Uploaded PyPy Windows x86-64

maxminddb-2.6.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (36.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

maxminddb-2.6.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (37.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

maxminddb-2.6.2-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (38.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

maxminddb-2.6.2-pp310-pypy310_pp73-macosx_11_0_arm64.whl (33.6 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

maxminddb-2.6.2-pp310-pypy310_pp73-macosx_10_9_x86_64.whl (33.8 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

maxminddb-2.6.2-pp39-pypy39_pp73-win_amd64.whl (36.5 kB view hashes)

Uploaded PyPy Windows x86-64

maxminddb-2.6.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (36.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

maxminddb-2.6.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (37.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

maxminddb-2.6.2-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (38.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

maxminddb-2.6.2-pp39-pypy39_pp73-macosx_11_0_arm64.whl (33.6 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

maxminddb-2.6.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (33.8 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

maxminddb-2.6.2-pp38-pypy38_pp73-win_amd64.whl (36.5 kB view hashes)

Uploaded PyPy Windows x86-64

maxminddb-2.6.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (36.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

maxminddb-2.6.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (37.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

maxminddb-2.6.2-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (38.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

maxminddb-2.6.2-pp38-pypy38_pp73-macosx_11_0_arm64.whl (33.6 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

maxminddb-2.6.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (33.8 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

maxminddb-2.6.2-cp312-cp312-win_amd64.whl (36.6 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

maxminddb-2.6.2-cp312-cp312-win32.whl (34.7 kB view hashes)

Uploaded CPython 3.12 Windows x86

maxminddb-2.6.2-cp312-cp312-musllinux_1_2_x86_64.whl (92.2 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

maxminddb-2.6.2-cp312-cp312-musllinux_1_2_i686.whl (91.1 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

maxminddb-2.6.2-cp312-cp312-musllinux_1_2_aarch64.whl (92.3 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ ARM64

maxminddb-2.6.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (89.5 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

maxminddb-2.6.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (90.0 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

maxminddb-2.6.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (87.6 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

maxminddb-2.6.2-cp312-cp312-macosx_11_0_arm64.whl (35.0 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

maxminddb-2.6.2-cp312-cp312-macosx_10_9_x86_64.whl (35.2 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

maxminddb-2.6.2-cp311-cp311-win_amd64.whl (36.5 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

maxminddb-2.6.2-cp311-cp311-win32.whl (34.5 kB view hashes)

Uploaded CPython 3.11 Windows x86

maxminddb-2.6.2-cp311-cp311-musllinux_1_2_x86_64.whl (90.5 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

maxminddb-2.6.2-cp311-cp311-musllinux_1_2_i686.whl (90.2 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

maxminddb-2.6.2-cp311-cp311-musllinux_1_2_aarch64.whl (91.3 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ ARM64

maxminddb-2.6.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (88.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

maxminddb-2.6.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (88.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

maxminddb-2.6.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (86.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

maxminddb-2.6.2-cp311-cp311-macosx_11_0_arm64.whl (34.8 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

maxminddb-2.6.2-cp311-cp311-macosx_10_9_x86_64.whl (34.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

maxminddb-2.6.2-cp310-cp310-win_amd64.whl (36.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

maxminddb-2.6.2-cp310-cp310-win32.whl (34.5 kB view hashes)

Uploaded CPython 3.10 Windows x86

maxminddb-2.6.2-cp310-cp310-musllinux_1_2_x86_64.whl (90.4 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

maxminddb-2.6.2-cp310-cp310-musllinux_1_2_i686.whl (90.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

maxminddb-2.6.2-cp310-cp310-musllinux_1_2_aarch64.whl (91.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ ARM64

maxminddb-2.6.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (87.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

maxminddb-2.6.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (88.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

maxminddb-2.6.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (86.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

maxminddb-2.6.2-cp310-cp310-macosx_11_0_arm64.whl (34.8 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

maxminddb-2.6.2-cp310-cp310-macosx_10_9_x86_64.whl (34.9 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

maxminddb-2.6.2-cp39-cp39-win_amd64.whl (36.5 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

maxminddb-2.6.2-cp39-cp39-win32.whl (34.5 kB view hashes)

Uploaded CPython 3.9 Windows x86

maxminddb-2.6.2-cp39-cp39-musllinux_1_2_x86_64.whl (90.1 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

maxminddb-2.6.2-cp39-cp39-musllinux_1_2_i686.whl (89.8 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ i686

maxminddb-2.6.2-cp39-cp39-musllinux_1_2_aarch64.whl (90.8 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ ARM64

maxminddb-2.6.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (87.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

maxminddb-2.6.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (88.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

maxminddb-2.6.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (86.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

maxminddb-2.6.2-cp39-cp39-macosx_11_0_arm64.whl (34.8 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

maxminddb-2.6.2-cp39-cp39-macosx_10_9_x86_64.whl (34.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

maxminddb-2.6.2-cp38-cp38-win_amd64.whl (36.5 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

maxminddb-2.6.2-cp38-cp38-win32.whl (34.5 kB view hashes)

Uploaded CPython 3.8 Windows x86

maxminddb-2.6.2-cp38-cp38-musllinux_1_2_x86_64.whl (91.1 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

maxminddb-2.6.2-cp38-cp38-musllinux_1_2_i686.whl (90.9 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ i686

maxminddb-2.6.2-cp38-cp38-musllinux_1_2_aarch64.whl (91.7 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ ARM64

maxminddb-2.6.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (88.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

maxminddb-2.6.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (89.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

maxminddb-2.6.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (87.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

maxminddb-2.6.2-cp38-cp38-macosx_11_0_arm64.whl (34.8 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

maxminddb-2.6.2-cp38-cp38-macosx_10_9_x86_64.whl (34.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

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