Google FarmHash Bindings for Python

0.4.0 · active · verified Sun Apr 12

Pyfarmhash provides fast Python bindings for Google's FarmHash, a non-cryptographic hashing algorithm optimized for large datasets. It is currently at version 0.4.0 and sees active maintenance, with the latest release on August 27, 2024.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic usage of `pyfarmhash` for 32-bit and 64-bit hashing, including using seeds and the critical distinction between string and byte string inputs for different function types.

import farmhash

# Hashing a standard string (utf-8 encoded by default for hash functions)
text_input = 'Hello, FarmHash!'
hash_value_64 = farmhash.hash64(text_input)
hash_value_32 = farmhash.hash32(text_input)
print(f"Hash64 for '{text_input}': {hash_value_64}")
print(f"Hash32 for '{text_input}': {hash_value_32}")

# Hashing a byte string (required for fingerprint functions)
bytes_input = b'Another test string'
fingerprint_64 = farmhash.fingerprint64(bytes_input)
fingerprint_32 = farmhash.fingerprint32(bytes_input)
print(f"Fingerprint64 for '{bytes_input.decode()}': {fingerprint_64}")
print(f"Fingerprint32 for '{bytes_input.decode()}': {fingerprint_32}")

# Hashing with a seed
seeded_hash = farmhash.hash64withseed(text_input, 12345)
print(f"Seeded Hash64 for '{text_input}' with seed 12345: {seeded_hash}")

view raw JSON →