WojciechMula/pyahocorasick
FreePython module (C extension and plain python) implementing Aho-Corasick algorithm
About WojciechMula/pyahocorasick
pyahocorasick is a fast and memory-efficient Python library for exact or approximate multi-pattern string search, implementing the Aho-Corasick algorithm. It provides an ahocorasick module that can be used as a dict-like trie or converted into an automaton for efficient searching. The library is implemented in C, supports Python 3.9 and up, and runs on 64-bit Linux, macOS, and Windows. It is licensed under BSD-3-Clause. Key features include the ability to build a search index ahead of time and persist it via pickle, and a simple API for adding words, checking membership, and iterating over all occurrences in input text. The library is used in production for tasks such as counting CRISPR guides in DNA sequencing reads.
Key Features
Pros & Cons
- Fast and memory efficient due to C implementation
- Simple API similar to Python dict for trie usage
- Multi-pattern search in a single pass over input
- Cross-platform support for Linux, macOS, Windows
- Open source with permissive BSD-3 license
- Proven in production at AstraZeneca for bioinformatics
- Requires a C compiler to install from source (via pip includes binary wheels for common platforms)
- Limited to Python 3.9+ (no support for older Python versions)
- May be overkill for simple single-pattern search tasks