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.
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires C compiler to build from source; Python 3.10+ required.
- Pre-built wheels available for common platforms.
- Medium install friction due to C compilation requirement, but actively maintained with recent release 109 days ago and 1122 GitHub stars.
License · maintenance · safety
BSD-3-Clause and Public-Domain (permissive) — BSD-3-Clause and Public-Domain license. Permissive treatment allows commercial and private use with minimal restrictions.
last release 2026-04-27 (109 days) · last repo commit 2026-04-27 · 1,122 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 5,979,577 downloads/mo, #1,997 on PyPI
Alternatives
Verify before relying
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)- 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
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 on this page. Verify before relying on it.
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
pyahocorasick on PyPI
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.
Requires C compiler to build from source; Python 3.10+ required. Pre-built wheels available for common platforms.
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)
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 the current Python release >=3.10 |
| Install friction | Medium. Platform-specific wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 109 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 5,979,577 / month, #1,997 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableProgramming Language :: CProgramming Language :: Python :: 3Topic :: Software Development :: LibrariesTopic :: Text Editors :: Text Processing |
Evidence: pyahocorasick-2.3.1-cp310-cp310-macosx_10_9_universal2.whl; pyahocorasick-2.3.1-cp310-cp310-macosx_11_0_arm64.whl; pyahocorasick-2.3.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; pyahocorasick-2.3.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; pyahocorasick-2.3.1-cp310-cp310-musllinux_1_2_aarch64.whl; pyahocorasick-2.3.1-cp310-cp310-musllinux_1_2_x86_64.whl; pyahocorasick-2.3.1-cp310-cp310-win_amd64.whl; pyahocorasick-2.3.1-cp311-cp311-macosx_10_9_universal2.whl; pyahocorasick-2.3.1-cp311-cp311-macosx_11_0_arm64.whl; pyahocorasick-2.3.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; pyahocorasick-2.3.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; pyahocorasick-2.3.1-cp311-cp311-musllinux_1_2_aarch64.whl; pyahocorasick-2.3.1-cp311-cp311-musllinux_1_2_x86_64.whl; pyahocorasick-2.3.1-cp311-cp311-win_amd64.whl; pyahocorasick-2.3.1-cp312-cp312-macosx_10_13_universal2.whl; pyahocorasick-2.3.1-cp312-cp312-macosx_11_0_arm64.whl; pyahocorasick-2.3.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl; pyahocorasick-2.3.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; pyahocorasick-2.3.1-cp312-cp312-musllinux_1_2_aarch64.whl; pyahocorasick-2.3.1-cp312-cp312-musllinux_1_2_x86_64.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “multi-pattern string matching”
- pyahocorasickFinds multiple keyword strings in text efficiently using an…
- ahocorasick-rsSearches for multiple substrings in text or bytes using the…
- multiregexMatches multiple regex patterns against a string efficiently by using…
Give your agent the search over MCP, or paste the wish link into any chat.
More Libraries packages
urllib3 is an HTTP client library that provides thread-safe connection pooling, SSL/TLS verification, multipart file uploads, request retries, compression support, and proxy handling for Python applications.
Requests is a Python HTTP library that simplifies sending HTTP/1.1 requests with automatic handling of headers, authentication, cookies, and response parsing.
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
Provides parsing, arithmetic, and recurrence rule computation for dates and times, with timezone support and iCalendar RFC compliance.
Install it if you need to parse flexible date strings, compute relative dates, handle timezones, or work with recurrence rules—it's the de facto choice for these tasks.
Six provides utility functions to write Python code that runs on both Python 2.7 and Python 3.3+, smoothing over language differences between the two versions.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
See also ahocorapy · ahocorasick-rs · textsearch · flashtext · retrie · marisa-trie · PyTrie · pysimstring · immutables · paragraphs