Skip to main content

Pure Python GeoIP API

This library is based on Maxmind’s GeoIP C API.

Tested with Python version 2.5, 2.6, 2.7, 3.2 and 3.3.

Build Status Coverage Status Downloads

Installation

You can easily install pygeoip from PyPi.

pip install pygeoip

Supported Databases

* COUNTRY_EDITION
* COUNTRY_EDITION_V6
* REGION_EDITION_REV0
* REGION_EDITION_REV1
* CITY_EDITION_REV0
* CITY_EDITION_REV1
* CITY_EDITION_REV1_V6
* ORG_EDITION
* ISP_EDITION
* ASNUM_EDITION
* ASNUM_EDITION_V6

Issues and Contribution

Bug reports are done by creating an issue on Github. If you want to contribute you can always create a pull request for discussion and code submission.

Getting Started

Create your GeoIP instance with appropriate access flag. STANDARD reads data from disk when needed, MEMORY_CACHE loads database into memory on instantiation and MMAP_CACHE loads database into memory using mmap.

import pygeoip
gi4 = pygeoip.GeoIP('/path/to/GeoIP.dat', pygeoip.MEMORY_CACHE)
gi6 = pygeoip.GeoIP('/path/to/GeoIPv6.dat', pygeoip.MEMORY_CACHE)

Country Lookup

>>> gi4.country_code_by_name('google.com')
'US'
>>> gi4.country_code_by_addr('64.233.161.99')
'US'
>>> gi4.country_name_by_addr('64.233.161.99')
'United States'
>>> gi6.country_code_by_name('google.com')
'IE'
>>> gi6.country_code_by_addr('2001:7fd::1')
'EU'
>>> gi6.country_name_by_addr('2001:7fd::1')
'Europe'

Region Lookup

>>> gi = pygeoip.GeoIP('/path/to/GeoIPRegion.dat')
>>> gi.region_by_name('apple.com')
{'region_code': 'CA', 'country_code': 'US'}

City Lookup

>>> gi = pygeoip.GeoIP('/path/to/GeoIPCity.dat')
>>> gi.record_by_addr('64.233.161.99')
{
    'city': u'Mountain View',
    'region_code': u'CA',
    'area_code': 650,
    'time_zone': 'America/Los_Angeles',
    'dma_code': 807,
    'metro_code': 'San Francisco, CA',
    'country_code3': 'USA',
    'latitude': 37.41919999999999,
    'postal_code': u'94043',
    'longitude': -122.0574,
    'country_code': 'US',
    'country_name': 'United States',
    'continent': 'NA'
}
>>> gi.time_zone_by_addr('64.233.161.99')
'America/Los_Angeles'

Organization Lookup

>>> gi = pygeoip.GeoIP('/path/to/GeoIPOrg.dat')
>>> gi.org_by_name('dell.com')
'Dell Computer Corporation'

ISP Lookup

>>> gi = pygeoip.GeoIP('/path/to/GeoIPISP.dat')
>>> gi.org_by_name('cnn.com')
'Turner Broadcasting System'

ASN Lookup

>>> gi = pygeoip.GeoIP('/path/to/GeoIPASNum.dat')
>>> gi.org_by_name('cnn.com')
'AS5662 Turner Broadcasting'

For more information, check out the full API documentation.

Metadata

Release files for pygeoip 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygeoip 0.3.0
File Size Uploaded Provenance Actions
pygeoip-0.3.0.tar.gz 97.3 kB Without provenance Details for pygeoip-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pygeoip 0.3.0
File Interpreter ABI Platform Actions
pygeoip-0.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for pygeoip-0.3.0-py2.py3-none-any.whl

Total release size: 117.7 kB

Release files / pygeoip-0.3.0.tar.gz

Download URL pygeoip-0.3.0.tar.gz
Size 97.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3abc07fe2fa1a6b025d7c75b681bf892dabf19c3f7f44fb896dc851f25d981e4
BLAKE2b-256 checksum
How to use checksums
742ebf61049b868198059fecb23b490d94c9addab66d818420dbff8c33210950
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pygeoip-0.3.0-py2.py3-none-any.whl

Download URL pygeoip-0.3.0-py2.py3-none-any.whl
Size 20.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
70f220a9940bd4286fc5dfe13e1627544c73c312dbe8e1a123ff1df7976e6591
BLAKE2b-256 checksum
How to use checksums
da9b60a2ede14e11aadc7c5fdd466247dee79f36cf75f1caa855a4ab63519ee7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pygeoip 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page