{"library":"py-radix","title":"py-radix","description":"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.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install py-radix"],"cli":null},"imports":["import radix"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import radix\n\n# Create a new tree\nrtree = radix.Radix()\n\n# Add nodes. Adding a node returns a RadixNode object.\n# You can store arbitrary data in its 'data' dict.\nrnode = rtree.add(\"10.0.0.0/8\")\nrnode.data[\"description\"] = \"Internal Network A\"\n\n# You can also specify networks using separate network and masklen, or packed binary addresses.\nrnode = rtree.add(network=\"172.16.0.0\", masklen=24)\nrnode.data[\"location\"] = \"Branch Office\"\n\n# IPv6 prefixes are fully supported\nrtree.add(\"2001:DB8::/32\")\n\n# Exact search returns a RadixNode if the prefix exists\nfound_node = rtree.search_exact(\"10.0.0.0/8\")\nif found_node:\n    print(f\"Found exact match: {found_node.prefix}, Data: {found_node.data}\")\n\n# Best-match search returns the longest matching prefix\nbest_match = rtree.search_best(\"10.0.0.123\")\nif best_match:\n    print(f\"Best match for 10.0.0.123: {best_match.prefix}, Data: {best_match.data}\")\n\n# Iterate over all nodes in the tree\nprint(\"\\nAll prefixes in the tree:\")\nfor node in rtree:\n    print(node.prefix)","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}