Registry / serialization / eth-hash

eth-hash

JSON →
library0.8.0pypypi✓ verified 26d ago

eth-hash is a low-level Python library that provides the Ethereum hashing function, Keccak256. While sometimes erroneously referred to as SHA3, it implements the specific Keccak variant used in Ethereum. It is primarily intended for internal use by other Ethereum development tools. The current version is 0.8.0, with releases driven by the needs of the broader Ethereum ecosystem.

pip install "eth-hash[pycryptodome]"
INSTALL
IMPORT
SIG · ETH-HASH
E
eth-hash
serializationpythonv0.8.0
Install
1.8s avg
Import
118ms
Disk
25MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.124s · 26.4MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.8s · import 0.112s · 27MB
25MB installed
● package 25MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

keccak
from eth_hash.auto import keccak
Automatically loads an available backend to provide the keccak256 hashing function.
Keccak256
from eth_hash import Keccak256 from eth_hash.backends import pysha3 keccak = Keccak256(pysha3)
from eth_hash.auto import SHA3
For explicit backend selection or creating a Keccak256 instance. Avoid using 'SHA3' as it's a different function; Ethereum uses 'Keccak256'.

Demonstrates how to compute a Keccak256 hash using the automatically selected backend, both for a single input and incrementally. The output is a bytes object, which can be converted to a hexadecimal string for display.

from eth_hash.auto import keccak # Hash a byte string data_to_hash = b'hello world' hashed_data = keccak(data_to_hash) print(f"Hashed data: {hashed_data.hex()}") # Incremental hashing preimage = keccak.new(b'part-a') preimage.update(b'part-b') incremental_hash = preimage.digest() print(f"Incremental hash: {incremental_hash.hex()}")
Debug
Known issues
gotchaEthereum's hashing algorithm is Keccak256, not SHA3. While often colloquially referred to as SHA3, it is a distinct function. Using libraries or functions explicitly named 'SHA3' might lead to incorrect hash values for Ethereum contexts.
fix
Always refer to and use functions explicitly implementing 'Keccak256' for Ethereum compatibility. `eth-hash` correctly implements Keccak256.
affects: All versions
breakingThe `eth-hash` library requires a backend to be installed for the `keccak` function to be available. Installing just `eth-hash` will not provide the hashing functionality out-of-the-box.
fix
Install `eth-hash` with a chosen backend as an extra, e.g., `pip install "eth-hash[pycryptodome]"` or `pip install "eth-hash[pysha3]"`. `pycryptodome` is generally recommended for its performance and broader compatibility.
affects: All versions
gotchaeth-hash is a low-level utility. If you're looking for a more convenient and feature-rich hashing tool that integrates with other Ethereum utilities, `eth_utils.keccak()` is often a friendlier alternative built on top of `eth-hash`.
fix
Consider using `from eth_utils import keccak` if you need a higher-level API or other Ethereum-related utilities, otherwise `eth-hash` is appropriate for direct Keccak256 operations.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'eth_hash'
The 'eth-hash' Python package has not been installed in the current environment.
fix
pip install eth-hash
ImportError: cannot import name 'keccak' from 'eth_hash'
The 'keccak' hashing function is not directly exposed under the top-level 'eth_hash' module; it resides within 'eth_hash.auto'.
fix
from eth_hash.auto import keccak
ModuleNotFoundError: No module named 'Cryptodome'
The 'eth-hash' library requires a hashing backend (such as pycryptodome or pysha3) to be installed. This error occurs when 'eth_hash.auto' attempts to load the 'pycryptodome' backend, but the 'pycryptodome' package itself is missing because 'eth-hash' was installed without specifying an extra.
fix
pip install "eth-hash[pycryptodome]"
Upgrade
Version history
0.8.0latest on PyPI · released Mar 25, 2026
Audit
Dependencies
pycryptodomeoptionalProvides a fast C-implemented backend for Keccak256 hashing. Recommended for general use and PyPy3 support.
pysha3optionalAlternative backend for Keccak256 hashing.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
eth-hash — pip install eth-hash · libregistry