Skip to main content

Convert ip addresses to a country using ip2nation db in memory.

Project description

=========== Geo IP

Provides a fast, seamless in memory ip to country functionality based on the ip2nation db.

  • No dependencies
  • Completely free
  • Country resolution only
  • Queries / sec > 13.5k per core
  • Data file can be refreshed without a restart
  • Memory footprint < 40 MB
  • Command line
  • Stream / pipe ips and get comma delimited [ip,2 letter country code] e.g.,US

Change log:

  • If you upgrade please note that there is a BREAKING CHANGE geoip module was renamed to xgeoip
  • Supports Python 2.7 / 3.x
  • ip2nation file updated to May 2020 version
#Python 2.7 / Python 3.x
from geoip import xgeoip
r = xgeoip.GeoIp()
#This prints : 'US'

print (r.resolve(""))
#This prints : {'country': 'Korea (South)', 'host_name': '', 'country_code': 'KR'}

#This prints : 'JP'

Command line

package usage: python geoip/ resolve {'country_code': 'AU', 'country': 'Australia', 'host_name': ''}

source usage: python [-h] [-v] {download,resolve} ...

positional arguments: {download,resolve}

optional arguments: -h, --help show this help message and exit -v, --verbose increase output verbosity

usage: resolve [-h] [-ho] [-s] [--stream] ip

positional arguments: ip The ip address to get the country for

optional arguments: -h, --help show this help message and exit -ho, --host When set to true the code will try to get the host name -s, --short When set to true the code will return a 2 letter country code only --stream When set to true the code expect a stream of ips

usage: download [-h]

optional arguments: -h, --help show this help message and exit


pip install geoip2nation




  • Data can be downloaded using the download method

  • The load_memory method loads the ip2nation sql data file from disk into an in memory sqlite3 db




Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geoip2nation-0.2.7.tar.gz (371.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page