marisa-trie
Static memory-efficient and fast Trie-like structures for Python.
What it is and what it does
marisa-trie wraps the MARISA C++ trie library to provide immutable, memory-efficient trie data structures for Python. It trades mutability for dramatic memory savings and fast lookups on static string collections. The package includes Trie (for string-to-integer ID mapping), BytesTrie (for arbitrary byte sequences), RecordTrie (for string-to-value mappings), and StringTrie (for string-to-string mappings). All structures support prefix search and iteration over keys and items.
The primary use case is storing and querying large static string datasets—such as dictionaries, word lists, or IP address ranges—where memory footprint is a concern. Once built, a trie is serialized to disk and can be memory-mapped for fast access without reloading into RAM. The trade-off is that the trie cannot be modified after creation; new data requires rebuilding.
Use it for:
- Store a large dictionary or word list for spell-checking or autocomplete with minimal memory overhead.
- Index IP addresses or network prefixes for fast lookup and prefix-based filtering.
- Build a static lexicon for natural language processing tasks requiring efficient string-to-ID or string-to-value mapping.
- Implement a fast prefix-search engine over a fixed set of strings (e.g., domain names, product SKUs).
- Serialize and memory-map a trie to disk for fast startup and low-memory footprint in long-running services.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides memory-efficient trie data structures for fast string lookups and prefix searches, using up to 50x-100x less memory than standard Python dicts while maintaining comparable lookup speed.
Yes, if you have a static string dataset and memory efficiency is a priority. The package is actively maintained, supports modern Python versions (3.9–3.14), has no known vulnerabilities, and offers prebuilt wheels for most platforms. The copyleft license (LGPL/BSD 2-clause bundled library) requires compliance but is not a blocker for most use cases. Install friction is moderate due to C++ compilation, but wheels mitigate this for common platforms.
Install
marisa-trie on PyPI
pip
pip install marisa-trieuv
uv add marisa-triepoetry
poetry add marisa-trieInstalling marisa-trie
Before you install
Medium install friction due to compiled C++ extensions, but prebuilt wheels are available for Python 3.9–3.14 across macOS, Linux (including aarch64), Windows, and musllinux platforms. Actively maintained with recent releases.
License in practice
Dual licensing: wrapper code is MIT; bundled C++ library is dual-licensed under LGPL or BSD 2-clause. Users must comply with LGPL or BSD 2-clause terms for the underlying library.
Quickstart
pip install marisa-trie
from marisa_trie import Trie
trie = Trie(['apple', 'application', 'apply'])
if 'apple' in trie:
print(trie.key_id('apple'))
Requires Python 3.9 or later; compiled C++ extension requires a compatible C++ compiler at build time if wheels are not available for your platform.
Verify before relying
- Whether the 50x-100x memory reduction claim applies to all data sizes or primarily to large datasets.
- Performance characteristics of prefix search and other advanced methods compared to alternative trie implementations.
- Practical use-case suitability for dynamic (mutable) datasets, given the static/immutable design.
Package facts
| License | MIT AND (BSD-2-Clause OR LGPL-2.1-or-later) (copyleft) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 128 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 4,718,771/month — #2,245 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: marisa_trie-1.4.1-cp310-cp310-macosx_10_9_x86_64.whl; marisa_trie-1.4.1-cp310-cp310-macosx_11_0_arm64.whl; marisa_trie-1.4.1-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; marisa_trie-1.4.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; marisa_trie-1.4.1-cp310-cp310-musllinux_1_2_aarch64.whl; marisa_trie-1.4.1-cp310-cp310-musllinux_1_2_x86_64.whl; marisa_trie-1.4.1-cp310-cp310-win32.whl; marisa_trie-1.4.1-cp310-cp310-win_amd64.whl; marisa_trie-1.4.1-cp310-cp310-win_arm64.whl; marisa_trie-1.4.1-cp311-cp311-macosx_10_9_x86_64.whl; marisa_trie-1.4.1-cp311-cp311-macosx_11_0_arm64.whl; marisa_trie-1.4.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; marisa_trie-1.4.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; marisa_trie-1.4.1-cp311-cp311-musllinux_1_2_aarch64.whl; marisa_trie-1.4.1-cp311-cp311-musllinux_1_2_x86_64.whl; marisa_trie-1.4.1-cp311-cp311-win32.whl; marisa_trie-1.4.1-cp311-cp311-win_amd64.whl; marisa_trie-1.4.1-cp311-cp311-win_arm64.whl; marisa_trie-1.4.1-cp312-cp312-macosx_10_13_x86_64.whl; marisa_trie-1.4.1-cp312-cp312-macosx_11_0_arm64.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
pygtriepygtrie provides pure Python implementations of…
permissive · top 5,000 on PyPI
PyTriePyTrie provides a pure Python 3 trie data…
permissive · top 15,000 on PyPI
trieImplements the Ethereum Merkle Trie data…
permissive · top 15,000 on PyPI
immutablesProvides an immutable mapping type backed by a…
permissive · top 5,000 on PyPI
sqltrieSQLTrie implements a prefix tree (trie) data…
permissive · top 5,000 on PyPI
retrieBuilds efficient Trie-based regex patterns for…
permissive · top 15,000 on PyPI
cidr-trieStores and queries CIDR IP address blocks (IPv4…
permissive · top 15,000 on PyPI
intbitsetintbitset provides a fast, memory-efficient set…
copyleft · top 15,000 on PyPI