marisa-trie provides static, memory-efficient, and fast Trie-like data structures for Python, wrapping the C++ MARISA library. It's ideal for use cases like autocomplete, spell checkers, and storing large sets of strings or byte sequences for fast prefix matching and lookup. The library is actively maintained with regular updates to support new Python versions and minor feature enhancements.
pip install marisa-trieVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating a BytesTrie (the default Trie) and a StringTrie, then performing basic lookups and prefix searches. Note that BytesTrie expects byte strings for all operations.
Upgrade to Python 3.9 or newer. For Python 3.7/3.8, use marisa-trie<1.3.0.
Plan your data set in advance. If dynamic updates are needed, MARISA Trie might not be the right choice, or you'll need to re-build the trie periodically.
Encode strings to bytes (e.g., `s.encode('utf-8')`) before passing them to `BytesTrie` methods. Alternatively, use `StringTrie` (available since v1.4.0) if you primarily work with `str` type keys and values.On Debian/Ubuntu: `sudo apt-get update && sudo apt-get install build-essential python3-dev`. On Fedora/RHEL: `sudo dnf install @development-tools python3-devel`. On macOS, install Xcode Command Line Tools: `xcode-select --install`.
Ensure the package is installed in your active environment: `pip install marisa-trie`. If using virtual environments, activate it before installing. If it's still missing, verify the installation path or check for more detailed errors during the `pip install` command.
Ensure all elements in the input iterable for `marisa_trie.Trie` are strings (e.g., `['key1', 'key2']`) or byte sequences. If you need to store complex objects, consider using `marisa_trie.RecordTrie` or `marisa_trie.BytesTrie` which support richer data types.
Upgrade to a `marisa-trie` version that officially supports Python 3.9+ (e.g., 1.x or later). The project actively maintains support for newer Python versions. `pip install --upgrade marisa-trie` should fetch a compatible version.
No dependency data recorded yet.