Rewrite of IPToCC 2.x with an emphesis on performance (>10000x faster queries!) and memory reduction (99% less!), with no external dependencies and database that is updated nightly. Designed to be blazing fast on even the smallest VPS cloud instances.
UPDATE: IPToCC 3.x is a complete rewrite in Rust, which is even faster than ip_to_country!
- No external API call
- No paid GeoIP service
- Offline
- Database updated nightly
- IPv4
- IPv6 (TODO)
Measured on M3 MacBook Air with Python 3.9.6
- Load database:
ctx = ip_to_country.Context()-> 0.0003s (vs IPToCC 19.158s) - IP to Country Code:
cc = ctx.country_code(ip)-> 0.0041ms (vs IPToCC 237.057ms) - Peak memory consumption: ~1.2MB (vs IPToCC 394MB)
Install the latest version with the latest database...
pip install git+https://github.com/jamesdolan/ip_to_country.git@mainimport ip_to_country
ctx = ip_to_country.Context()
cc = ctx.country_code("<IPv4/IPv6 address>")