ahocorasick-rs
Search for multiple substrings at the same time, and quickly too
What it is and what it does
ahocorasick_rs is a Python wrapper around the Rust aho-corasick library that finds all occurrences of multiple patterns in a single pass through a text or byte string. It implements the Aho-Corasick automaton algorithm, which is significantly faster than searching for patterns sequentially, especially when you have many patterns or large haystacks. The package supports both string and bytes searching, with configurable matching strategies (Standard, LeftmostFirst, LeftmostLongest) and optional overlapping match detection.
The library exposes two main classes: AhoCorasick for string patterns and BytesAhoCorasick for byte patterns. You can tune performance by choosing between different underlying automaton implementations (NoncontiguousNFA, ContiguousNFA, DFA) and control memory usage through pattern caching. It has one runtime dependency (typing-extensions) and requires Python 3.10 or later.
Use it for:
- Scanning log files or documents for multiple keywords or error codes in a single pass.
- Filtering or redacting sensitive terms from text or data streams.
- Building search indices or content-matching systems that need to detect many patterns efficiently.
- Detecting multiple signatures or indicators in binary or text data.
- Tokenizing or lexing source code by matching multiple reserved words and operators simultaneously.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Searches for multiple substrings in text or bytes using the Aho-Corasick algorithm, returning match positions and matched patterns with configurable overlap and matching strategies.
Yes, if you need to search for multiple patterns in text or bytes. The Aho-Corasick algorithm is significantly faster than sequential pattern matching. Install friction is moderate (compiled wheels) but well-supported across platforms. No vulnerabilities reported, actively maintained, and permissive license. Not necessary if you only search for single patterns or have very few patterns where overhead isn't a concern.
Install
ahocorasick-rs on PyPI
pip
pip install ahocorasick-rsuv
uv add ahocorasick-rspoetry
poetry add ahocorasick-rsInstalling ahocorasick-rs
Before you install
Medium install friction due to compiled wheels; prebuilt binaries available for Python 3.10 through modern versions on macOS, Linux, and Windows. Actively maintained with recent commits and no reported vulnerabilities.
License in practice
Licensed under Apache 2.0 (permissive), allowing use in commercial and proprietary projects with minimal restrictions.
Quickstart
pip install ahocorasick-rs
import ahocorasick_rs
patterns = ["hello", "world"]
ac = ahocorasick_rs.AhoCorasick(patterns)
matches = ac.find_matches_as_strings("hello world")
# Returns: ['hello', 'world']
Requires Python 3.10 or later.
Verify before relying
- Performance comparison with pyahocorasick under realistic workloads and pattern counts.
- Memory overhead of different Implementation choices for typical use cases.
- Thread safety guarantees beyond the documented mutable-buffer constraint.
Package facts
| License | Apache 2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 1 — typing-extensions |
| Maintenance | actively maintained — 310 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 534,741/month — #6,131 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: ahocorasick_rs-1.0.3-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl; ahocorasick_rs-1.0.3-cp310-cp310-macosx_10_12_x86_64.whl; ahocorasick_rs-1.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; ahocorasick_rs-1.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; ahocorasick_rs-1.0.3-cp310-cp310-win_amd64.whl; ahocorasick_rs-1.0.3-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl; ahocorasick_rs-1.0.3-cp311-cp311-macosx_10_12_x86_64.whl; ahocorasick_rs-1.0.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; ahocorasick_rs-1.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; ahocorasick_rs-1.0.3-cp311-cp311-win_amd64.whl; ahocorasick_rs-1.0.3-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl; ahocorasick_rs-1.0.3-cp312-cp312-macosx_10_12_x86_64.whl; ahocorasick_rs-1.0.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; ahocorasick_rs-1.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; ahocorasick_rs-1.0.3-cp312-cp312-win_amd64.whl; ahocorasick_rs-1.0.3-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl; ahocorasick_rs-1.0.3-cp313-cp313-macosx_10_12_x86_64.whl; ahocorasick_rs-1.0.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; ahocorasick_rs-1.0.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; ahocorasick_rs-1.0.3-cp313-cp313-win_amd64.whl
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
ahocorapyahocorapy implements the Aho-Corasick algorithm…
permissive · top 15,000 on PyPI
multiregexMatches multiple regex patterns against a…
permissive · top 15,000 on PyPI
rebulkReBulk provides a fluent API for building…
permissive · top 15,000 on PyPI
flashtextExtracts or replaces keywords in text using the…
permissive · top 5,000 on PyPI
fuzzyfinderFuzzy finder that matches partial strings from…
permissive · top 15,000 on PyPI
wcmatchwcmatch provides enhanced file pattern matching…
permissive · top 1,000 on PyPI
strsimpyImplements a dozen string similarity and…
permissive · top 15,000 on PyPI
farm-haystackHaystack is an end-to-end NLP framework for…
permissive · top 15,000 on PyPI
django-haystackHaystack provides a unified search API for…
permissive · top 15,000 on PyPI