skillfed

py-radix

Radix tree implementation

py-radix v1.1.0 211.8K downloads/30d#9,472 on PyPI130
Permissive license BSD AGING released

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-radix

uv

uv add py-radix

poetry

poetry add py-radix

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python ModulesTopic :: System :: Networking

Tags

radix tree implementationIP prefix lookuprouting table data structureIPv4 IPv6 network storageCIDR prefix matchingnetwork prefix searchtrie tree networking
routingip-networksdata-structures

More Python Modules packages