--- id: ahocorapy version: "1.8.0" license: MIT license_treatment: permissive maintenance: active --- # ahocorapy — ahocorapy - Pure python ahocorasick implementation License: permissive · Maintenance: active · Downloads: 77.4K/mo ## What it is and what it does ahocorapy is a pure-Python implementation of the Aho-Corasick algorithm designed to search for multiple keywords in text or arbitrary sequences with linear-time complexity. It was created to address gaps in existing libraries: it supports unicode in Python 2.7 without C extensions (making it platform-independent), and it uses suffix-shortcutting during setup to accelerate lookup times. The library works with any hashable symbols—strings, tuples of integers, lists of tokens, or bytes—making it flexible for character-level, word-level, or token-level matching. The package trades setup time for faster search performance by precomputing state transitions and match positions. On sparse text it matches C-extension performance on CPython; on dense text (many overlapping matches) it remains slower than C extensions but faster than other pure-Python alternatives. It is fully pickleable using a non-recursive serialization strategy to handle large keyword trees, and it supports case-insensitive matching for string-based searches. Use it for: - Scan large documents for a fixed set of names, terms, or patterns without installing compiled dependencies. - Perform word-level keyword matching by building a tree from token lists instead of character sequences. - Search binary data or custom symbol sequences (tuples, lists) using the same algorithm without string conversion. - Serialize and reuse large pre-built keyword trees across application restarts via pickling. - Find all overlapping keyword matches in a single pass through text, returning both matches and their positions. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. ahocorapy implements the Aho-Corasick algorithm in pure Python to search for multiple keywords in text or arbitrary sequences in linear time, supporting unicode and case-insensitive matching. Yes. ahocorapy is worth installing for multi-keyword search when you need a pure-Python, platform-independent solution with unicode support and no compiled dependencies. It is actively maintained, has no security vulnerabilities, carries a permissive MIT license, and performs competitively on typical (sparse) text. Install it if C extensions are unavailable or undesirable; if you are searching very dense text with many overlapping matches and latency is critical, a C-based alternative may be faster. ## Install pip install ahocorapy uv add ahocorapy poetry add ahocorapy ## Installing ahocorapy Before you install: Installation is straightforward with no runtime dependencies and low friction. The package is actively maintained with a release 24 days old and has been stable since its first release in 2018. License in practice: MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal restrictions. Quickstart: pip install ahocorapy from ahocorapy.keywordtree import KeywordTree kwtree = KeywordTree(case_insensitive=True) kwtree.add('malaga') kwtree.add('lacrosse') kwtree.finalize() result = kwtree.search('My favorite islands are malaga and sylt.') print(result) Tree construction is not thread-safe; concurrent calls to add() have undefined behavior. Finalize the tree before using it in multi-threaded search contexts. Verify before relying: - Whether the library's performance on dense text (0.42s for 100 searches) meets your latency requirements compared to C-extension alternatives. - Memory overhead of the suffix-shortcutting optimization relative to other pure-Python implementations in your use case. - Whether pickling support for huge keyword trees is tested at the scale your application requires. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 77.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags aho-corasick algorithm python, multi-keyword search, pattern matching multiple strings, fast substring search, keyword tree lookup, sequence matching algorithm, text search library, string-matching, algorithm-implementation, pure-python [View on SkillFed](https://skillfed.io/packages/ahocorapy) · [View on PyPI](https://pypi.org/project/ahocorapy/)