PyTricia is an efficient IP address storage and lookup module for Python, based on the Patricia trie data structure. It supports IPv4 and IPv6, longest-prefix matching, and set operations. Current version 1.3.0 is stable with no known breaking changes. Release cadence is low (last release 2025).
pip install pytriciaVerified import paths — ran on the pinned version, not inferred.
Basic usage: insert, lookup, longest-prefix match, containment check, iteration, and deletion.
Always provide a prefix length when inserting. For single IPs, use e.g., '192.168.1.1/32'.
Validate input with ipaddress.ip_network(prefix, strict=False) before inserting.
Use 'prefix in pt' before accessing pt[prefix] to avoid KeyError.
Ensure the IP is covered by an inserted prefix. For exact host lookup, insert with /32. Use pt.get(ip, None) to avoid exception.
Check input format: e.g., '10.0.0.0/8' is valid. Use ipaddress module to parse and validate.
Ensure you have created an instance: pt = pytricia.PyTricia() then use pt[prefix] = value.
No dependency data recorded yet.