py-radix
Radix tree implementation
What it is and what it does
py-radix provides a radix tree (also called a trie) optimized for storing and retrieving network prefixes. It accepts IPv4 and IPv6 addresses in multiple formats—CIDR notation, separate network and mask length, or binary packed addresses—and supports three types of prefix searches: exact match, best match (longest prefix, used in routing), and worst match (shortest prefix). The tree stores arbitrary metadata in a data dictionary attached to each node.
The package is implemented primarily in C for speed, with a pure Python fallback available. It has no runtime dependencies and compiles to wheels for Python 3.9–3.12 on macOS, Linux, Windows, and ARM architectures. The API is straightforward: create a tree, add prefixes, and query them using one of the search methods. It is commonly used in network applications, routing simulators, and IP-based access control systems.
Use it for:
- Build a routing table simulator or network lookup service that matches IP addresses to their containing network prefixes.
- Implement IP-based access control or firewall rules by storing allowed/blocked CIDR ranges and checking incoming addresses.
- Store geolocation or ASN data indexed by IP prefix and retrieve it with a single lookup.
- Analyze network traffic by classifying packets into predefined subnets and aggregating statistics per prefix.
- Validate or normalize network configurations by checking whether proposed prefixes overlap with existing allocations.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements a radix tree data structure for efficient storage and lookup of IPv4 and IPv6 network prefixes, commonly used for routing table operations.
Yes, if you need efficient prefix matching for IPv4 or IPv6 networks. The package is stable, permissively licensed, has no dependencies, and compiles to wheels for most platforms. The aging maintenance status (last release 253 days ago) is acceptable for a mature, narrow-purpose library with no known vulnerabilities, but check whether the feature set meets your exact needs before committing to it as a long-term dependency.
Install
py-radix on PyPI
pip
pip install py-radixuv
uv add py-radixpoetry
poetry add py-radixInstalling py-radix
Before you install
Medium install friction due to C extension compilation; wheels are pre-built for Python 3.9–3.12 across multiple platforms (macOS, Linux, Windows, ARM), reducing friction for standard environments. Maintenance status is aging—last release 253 days ago, but the repository remains active and not archived.
License in practice
Licensed under BSD (permissive), allowing use in both open-source and proprietary projects with minimal restrictions. The underlying C implementation is subject to a 4-term BSD license; see LICENSE file for details.
Quickstart
import radix
rtree = radix.Radix()
rnode = rtree.add("10.0.0.0/8")
rnode.data["label"] = "my_data"
# Best-match search (routing-style lookup)
result = rtree.search_best("10.123.45.6")
if result:
print(result.prefix)
C extension requires a C compiler at build time unless RADIX_NO_EXT=1 is set; pre-built wheels available for Python 3.9–3.12 on common platforms reduce this friction.
Verify before relying
- Whether the pure Python fallback (when C extension is disabled) has performance implications for large trees.
- Performance characteristics or benchmarks for trees with thousands or millions of prefixes.
- Whether IPv6 and IPv4 prefixes can be mixed in the same tree without performance degradation.
Package facts
| License | BSD (permissive) |
| Python support | not specified |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | aging — 253 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 211,822/month — #9,472 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: py_radix-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl; py_radix-1.1.0-cp310-cp310-macosx_11_0_arm64.whl; py_radix-1.1.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; py_radix-1.1.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; py_radix-1.1.0-cp310-cp310-musllinux_1_2_aarch64.whl; py_radix-1.1.0-cp310-cp310-musllinux_1_2_x86_64.whl; py_radix-1.1.0-cp310-cp310-win32.whl; py_radix-1.1.0-cp310-cp310-win_amd64.whl; py_radix-1.1.0-cp310-cp310-win_arm64.whl; py_radix-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl; py_radix-1.1.0-cp311-cp311-macosx_11_0_arm64.whl; py_radix-1.1.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; py_radix-1.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; py_radix-1.1.0-cp311-cp311-musllinux_1_2_aarch64.whl; py_radix-1.1.0-cp311-cp311-musllinux_1_2_x86_64.whl; py_radix-1.1.0-cp311-cp311-win32.whl; py_radix-1.1.0-cp311-cp311-win_amd64.whl; py_radix-1.1.0-cp311-cp311-win_arm64.whl; py_radix-1.1.0-cp312-cp312-macosx_10_13_x86_64.whl; py_radix-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
Keywords: radix, tree, trie, python, routing, networking
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
cidr-trieStores and queries CIDR IP address blocks (IPv4…
permissive · top 15,000 on PyPI
pyasnpyasn performs fast offline IP address to…
permissive · top 15,000 on PyPI
IPyIPy provides Python classes for parsing,…
permissive · top 5,000 on PyPI
netaddrRepresents and manipulates IPv4, IPv6, MAC…
permissive · top 5,000 on PyPI
pygtriepygtrie provides pure Python implementations of…
permissive · top 5,000 on PyPI
ipaddrProvides utilities for parsing, validating, and…
permissive · top 15,000 on PyPI
iptoolsProvides utilities for parsing, validating, and…
permissive · top 15,000 on PyPI
PyTriePyTrie provides a pure Python 3 trie data…
permissive · top 15,000 on PyPI
django-netfieldsProvides Django model fields for PostgreSQL…
permissive · top 15,000 on PyPI
sqltrieSQLTrie implements a prefix tree (trie) data…
permissive · top 5,000 on PyPI