{"id":21038,"library":"cidr-trie","title":"cidr-trie","description":"A Python library for storing and searching CIDR prefixes in a trie structure. It enables efficient longest-prefix matching of IP addresses against a set of CIDR blocks. The current version is 3.1.2. Release cadence is intermittent.","status":"active","version":"3.1.2","language":"python","source_language":"en","source_url":"https://github.com/Figglewatts/cidr-trie","tags":["cidr","trie","networking","ip","prefix-matching"],"install":[{"cmd":"pip install cidr-trie","lang":"bash","label":"Install"}],"dependencies":[],"imports":[{"note":"Old import path in pre-1.0 versions","wrong":"from cidr_trie import Trie","symbol":"CidrTrie","correct":"from cidr_trie import CidrTrie"},{"note":"","wrong":"","symbol":"IpNetwork","correct":"from cidr_trie import IpNetwork"}],"quickstart":{"code":"from cidr_trie import CidrTrie, IpNetwork\n\ntrie = CidrTrie()\ntrie.insert(IpNetwork('10.0.0.0/8'))\ntrie.insert(IpNetwork('10.0.0.0/16'))\nresult = trie['10.0.0.5']\nprint(result)  # IpNetwork('10.0.0.0/16')","lang":"python","description":"Create a trie, insert CIDR prefixes, and perform longest-prefix matching."},"warnings":[{"fix":"Replace `trie.find_longest_prefix(ip)` with `trie[ip]`","message":"The method `find_longest_prefix` is deprecated since v3.0.0; use `trie[ip]` instead.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Replace `trie.no_prefix(ip)` with `try: result = trie[ip]; except KeyError: # handle missing`","message":"CidrTrie.no_prefix() was removed in v3.0.0. Use `trie[ip]` and catch KeyError or pre-check with `ip in trie`.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use a threading lock when modifying the trie from multiple threads.","message":"CidrTrie is not threadsafe. Concurrent modifications may corrupt internal state.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `pip install cidr-trie` and import as `from cidr_trie import CidrTrie`.","cause":"Package name is 'cidr-trie' but import is 'cidr_trie'.","error":"ModuleNotFoundError: No module named 'cidr_trie'"},{"fix":"Use `trie.insert(IpNetwork('10.0.0.0/8'))` to add prefixes.","cause":"Trying to insert using `trie['10.0.0.0/8'] = IpNetwork(...)` instead of `trie.insert()`","error":"TypeError: 'CidrTrie' object does not support item assignment"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}