Python bindings for Hyperscan. This library provides high-performance regular expression matching, designed for large-scale pattern matching tasks, including multi-pattern and streaming modes. Version 0.8.2 is the current release, with active development and frequent updates, often seeing several patch releases and minor updates within a few months.
pip install hyperscanVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to compile multiple regular expressions into a Hyperscan database and then scan input data in both block and streaming modes. It includes a match event handler to process detected matches. Remember that patterns must be bytes.
For persistent issues, consider building from source with specific CMake flags to enable PCRE's UTF-8 support, or pre-encode/decode text to bytes. Note that upstream Hyperscan/Vectorscan has known bugs with `HS_FLAG_UTF8` for certain patterns.
Design your regex patterns to identify occurrences, and then use a separate, capture-group-capable regex engine on the identified regions if capture groups are essential.
Always provide a `match_event_handler` function if you intend to process matches. The handler function's return value can also control scanning termination.
Only use `HS_FLAG_SOM_LEFTMOST` when absolutely necessary, and be aware it may limit pattern complexity.
Upgrade to `hyperscan` version `0.8.2` or newer to ensure correct match offset handling for large data buffers.
Ensure `pip install hyperscan` completes without errors. If building from source, verify all C/C++ build prerequisites (CMake, C/C++ toolchain, Ragel) are met. For older library versions, ensure the system's Hyperscan library matches the expected version (e.g., `v0.1.5` needed Hyperscan `v4.x`, while `v0.2+` needs `v5.x`). Confirm your Python virtual environment is active.
If using pre-built wheels, try installing a more generic wheel if available, or ensure your CPU supports the instruction sets used. If building from source, set `CMAKE_ARGS="-DUSE_CPU_NATIVE=OFF"` during `pip install .` to disable CPU-native optimizations, or compile on the target machine.
Allocate a separate `hyperscan.Scratch` object for each concurrent scan operation or thread. Ensure each `db.scan()` or `stream.scan()` call receives its own dedicated `scratch` instance.
No dependency data recorded yet.