| staging | cron | production |
|---|---|---|
High-performance IP lookup backed by Rust. This public repository owns the final Python facade and publishes wheels.
Stable public contract:
from poptrie import IpSearcherIpSearcherresolves topoptrie.ip_searcher.IpSearcher- native extension details are intentionally hidden behind the facade
Install from PyPI:
pip install poptrieimport 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))python example.pyPublic facade verification:
python -m unittest discover tests- Country lookups are resolved in Rust and exposed as 2-letter strings in Python.
*_packedmethods are intended for high-throughput byte-oriented workloads.- The public Python facade lives in
poptrie/__init__.pyandpoptrie/ip_searcher.py. - Files such as
*-overlap.csvare input conflict audit reports, not evidence that the final.datfiles still contain overlapping CIDRs.