{"id":1824,"library":"eth-hash","title":"eth-hash: Ethereum Keccak256 Hashing Function","description":"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.","status":"active","version":"0.8.0","language":"en","source_language":"en","source_url":"https://github.com/ethereum/eth-hash","tags":["ethereum","hashing","keccak","sha3","cryptography"],"install":[{"cmd":"pip install \"eth-hash[pycryptodome]\"","lang":"bash","label":"Recommended installation with backend"},{"cmd":"pip install eth-hash","lang":"bash","label":"Basic installation (requires manual backend setup)"}],"dependencies":[{"reason":"Provides a fast C-implemented backend for Keccak256 hashing. Recommended for general use and PyPy3 support.","package":"pycryptodome","optional":true},{"reason":"Alternative backend for Keccak256 hashing.","package":"pysha3","optional":true}],"imports":[{"note":"Automatically loads an available backend to provide the keccak256 hashing function.","symbol":"keccak","correct":"from eth_hash.auto import keccak"},{"note":"For explicit backend selection or creating a Keccak256 instance. Avoid using 'SHA3' as it's a different function; Ethereum uses 'Keccak256'.","wrong":"from eth_hash.auto import SHA3","symbol":"Keccak256","correct":"from eth_hash import Keccak256\nfrom eth_hash.backends import pysha3\nkeccak = Keccak256(pysha3)"}],"quickstart":{"code":"from eth_hash.auto import keccak\n\n# Hash a byte string\ndata_to_hash = b'hello world'\nhashed_data = keccak(data_to_hash)\nprint(f\"Hashed data: {hashed_data.hex()}\")\n\n# Incremental hashing\npreimage = keccak.new(b'part-a')\npreimage.update(b'part-b')\nincremental_hash = preimage.digest()\nprint(f\"Incremental hash: {incremental_hash.hex()}\")","lang":"python","description":"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."},"warnings":[{"fix":"Always refer to and use functions explicitly implementing 'Keccak256' for Ethereum compatibility. `eth-hash` correctly implements Keccak256.","message":"Ethereum'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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"breaking","affected_versions":"All versions"},{"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.","message":"eth-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`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}