mmh3 (MurmurHash3)

5.2.1 · active · verified Sat Mar 28

mmh3 is a Python extension for MurmurHash (MurmurHash3), a collection of fast and robust non-cryptographic hash functions invented by Austin Appleby. Currently at version 5.2.1, it is actively maintained with updates for new Python versions, performance enhancements, and extended platform support for applications in data mining, machine learning, and natural language processing.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the most common `mmh3` hash functions: `hash()` for 32-bit results (signed or unsigned), `hash_bytes()` for 128-bit results as bytes, and `hash64()` for 64-bit results as a tuple of two integers. The `seed` and `signed` arguments are crucial for consistent results.

import mmh3

# Basic 32-bit hash, returns a signed integer
hash_value = mmh3.hash("foo")
print(f"32-bit signed hash of 'foo': {hash_value}")

# 32-bit hash with a seed
hash_with_seed = mmh3.hash("foo", seed=42)
print(f"32-bit signed hash of 'foo' with seed 42: {hash_with_seed}")

# 32-bit unsigned hash
unsigned_hash = mmh3.hash("foo", signed=False)
print(f"32-bit unsigned hash of 'foo': {unsigned_hash}")

# 128-bit hash as a string of bytes
hash_as_bytes = mmh3.hash_bytes("foo")
print(f"128-bit hash of 'foo' as bytes: {hash_as_bytes}")

# 64-bit hash (returns a tuple of two 64-bit signed integers)
hash64_result = mmh3.hash64("foo")
print(f"64-bit hash of 'foo': {hash64_result}")

view raw JSON →