skillfed

marisa-trie

Static memory-efficient and fast Trie-like structures for Python.

marisa-trie v1.4.1 4.7M downloads/30d#2,245 on PyPI1,123
Copyleft license MIT AND (BSD-2-Clause OR LGPL-2.1-or-later) Active released

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-trie

uv

uv add marisa-trie

poetry

poetry add marisa-trie

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: Science/ResearchProgramming Language :: CythonProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Programming Language :: Python :: Free Threading :: 2 - BetaProgramming Language :: Python :: Implementation :: CPythonTopic :: Scientific/Engineering :: Information AnalysisTopic :: Software Development :: Libraries :: Python ModulesTopic :: Text Processing :: Linguistic

Tags

memory-efficient trie data structurefast prefix search stringscompact string storage pythontrie lookup performancelow-memory string indexingmarisa trie implementationstatic trie structures
memory-efficientstatic-data-structuresstring-indexing

More Python Modules packages