Python wrapper for MurmurHash (MurmurHash3), a set of fast and robust hash functions.
Project description
mmhash3
Fork of the original mmh3 library since it is unmaintained.
mmhash3 is a Python wrapper for MurmurHash (MurmurHash3), a set of fast and robust non-cryptographic hash functions invented by Austin Appleby.
Combined with probabilistic techniques like a Bloom filter, MinHash, and feature hashing, mmh3 allows you to develop high-performance systems in fields such as data mining, machine learning, and natural language processing.
How to use
Install:
pip install mmhash3 # for macOS, use "pip3 install mmhash3" and python3
Quickstart:
>>> import mmh3
>>> mmh3.hash("foo") # returns a 32-bit signed int
-156908512
>>> mmh3.hash("foo", 42) # uses 42 as a seed
-1322301282
>>> mmh3.hash("foo", signed=False) # returns a 32-bit unsigned int
4138058784
Other functions:
>>> mmh3.hash64("foo") # two 64 bit signed ints (by using the 128-bit algorithm as its backend)
(-2129773440516405919, 9128664383759220103)
>>> mmh3.hash64("foo", signed=False) # two 64 bit unsigned ints
(16316970633193145697, 9128664383759220103)
>>> mmh3.hash128("foo", 42) # 128 bit unsigned int
215966891540331383248189432718888555506
>>> mmh3.hash128("foo", 42, signed=True) # 128 bit signed int
-124315475380607080215185174712879655950
>>> mmh3.hash_bytes("foo") # 128 bit value as bytes
'aE\xf5\x01W\x86q\xe2\x87}\xba+\xe4\x87\xaf~'
>>> import numpy as np
>>> a = np.zeros(2 ** 32, dtype=np.int8)
>>> mmh3.hash_bytes(a)
b'V\x8f}\xad\x8eNM\xa84\x07FU\x9c\xc4\xcc\x8e'
Beware that hash64
returns two values, because it uses the 128-bit version of MurmurHash3 as its backend.
hash_from_buffer
hashes byte-likes without memory copying. The method is suitable when you hash a large memory-view such as numpy.ndarray
.
>>> mmh3.hash_from_buffer(numpy.random.rand(100))
-2137204694
>>> mmh3.hash_from_buffer(numpy.random.rand(100), signed=False)
3812874078
hash64
, hash128
, and hash_bytes
have the third argument for architecture optimization. Use True for x64 and False for x86 (default: True):
>>> mmh3.hash64("foo", 42, True)
(-840311307571801102, -6739155424061121879)
Changelog
3.0.0 (2021-02-23)
- Python wheels are now available, thanks to the power of cibuildwheel.
- Supported platforms are
manylinux1_x86_64
,manylinux2010_x86_64
,manylinux2014_aarch64
,win32
,win_amd64
,macosx_10_9_x86_64
, andmacosx_11_0_arm64
(Apple Silicon).
- Supported platforms are
- Add support for newer macOS environments. Thanks Matthew Honnibal!
- Drop support for Python 2.7, 3.3, 3.4, and 3.5.
- Add support for Python 3.7, 3.8, 3.9, 3.10 and 3.11
- Migrate Travis CI and AppVeyor to GitHub Actions.
2.5.1 (2017-10-31)
- Bug fix for
hash_bytes
. Thanks doozr!
2.5 (2017-10-28)
- Add
hash_from_buffer
. Thanks Dimitri Vorona! - Add a keyword argument
signed
.
2.4 (2017-05-27)
- Support seeds with 32-bit unsigned integers; thanks Alexander Maznev!
- Support 64-bit data (under 64-bit environments)
- Fix compile errors for Python 3.6 under Windows systems.
- Add unit testing and continuous integration with Travis CI and AppVeyor.
2.3.2 (2017-05-26)
- Relicensed from public domain to CC0-1.0.
2.3.1 (2015-06-07)
- Fix compile errors for gcc >=5.
2.3 (2013-12-08)
- Add
hash128
, which returns a 128-bit signed integer. - Fix a misplaced operator which could cause memory leak in a rare condition.
- Fix a malformed value to a Python/C API function which may cause runtime errors in recent Python 3.x versions.
The first two commits are from Derek Wilson. Thanks!
2.2 (2013-03-03)
- Improve portability to support systems with old gcc (version < 4.4) such as CentOS/RHEL 5.x. (Commit from Micha Gorelick. Thanks!)
2.1 (2013-02-25)
- Add
__version__
constant. Check if it exists when the following revision matters for your application. - Incorporate the revision r147, which includes robustness improvement and minor tweaks.
Beware that due to this revision, the result of 32-bit version of 2.1 is NOT the same as that of 2.0. E.g.,:
>>> mmh3.hash("foo") # in mmh3 2.0
-292180858
>>> mmh3.hash("foo") # in mmh3 2.1
-156908512
The results of hash64 and hash_bytes remain unchanged. Austin Appleby, the author of Murmurhash, ensured this revision was the final modification to MurmurHash3's results and any future changes would be to improve performance only.
License
Known Issues
Getting different results from other MurmurHash3-based libraries
By default, mmh3 returns signed values for 32-bit and 64-bit versions and unsigned values for hash128
, due to historical reasons. Please use the keyword argument signed
to obtain a desired result.
For compatibility with Google Guava (Java), see https://stackoverflow.com/questions/29932956/murmur3-hash-different-result-between-python-and-java-implementation
Unexpected results when given non 32-bit seeds
Version 2.4 changed the type of seeds from signed 32-bit int to unsigned 32-bit int. The resulting values with signed seeds still remain the same as before, as long as they are 32-bit.
>>> mmh3.hash("aaaa", -1756908916) # signed representation for 0x9747b28c
1519878282
>>> mmh3.hash("aaaa", 2538058380) # unsigned representation for 0x9747b28c
1519878282
Be careful so that these seeds do not exceed 32-bit. Unexpected results may happen with invalid values.
>>> mmh3.hash("foo", 2 ** 33)
-156908512
>>> mmh3.hash("foo", 2 ** 34)
-156908512
Authors
MurmurHash3 was originally developed by Austin Appleby and distributed under public domain.
Ported and modified for Python by Hajime Senuma.
See also
Tutorials
The following textbooks and tutorials are great sources to learn how to use mmh3 (and other hash algorithms in general) for high-performance computing.
- Chapter 11: Using Less Ram in Micha Gorelick and Ian Ozsvald. 2014. High Performance Python: Practical Performant Programming for Humans. O'Reilly Media. ISBN: 978-1-4493-6159-4.
- Duke University. Efficient storage of data in memory.
- Max Burstein. Creating a Simple Bloom Filter.
- Bugra Akyildiz. A Gentle Introduction to Bloom Filter.
Similar libraries
- https://github.com/wc-duck/pymmh3: mmh3 in pure python (Fredrik Kihlander and Swapnil Gusani)
- https://github.com/escherba/python-cityhash: Python bindings for CityHash (Eugene Scherba)
- https://github.com/veelion/python-farmhash: Python bindigs for FarmHash (Veelion Chong)
- https://github.com/escherba/python-metrohash: Python bindings for MetroHash (Eugene Scherba)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for mmhash3-3.0.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 832ea2e25717446b928094554df2bad4b9bb8777263d41a90663f35973f1a766 |
|
MD5 | 6f5d1c681a2c223912f83e7187371f65 |
|
BLAKE2b-256 | 743841628d4919db0a0eff53813705e53f866f341addb8af9b7df90dd8ee83a3 |
Hashes for mmhash3-3.0.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72c6f04fa530e880b3d415cfd4b9633986dab9352c4e1004c872433a0f5d6f1e |
|
MD5 | c4700e32b17191bf22a5c07ddc953472 |
|
BLAKE2b-256 | ca0f4cf1afa5ab16257ea0039fae5a7c978adb51397fa9b6a361af70652aebe5 |
Hashes for mmhash3-3.0.0-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 770e986240b19269bb0d13e8d5950e4a08e49366b15a1344f6065c79a3894b56 |
|
MD5 | 174b6cb952fb1fe97f50b992f43f864c |
|
BLAKE2b-256 | 2b383b865337d281793087b4f41bf4b501489269e50791245ae64af064971ef9 |
Hashes for mmhash3-3.0.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41e04c8b715d86f062e2d9c09be26c1368fae747ea7aa6bd986ad70592ec26e3 |
|
MD5 | aea02192044b37028097e706fb9299ca |
|
BLAKE2b-256 | 084945330ea0667b19690e21ff2bb30b14e382c484f6b7c544f4cb428f1172d7 |
Hashes for mmhash3-3.0.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b6bcf20429bd9639fcf121df21a85cc31030c7d5c2cd96bbbd4c9b1f6a14c60 |
|
MD5 | c3b618501023f62eea746403f3b95d27 |
|
BLAKE2b-256 | 482c13f0c4026652e5073ebb1a69d4047f73068b64ef0907f9674a3a91d364ac |
Hashes for mmhash3-3.0.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae60d93355b95e7e2a59329f8bd173b4c9d4c97f8f984b6eaa6506f51a7cf748 |
|
MD5 | 875c0476459d003fb076997fa4b10f06 |
|
BLAKE2b-256 | f9ac77bbe19b91087366e493c09cb4cf66027f51cab6df909a92e4075fd96092 |
Hashes for mmhash3-3.0.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c3c296403bff8f68243e31e3311b53150fcb563ff7cc0206b54b5781c15bc5d |
|
MD5 | 29c30cf4be250e41b9c3f1695ecd22ee |
|
BLAKE2b-256 | ad2dca6e5cf001f89f3a26ce2ca57052003943f0723f5171cb49727551c248a2 |
Hashes for mmhash3-3.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac9886aa5a03e4a44d328c6e84521eae3b02b1cb5c34af8067f2c9cbcc6f8f54 |
|
MD5 | 882d791fd8c4392e63094c54cf3ffecd |
|
BLAKE2b-256 | 85615e4a360af05f1f9fe661ae1f48a14653b09eb34cdef8639f3e4ec04706a1 |
Hashes for mmhash3-3.0.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb7c1440fc443371005c6f480693945cdbca63c7028d2f8db2a16637577a5c34 |
|
MD5 | 4d3093cf853fc2971a16b8d394feba8b |
|
BLAKE2b-256 | a1cec5f04b02ac4501c16515b87d46dc909f5db3e03bd553a9af07534868aa88 |
Hashes for mmhash3-3.0.0-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66b06c61ada31f19bd18cf0f1e1750a4786eee5db711e8a5f095a617d319972c |
|
MD5 | 2814e9c9bc447d8e437fa751c750eee9 |
|
BLAKE2b-256 | 9c4d5a15f9f67558687aa21ba9036339d43c6fb96ac69f1806ba68d66cca8df0 |
Hashes for mmhash3-3.0.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b1fedbb1aca1bcf36ffd541f07e258e1da23d305027735c498289789d580d77 |
|
MD5 | 3b3b25c19d78a6ba6414346e845577a5 |
|
BLAKE2b-256 | ca2604bc0de3db4f3d1cb132c1f56218b33ebf331b1e1d63880d1b17f350655c |
Hashes for mmhash3-3.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33cd3f7cc953a18d039ceed6a5eb0c1d1f6b428987908cd70d7552590a545cd0 |
|
MD5 | 93f2adfe713f20628dd74aae295e79ea |
|
BLAKE2b-256 | 2e71ed9eedb649fce538aef7eb139e26b1e327857f56927cca18bc2a911080f1 |
Hashes for mmhash3-3.0.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 010b2be712403141e0a44271c98a5d05c4fb86f194f00478e956891192918e3f |
|
MD5 | b4a1fd3a0510487c823cbcc3088ba45f |
|
BLAKE2b-256 | a50cbf078981289e7831b9c110f7a10a524b93d6ef52bc6590b7f56db544d497 |
Hashes for mmhash3-3.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0362c52b7d5696cfe0ed69ed50abf2e55661a602d547aa1865ebae5d62dcda93 |
|
MD5 | 5904d3ec271de7aaf1123f905b3b7527 |
|
BLAKE2b-256 | bb00120c05c460260bfa200d8bb7d8abe8b5d674d4255389f36d6b9f28d42048 |
Hashes for mmhash3-3.0.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b2981eaa7d4808abe08b27759e42e14faafef2a47cd701ee258ef7e11962b4c |
|
MD5 | ec7cbbe075939fe7a41e00cd5ab1094d |
|
BLAKE2b-256 | cdbab418dbbd7bc8d8830432166876b6554a7a97d015531290af42545ceeb0ac |
Hashes for mmhash3-3.0.0-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2c1fbec97e97cebc5ec0442cae5ebc443d1b823f7f76466284a64b6416f3915 |
|
MD5 | ee129a381c612d6c700b204627589737 |
|
BLAKE2b-256 | 9763e40dfac8df9aa72496d2b9095b8db02487cdf97f589032b23f6809f1761e |
Hashes for mmhash3-3.0.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 245a432e0f71abd39404b395fd571742ae4995ac15400a595cbe48611972ba5b |
|
MD5 | 49a3dec71078cbae5422b1a8d5623852 |
|
BLAKE2b-256 | 39219f6b47b81e8b2f621f8f1725b0865cacff087fc7178d7d082d51f966ce78 |
Hashes for mmhash3-3.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 927e9ac7360446dcb5c6aea4f5cc23259776c8c7151d085e457d47a101bb7ecc |
|
MD5 | c24a3f67379f6cf5776e232066a88533 |
|
BLAKE2b-256 | 824365f36499daffd4877c87eb07088dd0ef265398ba7894917a80ed328e639d |
Hashes for mmhash3-3.0.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a35171e65f179c46cd60cec0fc4b09b3c5b7296dd069adee6836673e44676367 |
|
MD5 | a10a9d132920bf5727e4d29a35498caf |
|
BLAKE2b-256 | 62f58cd11494d39fe62a181f0a08c09d5833cbc5213ef39fd527a816e6e53db6 |
Hashes for mmhash3-3.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 162004a24e6bceb4faadf6faf7b94f4126997882751a91fafa349556c6f56a48 |
|
MD5 | 71290e9b7fed361128429dc4b680d766 |
|
BLAKE2b-256 | 080f29dd427b0f188d2fb6aaec82877aa319797c03593c9b581fe0ca71f7e1ae |
Hashes for mmhash3-3.0.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ede07a223eefca8a293abfec115425208cfd7be0c7ff3129e4d618aedd171b4 |
|
MD5 | b3f2434876970a0673ae6a9a598d7b8a |
|
BLAKE2b-256 | f8db01a490a7f66c3268af402517cb03a32f4bbebcc4c9a9663e27482aaba1eb |
Hashes for mmhash3-3.0.0-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e03fcea90e479097ab18fb3f13dde368434f7b97d63eec551126f284243aedf4 |
|
MD5 | bf71088aeebe25e251c4339432bdfd5e |
|
BLAKE2b-256 | 79a51ff03d1d35d4b013f0728b45ba864ffb17d2aa79fd98ebbe6a0064a14a00 |
Hashes for mmhash3-3.0.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3af483f8d60e828bf98a7c554103e88e5195406a4957b29736af40aa84ffe80b |
|
MD5 | f92c751883242270e8272f65c3a41356 |
|
BLAKE2b-256 | a5a6fdfa4d409d19844c4e2527918624bbe3fede5ecd05616cd65e8270ff3a46 |
Hashes for mmhash3-3.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acc5aaa3547e8c3a60298486d647a1982b079e18dfd16dfe3fac7f99c4c059e9 |
|
MD5 | 6fc924e3013e10ec71b33e525f201d94 |
|
BLAKE2b-256 | 2952264ae66c264e80c4baa064c395dd091cb59262cfcae649f41f056dd97603 |
Hashes for mmhash3-3.0.0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d7c159c6aa2fd58b2e8a9204ada8fdecf87de31f2673a46d0f863719a5b5390 |
|
MD5 | cbb97e04b9decb491403a32cacb49a28 |
|
BLAKE2b-256 | 16a9c782722572470082066741b283c622fbdaaa00f9547840ad7fc77f7b64f7 |