Skip to main content

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

Project description

Geo IP

Note: This is a friendly Python 3 port of [python-geo-ip]( by Avi Asher. We look forward to the original package supporting Python 3.

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

from geoip import geoip
r = geoip.GeoIp()
#This prints : 'US'

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

#This prints : 'JP'

# Command line

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

positional arguments:

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
--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

# Installation

pip install geoip2nation



# ip2nation

- 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

# license


# Links

- ip2nation home:
- ip2nation data file:

Project details

Release history Release notifications

This version
History Node


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
geoip2nation3-0.2.0-py3-none-any.whl (363.9 kB) Copy SHA256 hash SHA256 Wheel py3
geoip2nation3-0.2.0.tar.gz (364.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page