py-radix is a Python library that implements the radix tree (also known as a Patricia tree) data structure, primarily for efficient storage and retrieval of IPv4 and IPv6 network prefixes. This structure is commonly used for routing table lookups due to its ability to efficiently store prefixes of varying lengths and perform fast lookups of containing networks. The library is actively maintained, with version 1.1.0 released in late 2025, and consistently supports recent Python versions.
pip install py-radixVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a Radix tree, add IPv4 and IPv6 network prefixes with associated data, and perform exact and best-match lookups. It also shows how to iterate through all stored nodes.
Ensure C build tools are properly installed for your system. If encountering persistent build errors, particularly on newer Python versions, try setting the environment variable `RADIX_NO_EXT=1` before `pip install py-radix` to force installation of the pure Python version (though this may have performance implications). Check the GitHub issues for specific patches or workarounds for your environment.
Avoid adding or deleting nodes within a `for rnode in rtree:` loop. If you need to modify the tree based on its contents, collect the necessary modifications and apply them after the iteration completes. Modifying a node's `data` dictionary during iteration is safe.
To bypass C extension compilation and install the pure Python version, set the environment variable `RADIX_NO_EXT=1` before running `pip install py-radix`. Example: `RADIX_NO_EXT=1 pip install py-radix`.
Ensure `py-radix` is installed in your active Python environment by running `pip install py-radix`. If using virtual environments, ensure your environment is activated.
Install the necessary C build tools for your operating system. For Linux, this often involves `sudo apt-get install build-essential` (Debian/Ubuntu) or equivalent. For Windows, install 'Desktop development with C++' from Visual Studio Installer. As a workaround, you can install the pure Python version by setting `RADIX_NO_EXT=1` before installation: `RADIX_NO_EXT=1 pip install py-radix`.
No dependency data recorded yet.