TLSH (Trend Micro Locality Sensitive Hashing) is a fuzzy hashing algorithm for similarity comparison of binary data. The py-tlsh package provides a C++ Python extension for computing and comparing TLSH hashes. Current version 4.12.1 (but a major v5.0.0 exists; see warnings). Release cadence is irregular.
pip install py-tlshVerified import paths — ran on the pinned version, not inferred.
Basic usage: hash creation, comparison, and validation.
Use v4.12.1 (the latest PyPI release) unless you explicitly need v5 features. If using v5, be aware that all hashes will start with 'T1' and you may need to update storage/comparison logic.
If you need to ensure forward compatibility, consider stripping or handling the 'T1' prefix. For now, stick with v4.12.1 if you want to avoid breaking changes.
Use `tlsh.diff(hash1, hash2)` and interpret 0 as identical. For a similarity metric, you can invert the score (e.g., similarity = max(0, 100 - diff)) but note that the maximum difference is not fixed at 100.
Pass bytes: `tlsh.hash(b'hello')` or `tlsh.hash('hello'.encode('utf-8'))`.Install a C++ compiler (e.g., 'build-essential' on Ubuntu, Xcode on macOS, Visual Studio Build Tools on Windows). For Windows, consider using the unofficial Windows binary wheels from Christoph Gohlke or install via conda.
Encode the string to bytes: `tlsh.hash('hello'.encode('utf-8'))`Install via `pip install py-tlsh`. If that fails, ensure you have a C++ compiler (build-essential on Linux, Xcode command line tools on macOS).
Ensure the hash is exactly 70 hex characters (v4.x) or starts with 'T1' and is 72 characters (v5.x). Use `tlsh.is_valid(hash)` to check.
Reinstall py-tlsh via pip (it bundles the C extension). If using a custom build, set LD_LIBRARY_PATH or install the library system-wide.
No dependency data recorded yet.