Python wrapper for MurmurHash (MurmurHash3), a set of fast and robust hash functions.
Project description
mmh3
mmh3 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.
Another common use of mmh3 is to calculate favicon hashes used by Shodan, the world's first IoT search engine.
How to use
Install:
pip install mmh3 # for macOS, use "pip3 install mmh3" 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.1.0 (2023-03-24)
- Add support for Python 3.10 and 3.11. Thanks wouter bolsterlee and Dušan Nikolić!
- Drop support for Python 3.6; remove legacy code for Python 2.x at the source code level.
- Add support for 32-bit architectures such as
i686
andarmv7l
. From now on,hash
andhash_from_buffer
on these architectures will generate the same hash values as those on other environments. Thanks Danil Shein! - In relation to the above,
manylinux2014_i686
wheels are now available. - Support for hashing huge data (>16GB). Thanks arieleizenberg!
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, and 3.9.
- Migrate Travis CI and AppVeyor to GitHub Actions.
2.5.1 (2017-10-31)
- Bugfix for
hash_bytes
. Thanks doozr!
See CHANGELOG.md for the complete changelog.
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 (High-Performance Computing)
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.
- 2nd edition of the above (2020). ISBN: 978-1492055020.
- Max Burstein. February 2, 2013. Creating a Simple Bloom Filter.
- Duke University. April 14, 2016. Efficient storage of data in memory.
- Bugra Akyildiz. August 24, 2016. A Gentle Introduction to Bloom Filter. KDnuggets.
Tutorials (Internet of Things)
Shodan, the world's first IoT search engine, uses MurmurHash3 hash values for favicons (icons associated with web pages). ZoomEye follows Shodan's convention. Calculating these values with mmh3 is useful for OSINT and cybersecurity activities.
- Jan Kopriva. April 19, 2021. Hunting phishing websites with favicon hashes. SANS Internet Storm Center.
- Nikhil Panwar. May 2, 2022. Using Favicons to Discover Phishing & Brand Impersonation Websites. Bolster.
- Faradaysec. July 25, 2022. Understanding Spring4Shell: How used is it?. Faraday Security.
- Debjeet. August 2, 2022. How To Find Assets Using Favicon Hashes. Payatu.
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)
- https://github.com/ifduyue/python-xxhash: Python bindings for xxHash (Yue Du)
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 mmh3-3.1.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5edb5ac882c04aff8a2a18ae8b74a0c339ac9b83db9820d8456f518bb558e0d8 |
|
MD5 | fa25a8334a76d9fc956e7b48441aff23 |
|
BLAKE2b-256 | a9fb61c2b90f05b6496c3ac85120f39447d02b3448f310181225a947ae358aad |
Hashes for mmh3-3.1.0-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a886d9ce995a4bdfd7a600ddf61b9015cccbc73c50b898f8ff3c78af24384710 |
|
MD5 | 8f2ac9d0d2d4e99a98c4b6b36fb7a0e2 |
|
BLAKE2b-256 | 268e8520b7492b9c2851292cc30a52c70aab5d455eed271edeea71f5169373b7 |
Hashes for mmh3-3.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 524e29dfe66499695f9496edcfc96782d130aabd6ba12c50c72372163cc6f3ea |
|
MD5 | f3c761b11375395ecac4d2596e460665 |
|
BLAKE2b-256 | 8fe9442c2b324862cc43793f95cbe782f3ee3a2c437dba1ebc1c40fe8ccb053b |
Hashes for mmh3-3.1.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a4d471eb75df8320061ab3b8cbe11c970be9f116b01bc2222ebda9c0a777520 |
|
MD5 | 2c33145c3a83ea58bceab7372c626168 |
|
BLAKE2b-256 | 407c29c361b77f94b0310332789e70aae43a914c6203b167b55e08f7ebf3e954 |
Hashes for mmh3-3.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66bdb06a03074e65e614da1aa199b1d16c90608bec9d8fc3faa81d887ffe93cc |
|
MD5 | ea34b3afc75bef257482e3bae0714821 |
|
BLAKE2b-256 | 54a93020f3f9e93c060279c784ad2d215bfcb456c2064a01bb06911d5b82211d |
Hashes for mmh3-3.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0109320f7e0e262123ff4f1acd06acfbc8b3bf19cc13d98c0bc369264430aaeb |
|
MD5 | d3ba722c53a9ed8893792fe5cb972871 |
|
BLAKE2b-256 | bf51b705297e731d663cf3206c6a3c277468730137d46446ad09582be15bfa95 |
Hashes for mmh3-3.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c271472325b70d64a4fbb1f2e964ca5b093ac10258e1390f8408890b065868fe |
|
MD5 | da8cbac840a55b14fff09a07d1c074f1 |
|
BLAKE2b-256 | 3d702ebc0fd1c05c26f008709f27974a12eefdf6c26d927212764f023460eeb8 |
Hashes for mmh3-3.1.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29e878e7467a000f34ab68c218ad7ad81312c0a94bc10df3c50a48bcad39dd83 |
|
MD5 | 45cc62b0ef2c22225cb456bde125f4b4 |
|
BLAKE2b-256 | 777d2ea96011bf1219b2f83c54d861bddfd6858c336ec8104aebee678e547fb8 |
Hashes for mmh3-3.1.0-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8ed7a2361718795a1b519a08d05f44947a20b27e202b53946561a00dde669c1 |
|
MD5 | 9798fdd51359d01bc447950929e13f43 |
|
BLAKE2b-256 | d28640aa4151c0d9b61f26dd300ac034e39e6b780665a5593b28fe672d90deee |
Hashes for mmh3-3.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e751f5433417a21c2060b0efa1afc67cfbe29977c867336148c8edb086fae70 |
|
MD5 | d10154de8093b0cb9ed0329de7e500fb |
|
BLAKE2b-256 | 287d4eaa4e25431a73c0de903f27004a8dc1655b3d6cb0b1cf525d0a4dcc9d7e |
Hashes for mmh3-3.1.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1230930fbf2faec4ddf5b76d0768ae73c102de173c301962bdd468177275adf9 |
|
MD5 | 38921a89b440aa8ecd0cbad822f9b65e |
|
BLAKE2b-256 | abbd8f30e50f16a1ac486c219e2505484a5d53cf6e138b2868cafddb173b890d |
Hashes for mmh3-3.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdb863b89c1b34e3681d4a3b15d424734940eb8036f3457cb35ef34fb87a503c |
|
MD5 | f8243670a6d67fe9c0623fe5dd682f75 |
|
BLAKE2b-256 | 1ea1afaeb2bb0dfeea9e33ac783283229df1a41418f4367d3ad09b66371ee9b9 |
Hashes for mmh3-3.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04ac865319e5b36148a4b6cdf27f8bda091c47c4ab7b355d7f353dfc2b8a3cce |
|
MD5 | 5c47208cd89f15d2bb0e4f2770314572 |
|
BLAKE2b-256 | 9266bde2e801bc662ab497b8c15507c48bb343907734a6f9e16f56339e154879 |
Hashes for mmh3-3.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16ee043b1bac040b4324b8baee39df9fdca480a560a6d74f2eef66a5009a234e |
|
MD5 | f75eafe8a936f47589e142c633efd7c9 |
|
BLAKE2b-256 | d054e1a7d2fc78a4b13b6901b74d085ec2c80cf88524b872e5e2bdb24971b962 |
Hashes for mmh3-3.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03e04b3480e71828f48d17653451a3286555f0534942cb6ba93065b10ad5f9dc |
|
MD5 | d8bdd72e2e51ee56cb844a98cb4c9d1f |
|
BLAKE2b-256 | f69baa1b12c54d3f345f750fe72f9dbe9f417dcc5417b168c1131b20d63dc7f3 |
Hashes for mmh3-3.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f906833753b4ddcb690c2c1b74e77725868bc3a8b762b7a77737d08be89ae41d |
|
MD5 | 73744e87883f9460242c6428236e2d3a |
|
BLAKE2b-256 | e954b4fad81ed89cea0f158ae13c51c183073b27c92cda1fa3f04a543ea2634a |
Hashes for mmh3-3.1.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d2aa4d422c7c088bbc5d367b45431268ebe6742a0a64eade93fab708e25757c |
|
MD5 | f982146b8de703ba5d6be620d98ffac7 |
|
BLAKE2b-256 | e556918a132e9e7c6fa83df3ecfb56b7f23e01f96160f3295a2881f495d2015c |
Hashes for mmh3-3.1.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72b5685832a7a87a55ebff481794bc410484d7bd4c5e80dae4d8ac50739138ef |
|
MD5 | 2a849f1d26939660a35ec511ea0e359c |
|
BLAKE2b-256 | 68f75f652712d52e7ee4b8c2cf9923b71e171d6cf1925959f7fa5fe74b392d6d |
Hashes for mmh3-3.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ced92a0e285a9111413541c197b0c17d280cee96f7c564b258caf5de5ab8ee01 |
|
MD5 | 91b22b597d5e25c14837ebeff2d96408 |
|
BLAKE2b-256 | 9a802ac8ddf8736b8eafd2cbf4712e26b1a23e3b094cdbfe9444d9c9b067317b |
Hashes for mmh3-3.1.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b22832d565128be83d69f5d49243bb567840a954df377c9f5b26646a6eec39b |
|
MD5 | b05bf5443f144554b652a959cfdbe4e6 |
|
BLAKE2b-256 | 524da0946cf099ca5a90e092f128c165d3039b1d585f7c2e0a1ea9cc6e89f796 |
Hashes for mmh3-3.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbc2917df568aeb86ec5aa863bfb20fa14e01039cbdce7650efbabc30960df49 |
|
MD5 | 780109b46cf06a95ee504402315d5a31 |
|
BLAKE2b-256 | c7f72d9fec77309589d3dec5d70b5cc902638ad0ce9b00a667e1ac3ea0698593 |
Hashes for mmh3-3.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87cdbc6e70099ad92f17a28b4054ffb1938657e8fb7c1e4e03b194a1b4683fd6 |
|
MD5 | 354271f57747d7dcf5ba0cd1d53b2aa0 |
|
BLAKE2b-256 | 703ae307d98c5bed155e7b4074a6d934f69cfd55561927c43d1d4b0a62a24a92 |
Hashes for mmh3-3.1.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e6eba88e5c1a2778f3de00a9502e3c214ebb757337ece2a7d71e060d188ddfa |
|
MD5 | b10da2587bb658351c0fa24cd79823e6 |
|
BLAKE2b-256 | 504d12127343b12373820ff13071656bde3bb2e90cde0eca00ea090e04206001 |
Hashes for mmh3-3.1.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dd81321d14f62aa3711f30533c85a74dc7596e0fee63c8eddd375bc92ab846c |
|
MD5 | cf794597f6d06fc565aad219c5bd4c56 |
|
BLAKE2b-256 | 8853f90b91db41bf8c53fdd443b807855d0b9138069d96f8f17d10d3864a24ba |
Hashes for mmh3-3.1.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf4f3f20a8b8405c08b13bc9e4ac33bf55129b50b535cd07ce1891b7f96326ac |
|
MD5 | 325e02a7d2596cc5a666a5f20ef14c9d |
|
BLAKE2b-256 | 46868fb02abac4e5e2f2647b3cedc1aa2926b25c735a4811041ab441088f4172 |
Hashes for mmh3-3.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9977fb81f8c66f4eee8439734a18dba7826fe78723d15ab53f42db977005be0f |
|
MD5 | bc234ab553fc43cce812ee183ee35dd2 |
|
BLAKE2b-256 | 13bf0da337119c81cdb913893e8cb5a48cba22973b3f850fa8079c04ec60573f |
Hashes for mmh3-3.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 731d37f089b6c212fab1beea24e673161146eb6c76baf9ac074a3424d1172d41 |
|
MD5 | 1c5169dca80b921bc722e2a59323c216 |
|
BLAKE2b-256 | aeba85543a2dfac95acc050379279de7f73ce50cf1d15f27189db29391eb31ef |
Hashes for mmh3-3.1.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd781b115cf649811cfde76368c33d2e553b6f88bb41131c314f30d8e65e9d24 |
|
MD5 | 0ea661f30e02be1a60261df1d3e50997 |
|
BLAKE2b-256 | caf670a232d0c85ac51834727d154e8217d31256a72e074ac50b418f000bb025 |
Hashes for mmh3-3.1.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d0936a82438e340636a11b9a938378870fc1c7a139632dac09a9a9277351704 |
|
MD5 | f5cef7ccd147be251bb08a5fdd8e088d |
|
BLAKE2b-256 | 6f3d91fe57da658900393663ca94d1e9cf79d08daaa3cabcc8187230b97d477b |
Hashes for mmh3-3.1.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f48bb0a867077acc1f548591ad49506389f36d18f36dccd10becf071e5cbdda4 |
|
MD5 | 6f50a2885af666bac75ee617822bc978 |
|
BLAKE2b-256 | f5547b1e799669197fd487831fa26fa242a21d50da4f7124ed497d4b0f4cc48a |
Hashes for mmh3-3.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 190fd10981fbd6c67e10ce3b56bcc021562c0df0fee2e2864347d64e65b1783a |
|
MD5 | 7adbf989b83c1d3012bf11616fcfb00c |
|
BLAKE2b-256 | 3f671639b82153e32a1a8cd930d61214d2af527efd4db0f07ac2d07691238bb4 |