API Reference

GeoIP

class pygeoip.GeoIP(filename, flags=0, cache=True)
__init__(filename, flags=0, cache=True)

Create and return an GeoIP instance.

Parameters:
  • filename – File path to a GeoIP database
  • flags – Flags that affect how the database is processed. Currently supported flags are STANDARD (default), MEMORY_CACHE (preload the whole file into memory) and MMAP_CACHE (access the file via mmap)
  • cache – Used in tests to skip instance caching
country_code_by_addr(addr)

Returns 2-letter country code (e.g. US) from IP address.

Parameters:addr – IP address (e.g. 203.0.113.30)
country_code_by_name(hostname)

Returns 2-letter country code (e.g. US) from hostname.

Parameters:hostname – Hostname (e.g. example.com)
country_name_by_addr(addr)

Returns full country name for specified IP address.

Parameters:addr – IP address (e.g. 203.0.113.30)
country_name_by_name(hostname)

Returns full country name for specified hostname.

Parameters:hostname – Hostname (e.g. example.com)
id_by_addr(addr)

Returns the database ID for specified address. The ID might be useful as array index. 0 is unknown.

Parameters:addr – IPv4 or IPv6 address (eg. 203.0.113.30)
last_netmask()

Returns the netmask depth of the last lookup.

netspeed_by_addr(addr)

Returns NetSpeed name from address.

Parameters:addr – IP address (e.g. 203.0.113.30)
netspeed_by_name(hostname)

Returns NetSpeed name from hostname. Can be Unknown, Dial-up, Cable, or Corporate.

Parameters:hostname – Hostname (e.g. example.com)
org_by_addr(addr)

Returns Organization, ISP, or ASNum name for given IP address.

Parameters:addr – IP address (e.g. 203.0.113.30)
org_by_name(hostname)

Returns Organization, ISP, or ASNum name for given hostname.

Parameters:hostname – Hostname (e.g. example.com)
record_by_addr(addr)

Returns dictionary with city data containing country_code, country_name, region, city, postal_code, latitude, longitude, dma_code, metro_code, area_code, region_code and time_zone.

Parameters:addr – IP address (e.g. 203.0.113.30)
record_by_name(hostname)

Returns dictionary with city data containing country_code, country_name, region, city, postal_code, latitude, longitude, dma_code, metro_code, area_code, region_code and time_zone.

Parameters:hostname – Hostname (e.g. example.com)
region_by_addr(addr)

Returns dictionary containing country_code and region_code.

Parameters:addr – IP address (e.g. 203.0.113.30)
region_by_name(hostname)

Returns dictionary containing country_code and region_code.

Parameters:hostname – Hostname (e.g. example.com)
time_zone_by_addr(addr)

Returns time zone in tzdata format (e.g. America/New_York or Europe/Paris)

Parameters:addr – IP address (e.g. 203.0.113.30)
time_zone_by_name(hostname)

Returns time zone in tzdata format (e.g. America/New_York or Europe/Paris)

Parameters:hostname – Hostname (e.g. example.com)

GeoIPError

exception pygeoip.GeoIPError

Thin wrapper of Exception, will be thrown in case of an unrecoverable error.