The stringzilla module covers single-string search, slicing, splitting, trimming, translation, hashing, checksums, sorting, sampling, random generation, UTF-8 segmentation, Unicode case-folding, Unicode normalization, escaping, and dumping JSON and CSV.
The same module also carries the batch engines, each preparing one set of queries once and scoring it against many collections of candidates, on the host or on a CUDA, ROCm or Metal device.
Every call runs the best kernel of the capabilities it is given, by default every CPU capability, which the library clamps to sz.cpu_capabilities_enabled(), and the batch engines release the GIL around native work.
The module is also marked safe for free-threaded Py_GIL_DISABLED CPython builds.
Throughout this document the stringzilla package is imported as sz, and NumPy as np:
import stringzilla as sz
import numpy as npAlmost every sz operation is available both as a method on a String object and as a module-level function that accepts a str, bytes, bytearray, or String.
For example sz.String("hello").find("l") and sz.find("hello", "l") are equivalent.
Topics
| Installation | |
|---|---|
| Types77 | The stringzilla module exposes String, Strings, and File, the incremental hashers Hasher, Sha256 and Sha256s, the batch engines LevenshteinEngine, OverlapEngine and SubstringsEngine, plus a family of UTF-8 iterator types. |
| Searching and Counting27 | All search methods accept optional start and end indices that bound the search window; start defaults to 0 and end to the string length. |
| Comparison and Equality1 | |
| Splitting and Partitioning12 | maxsplit caps the number of separators consumed, so 0 leaves the text whole, while a negative value or the default means unlimited. |
| Trimming and Translating7 | With no argument, the default character set is ASCII whitespace. |
| Unicode Segmentation22 | String, along with the matching module-level functions, exposes lazy iterators over Unicode boundaries. |
| Case Folding and Normalization7 | |
| Hashing and Checksums41 | hash, hashmultiseed, bytesum, and sha256 are also available as String methods. |
| Sorting and Sets4 | These operate on a Strings collection and return new collections or tuples of numbers, leaving the original unchanged. |
| Memory Operations1 | |
| Edit Distances3 | Three engines prepare one set of queries once and score it against as many collections of candidates as a caller has. |
| Fingerprints3 | |
| Runtime Dispatch12 | StringZilla detects the running CPU's SIMD features and routes every kernel to the fastest capability both the CPU and this build have, without recompilation. |