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 IpSearcherIpSearcherresolves topoptrie.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 codes are returned as u16 in Rust and converted to 2-letter strings in Python.
*_packedmethods are the high-throughput APIs for packed inputs (stride 4/16).- The public Python facade lives in
poptrie/__init__.pyandpoptrie/ip_searcher.py.
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file poptrie-0.4.2-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: poptrie-0.4.2-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 155.3 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbb741af7530363aec1043dcf89a0cc2f9967e052ec1f33b5f27a5f21478e862
|
|
| MD5 |
ac3efbd3a65110e5d98cde94c6d07d34
|
|
| BLAKE2b-256 |
56c4eee62b888010df9565685848d4e6bf10e2640dad5b49caaef1a2fcb2724c
|
File details
Details for the file poptrie-0.4.2-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: poptrie-0.4.2-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 252.2 kB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96953c44ed3f9ab4222ca2a97bd664168e3404fd2f3810a87233e5b3ed9c325c
|
|
| MD5 |
7925ec275d54f33797e98890964571d1
|
|
| BLAKE2b-256 |
d1ac75b2f2bfef982186e9c68ce2832f5f64fc1329c1198dca7bae90b7f46b8b
|
File details
Details for the file poptrie-0.4.2-cp38-abi3-macosx_11_0_universal2.whl.
File metadata
- Download URL: poptrie-0.4.2-cp38-abi3-macosx_11_0_universal2.whl
- Upload date:
- Size: 212.1 kB
- Tags: CPython 3.8+, macOS 11.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b33cefed473c2f46d54928a9e0de0cd2cc55a0c11d607c0c4baa4a7b3c25786
|
|
| MD5 |
cd322495e4c09acee89ffdd99cbf8cf0
|
|
| BLAKE2b-256 |
5e680e823ade7f09c813519e080dba17cb4e9379a77abce58a051ccc45c9320e
|