--- id: ahocorasick-rs version: "1.0.3" license: Apache 2.0 license_treatment: permissive maintenance: active --- # ahocorasick-rs — Search for multiple substrings at the same time, and quickly too License: permissive · Maintenance: active · Downloads: 534.7K/mo ## 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 above — 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 pip install ahocorasick-rs uv add ahocorasick-rs poetry add ahocorasick-rs ## Installing 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_current - Install friction: medium - Maintenance: active - Downloads: 534.7K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags multiple substring search, aho-corasick algorithm, pattern matching in text, fast multi-pattern search, string matching library, bulk text search, overlapping pattern detection, string-matching, performance-critical, rust-backed [View on SkillFed](https://skillfed.io/packages/ahocorasick-rs) · [View on PyPI](https://pypi.org/project/ahocorasick-rs/)