clickhouse-cityhash provides Python bindings for a specific, older version of Google's CityHash algorithm (v1.0.2). This library is primarily used to ensure compatibility with ClickHouse servers, which internally use this particular CityHash version for various hashing operations, including data in its protocol. It is a fork of the broader `python-cityhash` library, specifically tailored for the ClickHouse ecosystem. The current version is 1.0.2.5, and it receives updates for compatibility and bug fixes.
pip install clickhouse-cityhashVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use the `CityHash64` and `CityHash128` functions. It highlights the crucial step of encoding Python strings to bytes before hashing, as CityHash operates on byte strings. It also shows how to hash integers consistently by converting them to a fixed-size byte representation.
Always verify which CityHash version (and thus hash output) is expected by your downstream system. For general non-ClickHouse use cases, consider `python-cityhash` or `farmhash` which implement newer algorithms. Ensure consistent hashing across systems if comparing hash values.
For cryptographic security requirements, use standard library `hashlib` functions (e.g., SHA256, Blake2b).
Always explicitly encode strings to bytes using a consistent encoding (e.g., `my_string.encode('utf-8')`) before passing them to hashing functions.For stream processing or incremental hashing needs, use a library that explicitly supports this feature (e.g., `MetroHash` or `xxHash`).
Convert integers to a fixed-size byte sequence: `integer_value.to_bytes(8, 'big')` (for 64-bit hash, adjust size and endianness as needed).
No dependency data recorded yet.