$ show darvid/python-hyperscan
python-hyperscan is a CPython extension providing Python bindings for Vectorscan (a fork of Intel's Hyperscan), a high-performance multiple regex matching library. The library enables efficient pattern matching with statically linked binaries and cross-platform support. It exposes most of the Hyperscan C API through Python classes including Database for pattern compilation, Scan for text scanning, Stream for streaming processing, and Scratch for thread-safe scratch space management. The implementation features proper buffer protocol support, sophisticated GIL handling for both traditional and free-threaded Python models, and careful resource management. The build system uses scikit-build-core with CMake to statically link Hyperscan/Vectorscan along with dependencies like PCRE and Boost, producing binary wheels for multiple platforms.
The LLM identified 2 files worth highlighting for reuse:
Implements sophisticated locking mechanism that works with both traditional Python's GIL and free-threaded Python (PEP 703). Uses conditional compilation to provide minimal-overhead locking when GIL is present and proper mutex locking when GIL is disabled. This demonstrates forward-thinking compatibility work that allows the extension to benefit from Python's threading improvements without sacrificing performance on traditional builds.
Properly implements Python's buffer protocol (PEP 3118) in both regular and vectored scanning modes. Uses PyObject_GetBuffer and PyBuffer_Release to work directly with memoryview, bytearray, and other buffer-like objects without unnecessary data copying. This improves performance and usability by accepting a wide range of input types while maintaining zero-copy semantics where possible.