eth-hash: Ethereum Keccak256 Hashing Function

0.8.0 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

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()}")

view raw JSON →