--- id: pygtrie version: "2.5.0" license: Apache-2.0 license_treatment: permissive maintenance: dormant --- # pygtrie — A pure Python trie data structure implementation. License: permissive · Maintenance: dormant · Downloads: 13.9M/mo ## What it is and what it does pygtrie is a pure Python trie (prefix tree) library that stores key-value pairs organized by shared prefixes, allowing efficient prefix-based lookups and iteration. It provides three main classes—Trie, CharTrie, and StringTrie—each implementing Python's mutable mapping interface (dict-like behavior), plus a PrefixSet class for storing sets of prefixes where membership includes all keys sharing a stored prefix. The library is useful when you need to query or iterate over all keys with a common prefix, find shortest or longest prefix matches, or delete entire subtrees of keys at once. It works as a drop-in dict replacement in most cases but shines when prefix operations are central to your use case. The package has no runtime dependencies and is compatible with Python 2.x and 3.x, though it is currently dormant—last release was 2022-07-16. Use it for: - Autocomplete and search-as-you-type systems that need to retrieve all keys starting with a user's input prefix - IP routing tables or CIDR block lookups where you need longest-prefix matching - Dictionary or spell-checker implementations that support prefix-based word lookups and suggestions - File path or URL hierarchies where you need to query or delete all entries under a given path prefix - Storing and querying hierarchical configuration keys or namespaced settings by prefix ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. pygtrie provides pure Python implementations of trie (prefix tree) data structures—Trie, CharTrie, StringTrie, and PrefixSet—that implement the mutable mapping interface for efficient prefix-based lookups and storage. Yes, if you need trie-based prefix lookups and can tolerate dormant maintenance. The package is stable, has no dependencies, and solves a specific problem well. However, verify that the empty requires_python field doesn't mask compatibility issues with your Python version, and be aware that bug fixes or updates are unlikely without community contribution. ## Install pip install pygtrie uv add pygtrie poetry add pygtrie ## Installing pygtrie Before you install: Installation is straightforward with no runtime dependencies. The package is marked Production/Stable but dormant—last release was 2022-07-16 and the repository received its last commit 2024-03-26, so expect no active maintenance or rapid bug fixes. License in practice: Licensed under Apache-2.0 (permissive), so you can use, modify, and distribute pygtrie freely in commercial and private projects with minimal restrictions. Quickstart: pip install pygtrie from pygtrie import StringTrie trie = StringTrie({'foo/bar': 42}, separator='/') print(trie['foo/bar']) # 42 print(list(trie.prefixes('foo/bar/baz'))) # prefix lookup Verify before relying: - Whether the package is actively maintained or receives security updates despite dormant status - Performance characteristics and memory usage compared to alternative trie implementations - Compatibility with Python versions beyond 2.7 and 3.x (requires_python field is empty) ## Package facts - License: Apache-2.0 (permissive) - Python support: unspecified - Install friction: low - Maintenance: dormant - Downloads: 13.9M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags trie data structure python, prefix tree implementation, radix tree library, prefix lookup dictionary, string prefix matching, trie prefix set, python mutable mapping trie, data-structures, prefix-matching [View on SkillFed](https://skillfed.io/packages/pygtrie) · [View on PyPI](https://pypi.org/project/pygtrie/)