Pure Python API for Maxmind’s binary GeoIP databases

Work in progress!

GeoIP methods

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

Initialize the class.

@param filename: Path to a geoip database. @type filename: str @param flags: Flags that affect how the database is processed. Currently supported flags are STANDARD (the default), MEMORY_CACHE (preload the whole file into memory) and MMAP_CACHE (access the file via mmap). @type flags: int @param cache: Used in tests to skip instance caching @type cache: bool

Country lookup

GeoIP.country_code_by_addr(addr)

Returns 2-letter country code (e.g. ‘US’) for specified IP address. Use this method if you have a Country, Region, or City database.

@param addr: IP address @type addr: str @return: 2-letter country code @rtype: str

GeoIP.country_code_by_name(hostname)

Returns 2-letter country code (e.g. ‘US’) for specified hostname. Use this method if you have a Country, Region, or City database.

@param hostname: Hostname @type hostname: str @return: 2-letter country code @rtype: str

Table Of Contents

This Page