Skip to content

jamesdolan/ip_to_country

Repository files navigation

🌎 ip_to_country

Rewrite of IPToCC 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.

CI Update MIT

Features

  • No external API call
  • No paid GeoIP service
  • Offline
  • Database updated nightly
  • IPv4
  • IPv6 (TODO)

Performance

Measured on M3 MacBook Air with Python 3.9.6

  • Load database: ctx = ip_to_country.Context() -> 0.0006s (vs IPToCC 19.158s)
  • IP to Country Code: cc = ctx.country_code(ip) -> 0.0182ms (vs IPToCC 237.057ms)
  • Peak memory consumption: ~3MB (vs IPToCC 394MB)

Install

Install the latest version with the latest database...

pip install git+https://github.com/jamesdolan/ip_to_country.git@main

Usage

import ip_to_country
ctx = ip_to_country.Context()
cc = ctx.country_code("<IPv4/IPv6 address>")

References

About

Fast Offline IP to Country Code lookup

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages