MurmurHash

1.0.15 · active · verified Sun Mar 29

MurmurHash is a fast, non-cryptographic hash function library, primarily used for tasks like hash table indexing, data deduplication, and probabilistic data structures. This Python library provides efficient Cython bindings for MurmurHash, offering various 32-bit and 128-bit hash variants. It is actively maintained with frequent updates to support new Python versions and architectures.

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of `murmurhash.mrmr.hash`, `hash64`, and `hash128` functions with string and bytes input, and explicit seed values. Strings are UTF-8 encoded by default.

import murmurhash.mrmr

# Hash a string (UTF-8 encoded by default)
text_hash = murmurhash.mrmr.hash('hello world', seed=42)
print(f"32-bit hash for 'hello world': {text_hash}")

# Hash bytes
bytes_hash = murmurhash.mrmr.hash(b'hello world', seed=42)
print(f"32-bit hash for b'hello world': {bytes_hash}")

# Get a 64-bit hash
hash_64 = murmurhash.mrmr.hash64('another example', seed=0)
print(f"64-bit hash: {hash_64}")

# Get a 128-bit hash (returns a tuple of two integers)
hash_128 = murmurhash.mrmr.hash128('long string data', seed=12345)
print(f"128-bit hash: {hash_128}")

# Example with environment variable for seed (not typical for hash, but for auth template)
# import os
# seed_from_env = int(os.environ.get('MURMURHASH_SEED', '0'))
# env_hash = murmurhash.mrmr.hash('secure_data', seed=seed_from_env)
# print(f"Hash with env seed: {env_hash}")

view raw JSON →