spookyhash
raw JSON → 2.1.1 verified Sat May 09 auth: no python
A Python wrapper for SpookyHash version 2, a fast non-cryptographic hash function. Current version 2.1.1 provides hash128 and hash64 algorithms with an API similar to hashlib. Release cadence is low; last update July 2024.
pip install spookyhash Common errors
error AttributeError: module 'spookyhash' has no attribute 'spookyhash128' ↓
cause Old API from version 1.x imports incorrectly.
fix
Use from spookyhash import hash128 (or hash64).
error TypeError: a bytes-like object is required, not 'str' ↓
cause Passing a string instead of bytes to hash functions.
fix
Encode the string: hash128(b"text") or hash128("text".encode()).
Warnings
breaking In version 2.1.0, Hash.hexdigest() changed from returning bytes to returning str, aligning with hashlib. Code expecting bytes will break. ↓
fix Update code to expect str from hexdigest(), or use .digest() for bytes.
gotcha spookyhash is non-cryptographic; do not use for security purposes like password hashing or digital signatures. ↓
fix Use hashlib or cryptography for secure hashing.
deprecated The older spookyhash package (version 1.x) had a different API. Ensure you are using version 2.x and importing from 'spookyhash'. ↓
fix Upgrade to 2.1.1 and follow the current API.
Imports
- hash128
from spookyhash import hash128 - hash64
from spookyhash import hash64 - Hash
from spookyhash import Hash
Quickstart
from spookyhash import hash128, hash64
# Simple hashing
print(hash128(b"hello world"))
print(hash64(b"hello world"))
# Incremental hashing (like hashlib)
from spookyhash import Hash
h = Hash()
h.update(b"hello")
h.update(b" world")
print(h.hexdigest())