ahocorasick-rs is a Python library that provides efficient multi-pattern string searching capabilities. It's implemented as a high-performance wrapper around the Rust `aho-corasick` library, offering a significantly faster alternative to pure Python or C-backed `pyahocorasick` for searching many substrings simultaneously. The library is actively maintained, with its latest version being 1.0.3, and typically releases updates as needed for performance improvements or new Python version support.
pip install ahocorasick-rsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize an AhoCorasick object with a list of patterns and then use it to find occurrences within a haystack string, returning either the pattern indices and positions or the matched strings themselves. It also includes an example for byte string matching.
Upgrade to version 1.0.0 or later for guaranteed API stability. Review changelog for specific changes if migrating from pre-1.0.0 versions.
Benchmark with your specific use case. For extremely small-scale, infrequent operations, consider simpler string methods.
Explicitly configure the `MatchKind` when constructing `AhoCorasick` or `BytesAhoCorasick` if specific overlap handling is required. Consult the documentation for `MatchKind` options.
For memory-constrained environments or applications with very high pattern counts, explore `Implementation.ContiguousNFA` or `Implementation.NoncontiguousNFA` to reduce memory footprint at the potential cost of search speed. Profile your application to find the optimal balance.
The main class for string matching in `ahocorasick_rs` is `AhoCorasick` (or `BytesAhoCorasick` for byte strings). Replace `ahocorasick_rs.Automaton` with `ahocorasick_rs.AhoCorasick`.
Ensure the input `patterns` argument is an iterable (e.g., `['pattern1', 'pattern2']`) and that all elements within it are consistent (e.g., all `str` or all `bytes`).
Install the library using `pip install ahocorasick-rs`. If using a virtual environment, ensure it's activated.
No dependency data recorded yet.