eth-pydantic-types: Pydantic Types for Ethereum
Project description
eth-pydantic-types
The types in this package are pydantic types for Ethereum inspired from eth-typing.
Hash32
Hash32 is a good type to use for Ethereum transaction hashes. When using the Hash32 type, your inputs will be validated by length and your schema will declare the input a string with a binary format. Use Hash32 like this:
from pydantic import BaseModel
from eth_pydantic_types import Hash32
class Transaction(BaseModel):
tx_hash: Hash32
# NOTE: I am able to pass an int-hash as the value and it will
# get validated and type-coerced.
tx = Transaction(
tx_hash=0x1031f0c9ac54dcb64b4f121a27957c14263c5cb49ed316d568e41e19c34d7b28
)
HexBytes
A thin-wrapper around an already thin-wrapper hexbytes.HexBytes
.
The difference here is that this HexBytes properly serializes.
Use HexBytes any place where you would actually use hexbytes.HexBytes
.
from pydantic import BaseModel
from eth_pydantic_types import HexBytes
class MyStorage(BaseModel):
cid: HexBytes
# NOTE: We are able to pass a hex-str for a HexBytes value.
storage = MyStorage(cid="0x123")
Address
Use the Address class for working with checksummed-addresses. Addresses get validated and checksummed in model construction.
from pydantic import BaseModel
from eth_pydantic_types import Address
class Account(BaseModel):
address: Address
# NOTE: The address ends up checksummed
# ("0x0837207e343277CBd6c114a45EC0e9Ec56a1AD84")
account = Account(address="0x837207e343277cbd6c114a45ec0e9ec56a1ad84")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file eth-pydantic-types-0.1.0a1.tar.gz
.
File metadata
- Download URL: eth-pydantic-types-0.1.0a1.tar.gz
- Upload date:
- Size: 61.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/42.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.0.6 tqdm/4.66.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2d73769e7b366fcaa28c6dd9cae286e17ca3d74358b43877da92a17c5080605 |
|
MD5 | 0cfe4e95ca4514719de5fae6eb8aa587 |
|
BLAKE2b-256 | 9c99369e61fb85e9d43dd43ff3611eb39946f735fed495638da5ab20db493168 |
File details
Details for the file eth_pydantic_types-0.1.0a1-py3-none-any.whl
.
File metadata
- Download URL: eth_pydantic_types-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/42.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.0.6 tqdm/4.66.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | babd6678ae19c00063ac92269af76fe9441d94baf16718f691d03971118fafaa |
|
MD5 | 87909dca9400043419cb0049fd46f2bd |
|
BLAKE2b-256 | e84a7f78e9ded0a7baff3a1edb4d4fbaa70f6a2324abd5b389fd9ec1841b76d1 |