ip3country

A zero-dependency, local, fast, tiny ip-address to country lookup


Keywords
ip, country, lookup, statsig
License
ISC
Install
pip install ip3country==0.2.1

Documentation

ip3country

This is a zero-dependency, super small, IP address to 2-letter country code lookup library. There are already several libraries available, but none met our requirements for binary size and speed.

This project in its entirety is <500KB, compared to most alternatives out there that are north of 40MB (but might provide more than just countries).

The database used in this project is compacted from IP2Location. Their DB1.LITE edition is provided under CCA, with the attribution below:


NOTE

This site or product includes IP2Location LITE data available from https://lite.ip2location.com.


Usage

$ pip install ip3country
# Setup
from ip3country import CountryLookup

lookup = CountryLookup()

# Lookup using ip4 str
print(lookup.lookupStr("123.45.67.8")) # 'KR'

print(lookup.lookupNumeric(2066563848)) # 'KR'

Accuracy

ip3country's accuracy is dependent on IP2Location LITE's accuracy. In our experience, for country lookups, it is accurate enough for most applications.

IP2Location publishes accuracy reports here: https://www.ip2location.com/data-accuracy

There's also this third party report available: https://www.cl.cam.ac.uk/~nz247/publications/JSAC2011-Geolocation.pdf

Name

All variants of "ip2country" were already taken in npm, so we decided to step it up.

Motivation

At Statsig, we needed a library to evaluate location-based conditions on Feature Gates (Feature Flags). We use ip3country to power country-level rollouts or A/B tests for new features.