{"id":6399,"library":"murmurhash2","title":"Murmurhash2","description":"Murmurhash2 is a Python library providing fast, non-cryptographic hash functions, specifically bindings for the MurmurHash2 and MurmurHash3 algorithms. It is designed for high performance in applications such as hash tables, caching, and data distribution, rather than for security-sensitive use cases. The current version, 0.2.10, was last released in February 2022 and supports Python 3.6+ environments. The project appears to be in a maintenance status with infrequent updates.","status":"maintenance","version":"0.2.10","language":"en","source_language":"en","source_url":"https://github.com/messense/murmurhash2-py","tags":["hashing","murmurhash","non-cryptographic","performance","utility","hashdos"],"install":[{"cmd":"pip install murmurhash2","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"Imports the MurmurHash2 function.","symbol":"murmurhash2","correct":"from murmurhash2 import murmurhash2"},{"note":"Imports the MurmurHash3 function, also provided by this library.","symbol":"murmurhash3","correct":"from murmurhash2 import murmurhash3"}],"quickstart":{"code":"from murmurhash2 import murmurhash2, murmurhash3\n\nSEED = 3242157231  # A common seed value, can be any integer\ndata_to_hash = b'Hello, MurmurHash!' # Input must be bytes\n\nhash_value_2 = murmurhash2(data_to_hash, SEED)\nhash_value_3 = murmurhash3(data_to_hash, SEED)\n\nprint(f\"MurmurHash2 of '{data_to_hash.decode()}' with seed {SEED}: {hash_value_2}\")\nprint(f\"MurmurHash3 of '{data_to_hash.decode()}' with seed {SEED}: {hash_value_3}\")","lang":"python","description":"Demonstrates how to import and use both `murmurhash2` and `murmurhash3` functions. Input data must be provided as bytes."},"warnings":[{"fix":"For security-sensitive applications, use cryptographic hash functions like `hashlib.sha256`.","message":"MurmurHash2 and MurmurHash3 are non-cryptographic hash functions. They are explicitly vulnerable to collision attacks (HashDoS) and must NOT be used for security-sensitive applications such as password hashing, digital signatures, or any context where an attacker can control input data.","severity":"breaking","affected_versions":"All versions"},{"fix":"Always encode string inputs to bytes explicitly, e.g., `my_string.encode('utf-8')`.","message":"The hash functions expect byte input. Passing a standard Python string (`str`) directly will result in a `TypeError` or unexpected behavior if the library attempts implicit conversion, which may not be platform-consistent.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure consistent byte representation of input data, especially when hashing data structures or integers that might have different endianness on different systems. Test cross-platform consistency if required.","message":"Due to its low-level C implementation, MurmurHash2 can be sensitive to endianness and data alignment across different platforms or when byte ordering is not strictly controlled, potentially leading to inconsistent hash values for the same logical input if the byte representation varies.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider using `murmurhash3` instead of `murmurhash2` for new implementations unless specific compatibility with MurmurHash2 is required.","message":"MurmurHash2 is an older algorithm. MurmurHash3, which is also provided by this library, is the more current version and often recommended over MurmurHash2 for improved distribution and performance characteristics.","severity":"deprecated","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}