Registry / auth-security / eth-keys

eth-keys

JSON →
library0.8.0pypypi✓ verified 25d ago

eth-keys is a Python library providing a common API for Ethereum key operations, including private key, public key, and signature management. It is currently at version 0.7.0 and is actively maintained by the Ethereum Foundation, with development hosted on GitHub.

pip install eth-keys
INSTALL
IMPORT
SIG · ETH-KEYS
E
eth-keys
auth-securitypythonv0.8.0
Install
3.8s avg
Import
650ms
Disk
40MB
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.95 runs
installs and imports cleanly · install 0.0s · import 0.692s · 40.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.8s · import 0.608s · 42MB
40MB installed
● package 40MB
Code
Verified usage

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

PrivateKey
from eth_keys import keys
from eth_keys import keys
KeyAPI
from eth_keys import KeyAPI

Initializes a PrivateKey object, derives the corresponding PublicKey, signs a message, and verifies the signature. It also demonstrates address generation and public key recovery from a signature.

from eth_keys import keys # Generate a new private key (random bytes in a real scenario) pk_bytes = b'\x01' * 32 # Example private key bytes pk = keys.PrivateKey(pk_bytes) # Get the public key pub_key = pk.public_key # Sign a message message = b'a message' signature = pk.sign_msg(message) # Verify the signature is_valid = signature.verify_msg(message, pub_key) print(f"Private Key: {pk.to_hex()}") print(f"Public Key: {pub_key.to_hex()}") print(f"Ethereum Address: {pub_key.to_checksum_address()}") print(f"Signature: {signature.to_hex()}") print(f"Signature Valid: {is_valid}") # Recover public key from signature recovered_pub_key = signature.recover_public_key_from_msg(message) print(f"Recovered Public Key Matches: {recovered_pub_key == pub_key}")
Debug
Known issues
breakingThe library and PyPI package were renamed from `ethereum-keys` to `eth-keys` in November 2017. Ensure you are importing from `eth_keys` and not the old package name.
fix
Update your import statements from `ethereum_keys` to `eth_keys` and install `eth-keys`.
affects: All versions after 2017-11 (effectively 0.2.0 and later)
gotchaFor optimal performance, `eth-keys` defaults to using the `CoinCurveECCBackend` if the `coincurve` library is installed. However, `coincurve` is not automatically installed as a dependency and must be installed separately. If not installed, it falls back to the pure Python `NativeECCBackend`, which is slower.
fix
For performance-critical applications, install `coincurve` explicitly: `pip install coincurve`.
affects: All versions
gotchaThe `PublicKey` class constructor expects a 64-byte `bytes` string. Common public key formats like 65-byte (with a leading `\x04` byte) or 33-byte (compressed, starting with `\x02` or `\x03`) require pre-processing (e.g., stripping the first byte for 65-byte format or using `PublicKey.from_compressed_bytes`).
fix
Ensure public key input is in the expected 64-byte uncompressed format or use appropriate `from_...` class methods.
affects: All versions
gotchaA private key consisting of all zero bytes (`b'\x00' * 32`) is mathematically invalid for generating a public key in elliptic-curve cryptography. While an address might be derived and accept funds, any transaction signed with this 'private key' will be rejected by the network as having an 'invalid sender'.
fix
Always generate private keys using a cryptographically secure random number generator to ensure they are within the valid range and non-zero.
affects: All versions
gotchaNever hardcode, commit to version control, or expose private keys directly in source code. Private keys are critical secrets that should be handled securely, ideally loaded from environment variables or a secure key management system.
fix
Store private keys in environment variables (e.g., `os.environ.get('PRIVATE_KEY', '')`) or a secure vault, and load them at runtime.
affects: All versions
Upgrade
Version history
0.8.0latest on PyPI · released Aug 21, 2026
Audit
Dependencies
eth-utilsrequiredUtility functions for Ethereum development.
eth-typingrequiredType hinting for Ethereum primitives.
coincurveoptionalOptional backend for faster ECC operations. eth-keys falls back to NativeECCBackend if not installed.
Agent activity
28 hits · last 30 days
node
24
Amazon
1
OpenAI (training)
1
Resources
eth-keys — pip install eth-keys · libregistry