Skip to main content

High-performance IP and country lookup backed by Rust poptrie

Project description

poptrie

High-performance IP lookup backed by Rust. This public repository owns the final Python facade and publishes wheels.

Stable public contract:

  • from poptrie import IpSearcher
  • IpSearcher resolves to poptrie.ip_searcher.IpSearcher
  • native extension details are intentionally hidden behind the facade

Installation

Install from PyPI:

pip install poptrie

Usage

import socket
from pathlib import Path

from poptrie import IpSearcher


bin_path = Path("china-ip.bin")
searcher = IpSearcher(bin_path)

print("1.0.1.1" in searcher)
print(searcher.contains_ip("1.0.1.1"))
print(searcher.lookup_country("1.0.1.1"))
print(searcher.is_china("1.0.1.1"))

ips = ["1.0.1.1", "8.8.8.8", "240e::1", "2001:db8::"]
print(searcher.contains_ips(ips))
print(searcher.lookup_countries(ips))
print(searcher.matches_countries(ips, "CN"))

v4_ips = ["1.0.1.1", "8.8.8.8", "110.16.0.1", "127.0.0.1"]
packed_v4 = b"".join(socket.inet_pton(socket.AF_INET, ip) for ip in v4_ips)
print(searcher.contains_packed(packed_v4, is_v6=False))
print(searcher.lookup_countries_packed(packed_v4, is_v6=False))
print(searcher.matches_country_packed(packed_v4, "CN", is_v6=False))

Example

python example.py

Tests

Public facade verification:

python -m unittest discover tests

Notes

  • Country lookups are resolved in Rust and exposed as 2-letter strings in Python.
  • *_packed methods are intended for high-throughput byte-oriented workloads.
  • The public Python facade lives in poptrie/__init__.py and poptrie/ip_searcher.py.
  • Files such as *-overlap.csv are input conflict audit reports, not evidence that the final .dat files still contain overlapping CIDRs.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

poptrie-0.4.3-cp38-abi3-win_amd64.whl (154.5 kB view details)

Uploaded CPython 3.8+Windows x86-64

poptrie-0.4.3-cp38-abi3-manylinux_2_34_x86_64.whl (251.0 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ x86-64

poptrie-0.4.3-cp38-abi3-macosx_11_0_universal2.whl (211.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file poptrie-0.4.3-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: poptrie-0.4.3-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 154.5 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for poptrie-0.4.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 45c5366cf020dc191c26a2efb9e651758ac3c4c18f69c2d82a0ffa0dc7120191
MD5 6646bb2e7958125e6f0146672bb39c25
BLAKE2b-256 887fe9b68985e76bb4a758bf7d26f54723e5536007257911986f5c41f2095711

See more details on using hashes here.

File details

Details for the file poptrie-0.4.3-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for poptrie-0.4.3-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 05b66acf6f0e84b4c45385885acd75f8b80ca89ab089a16c1b72c400a7f86bf6
MD5 cd82a601421149441430d2465bd137c7
BLAKE2b-256 9971bdd50095be1a360ef07e7b31aafbc7d13d0d842edfa928d359fc4936c2bc

See more details on using hashes here.

File details

Details for the file poptrie-0.4.3-cp38-abi3-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for poptrie-0.4.3-cp38-abi3-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 407a1e5e05056787b41085804fb12e5a000af6cd22f2cc96bd265ee0cf7e651c
MD5 fd078aff95ab89ca748aabdfee256cd1
BLAKE2b-256 b05f72db69005118ecf8281b0dae25cfa184401bce7d5760c6f989ea4d6959fe

See more details on using hashes here.

Supported by

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