--- id: pyahocorasick version: "2.3.1" license: BSD-3-Clause and Public-Domain license_treatment: permissive maintenance: active --- # pyahocorasick — pyahocorasick is a fast and memory efficient library for exact or approximate multi-pattern string search. With the ``ahocorasick.Automaton`` class, you can find multiple key string occurrences at once in some input text. You can use it as a plain dict-like Trie or convert a Trie to an automaton for efficient Aho-Corasick search. And pickle to disk for easy reuse of large automatons. Implemented in C and tested on Python 3.6+. Works on Linux, macOS and Windows. BSD-3-Cause license. License: permissive · Maintenance: active · Downloads: 6.0M/mo ## What it is and what it does pyahocorasick is a C-based Python library implementing the Aho-Corasick string matching algorithm, allowing you to search for multiple keyword strings in text in a single pass. It exposes both a Trie data structure for dict-like key-value storage by string and a finalized automaton for efficient multi-pattern search. You build the automaton ahead of time, optionally pickle it to disk, then reuse it to search text repeatedly—making it suited for applications like intrusion detection, anti-virus scanning, or bioinformatics where you have a fixed set of patterns to match against variable input. The library stores pattern prefixes efficiently in memory and guarantees similar worst-case and best-case runtime regardless of pattern count, depending mainly on input text size and match count. It supports both unicode and bytes, works on Python 3.10 and up, and is available as pre-built wheels for Linux, macOS, and Windows, though building from source requires a C compiler. Use it for: - Scan DNA sequencing reads for known CRISPR guide sequences or genetic markers in bioinformatics pipelines - Detect multiple malware signatures or intrusion patterns in network traffic or log files - Find all occurrences of a dictionary of keywords in large text documents for content filtering or analysis - Build a reusable index of product codes or identifiers to match against incoming transaction or inventory data - Implement fast spell-checking or autocorrect by matching input against a pre-built dictionary of valid words ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Finds multiple keyword strings in text efficiently using an Aho-Corasick automaton, built and pickled for reuse. Yes, if you need to match multiple fixed patterns in text efficiently. The C implementation, active maintenance, permissive license, and zero security vulnerabilities make it reliable. Medium install friction is offset by pre-built wheels and performance gains over pure-Python alternatives for large-scale matching. Not necessary for single-pattern or occasional searches. ## Install pip install pyahocorasick uv add pyahocorasick poetry add pyahocorasick ## Installing pyahocorasick Before you install: Medium install friction due to C compilation requirement, but actively maintained with recent release 109 days ago and 1122 GitHub stars. Pre-built wheels available for Python 3.10+ on Linux, macOS, and Windows. License in practice: BSD-3-Clause and Public-Domain license. Permissive treatment allows commercial and private use with minimal restrictions. Quickstart: pip install pyahocorasick import ahocorasick automaton = ahocorasick.Automaton() automaton.add_word('he', (0, 'he')) automaton.add_word('she', (1, 'she')) automaton.make_automaton() for end_index, value in automaton.iter('she'): print(end_index, value) Requires C compiler to build from source; Python 3.10+ required. Pre-built wheels available for common platforms. Verify before relying: - Whether approximate matching (mentioned in description) is fully implemented or only exact matching is production-ready - Performance characteristics compared to other multi-pattern matching libraries in real-world scenarios ## Package facts - License: BSD-3-Clause and Public-Domain (permissive) - Python support: supports_current - Install friction: medium - Maintenance: active - Downloads: 6.0M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags multi-pattern string matching, aho-corasick automaton, trie data structure, fast keyword search, pattern matching library, dictionary-based text search, bulk string matching, string-matching, trie, pattern-search [View on SkillFed](https://skillfed.io/packages/pyahocorasick) · [View on PyPI](https://pypi.org/project/pyahocorasick/)