Skip to main content

# Pure Python GeoIP API # The API is based on [MaxMind’s C-based Python API](http://www.maxmind.com/app/python), but the code itself is ported from the [Pure PHP GeoIP API](http://pear.php.net/package/Net_GeoIP) by Jim Winstead and Hans Lellelid.

It is mostly a drop-in replacement, except the new and open methods are gone.

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

## Issues and contribution ##

Bug reports are done by [creating an issue on Github](https://github.com/appliedsec/pygeoip/issues). If you want to contribute you can always [create a pull request](https://github.com/appliedsec/pygeoip/pulls) for discussion and code submission.

## Installation ##

You can easily install pygeoip with setuptools:

easy_install pygeoip

## Supported Databases ##

  • Country

  • Region

  • City

  • Organization

  • ISP

  • ASN

## Quick Documentation ##

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 gi = pygeoip.GeoIP(‘/path/to/GeoIP.dat’, pygeoip.MEMORY_CACHE)

### Country lookup ###

>>> gi.country_code_by_name('google.com')
'US'
>>> gi.country_code_by_addr('64.233.161.99')
'US'
>>> gi.country_name_by_addr('64.233.161.99')
'United States'

### Region lookup ###

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

### City lookup ###

>>> gi = pygeoip.GeoIP('/path/to/GeoIPCity.dat')
>>> gi.record_by_addr('64.233.161.99')
{
    'city': 'Mountain View',
    'region_name': 'CA',
    'area_code': 650,
    'longitude': -122.0574,
    'country_code3': 'USA',
    'latitude': 37.419199999999989,
    'postal_code': '94043',
    'dma_code': 807,
    '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](http://packages.python.org/pygeoip).

Release files for pygeoip 0.2.6

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.2.6
File Size Uploaded
pygeoip-0.2.6.zip 136.8 kB Details

Release files / pygeoip-0.2.6.zip

Download URL pygeoip-0.2.6.zip
Size 136.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e86058479b3820bd08f51b64e22c59fe1ed45ec468d51d36acd5ed413e49e810
BLAKE2b-256 checksum
How to use checksums
db95fd8d930c92abc79e2a82da673a49486246cc47b925c3c519b4e82ac4d8a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.7

1 release file

This release

0.2.6 This release

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.6

1 release file

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