mmhash3 (MurmurHash3)
mmhash3 is a Python wrapper for MurmurHash (MurmurHash3), a collection of fast and robust non-cryptographic hash functions. This specific library (version 3.0.1, last updated Oct 2022) is a fork of the original 'mmh3' library, which was considered unmaintained at the time of its creation. For a more actively developed and current version of a MurmurHash3 Python wrapper, users often look to the 'mmh3' package (pypi.org/project/mmh3).
Warnings
- gotcha The library is installed via `pip install mmhash3`, but the Python module to import is `mmh3`. Importing `mmhash3` will fail.
- breaking Results of 32-bit `mmh3.hash()` changed in version 2.1 (prior to 3.0.1). If your application relies on specific hash values from very old `mmh3` versions (pre-2.1), the results from `mmhash3` (v3.0.1) will differ.
- gotcha By default, `mmh3.hash()` and `mmh3.hash64()` return signed integers, while `mmh3.hash128()` returns an unsigned integer. This can lead to different results compared to other MurmurHash3 implementations that might default to unsigned values. The `mmh3.hash64()` function also returns two 64-bit values as a tuple.
- gotcha The behavior of seed values changed around version 2.4 (prior to 3.0.1), shifting from signed to unsigned 32-bit integers. While existing 32-bit signed seeds *should* yield the same results, using non-32-bit or intentionally negative seeds without careful consideration may lead to unexpected results or compatibility issues.
- deprecated This `mmhash3` package (version 3.0.1) is a fork of an older, unmaintained `mmh3` library. For active development, newer Python versions support, and potential performance improvements, consider using the actively maintained `mmh3` package (github.com/hajimes/mmh3, pypi.org/project/mmh3) which is currently at version 5.x.x.
Install
-
pip install mmhash3
Imports
- hash
import mmh3 mmh3.hash('your_string')
Quickstart
import mmh3
# Hash a string to a 32-bit signed integer
hash_value_32_bit = mmh3.hash("hello world")
print(f"32-bit hash: {hash_value_32_bit}")
# Hash with a seed
hash_value_seeded = mmh3.hash("hello world", 42)
print(f"32-bit hash with seed 42: {hash_value_seeded}")
# Get a 32-bit unsigned integer hash
hash_value_unsigned = mmh3.hash("hello world", signed=False)
print(f"32-bit unsigned hash: {hash_value_unsigned}")
# Get a 128-bit hash as a single unsigned integer
hash_value_128_bit = mmh3.hash128("hello world", 0)
print(f"128-bit hash: {hash_value_128_bit}")