All Projects → maxmind → MaxMind-DB-Reader-python

maxmind / MaxMind-DB-Reader-python

Licence: Apache-2.0 license
Python MaxMind DB reader extension

Programming Languages

python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to MaxMind-DB-Reader-python

MaxMind-DB-Reader-ruby
Ruby reader for the MaxMind DB Database Format
Stars: ✭ 35 (-73.28%)
Mutual labels:  geoip2, geoip, maxmind, mmdb
MaxMind-DB-Writer-perl
Create MaxMind DB database files
Stars: ✭ 63 (-51.91%)
Mutual labels:  geoip2, geoip, maxmind, mmdb
mmdbwriter
Go library for writing MaxMind DB (mmdb) files
Stars: ✭ 44 (-66.41%)
Mutual labels:  geoip2, geoip, maxmind, mmdb
GeoIP2-ruby
Ruby API for GeoIP2 webservice client and database reader
Stars: ✭ 41 (-68.7%)
Mutual labels:  geoip2, geoip, maxmind, mmdb
GeoIP2-perl
Perl API for MaxMind's GeoIP2 web services and databases
Stars: ✭ 18 (-86.26%)
Mutual labels:  geoip2, geoip, maxmind, mmdb
Geoip2 Php
PHP API for GeoIP2 webservice client and database reader
Stars: ✭ 1,956 (+1393.13%)
Mutual labels:  geoip2, geoip, maxmind, mmdb
MaxMind-DB-Reader-java
Java reader for the MaxMind DB format
Stars: ✭ 88 (-32.82%)
Mutual labels:  geoip2, geoip, maxmind, mmdb
locus
MMDB reader for geolocation and ASN lookup of IP addresses
Stars: ✭ 93 (-29.01%)
Mutual labels:  geoip2, geoip, mmdb
nodejs-geoip2ws
Maxmind GeoIP2 Web Services for Node.js
Stars: ✭ 47 (-64.12%)
Mutual labels:  geoip2, geoip, maxmind
geoip2-rs
Fast GeoIP2 Reader for Rust
Stars: ✭ 25 (-80.92%)
Mutual labels:  geoip2, geoip, maxmind
geoip2
GeoIP2 Reader for Go
Stars: ✭ 54 (-58.78%)
Mutual labels:  geoip2, geoip, maxmind
sawmill
Sawmill is a JSON transformation Java library
Stars: ✭ 92 (-29.77%)
Mutual labels:  geoip, maxmind
lua-resty-maxminddb
A Lua library for reading MaxMind's Geolocation database
Stars: ✭ 72 (-45.04%)
Mutual labels:  geoip, maxmind
GeoIP2-CN
小巧精悍、准确、实用 GeoIP2 数据库
Stars: ✭ 3,965 (+2926.72%)
Mutual labels:  geoip2, geoip
pf-azure-sentinel
Parse pfSense/OPNSense logs using Logstash, GeoIP tag entities, add additional context to logs, then send to Azure Sentinel for analysis.
Stars: ✭ 24 (-81.68%)
Mutual labels:  geoip, maxmind
GeoLite2-City
GeoLite2-City.mmdb.gz CDN files based on Free Open Source CDN jsDelivr!
Stars: ✭ 170 (+29.77%)
Mutual labels:  geoip, maxmind
GeoLite2-Country
GeoLite2-Country.mmdb.gz CDN files based on Free Open Source CDN jsDelivr!
Stars: ✭ 69 (-47.33%)
Mutual labels:  geoip, maxmind
ZfSnapGeoip
Maxmind Geoip module for Zend Framework 2
Stars: ✭ 15 (-88.55%)
Mutual labels:  geoip
ip-finder-cli
The official command line client for IPFinder
Stars: ✭ 11 (-91.6%)
Mutual labels:  geoip
mmdb-server
mmdb-server is an open source fast API server to lookup IP addresses for their geographic location.
Stars: ✭ 69 (-47.33%)
Mutual labels:  mmdb

MaxMind DB Python Module

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

If you want to use the C extension, you must first install libmaxminddb C library installed before installing this extension. If the library is not available, the module will fall-back to a pure Python implementation. Note that when installing the C library from a package, you may be required to install additonal packages containing build requirements such as libmaxminddb-dev on Debian.

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 .

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.

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)

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.6+. 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].