eth-typing: Common type annotations for ethereum python packages

6.0.0 · active · verified Thu Apr 09

eth-typing provides common type annotations for various Ethereum Python packages, offering a standardized set of types for improved type hinting and code clarity across the Ethereum ecosystem. It is actively maintained with frequent releases, currently at version 6.0.0, supporting modern Python versions. [1, 2, 5]

Warnings

Install

Imports

Quickstart

Demonstrates importing and using `Address`, `ChecksumAddress`, and `HexStr` for type hinting. This example simplifies address processing as `eth-typing` focuses solely on type definitions, not implementation logic.

from eth_typing.evm import Address, ChecksumAddress
from eth_typing.encoding import HexStr

def process_ethereum_address(address: Address) -> ChecksumAddress:
    # In a real application, you would perform checksum validation
    # or other address-related logic here.
    # For this example, we'll just cast it for demonstration.
    # eth-utils or web3.py typically handle checksumming.
    if not isinstance(address, str) or not address.startswith('0x'):
        raise ValueError('Invalid address format')
    # Simulate a checksummed address return
    return ChecksumAddress(address.lower()) # Simplified for quickstart

my_raw_address: Address = Address('0x742d35Cc6634C0532925a3b844Bc454e4438f444')
checksum_addr: ChecksumAddress = process_ethereum_address(my_raw_address)

print(f'Processed Address: {checksum_addr}')

def get_hex_string_length(hex_str: HexStr) -> int:
    return len(hex_str)

my_hex_string: HexStr = HexStr('0xabcdef123456')
print(f'Hex string length: {get_hex_string_length(my_hex_string)}')

view raw JSON →