token-network
Resolve blockchain networks and tokens by name and get config (contract addresses, decimals, confirmations). All returned objects are Pydantic models (TokenDto, NetworkConfigDto, TokenOnNetworkDto, NetworkDataDto).
Install
pip install token-network
From source:
pip install -e .
Examples
Get a network and its settings
from token_network import network
# By name (callable)
bitcoin = network("bitcoin")
bitcoin.decimal # 8 (base token decimals)
bitcoin.confirmation_number # 2 (required confirmations)
bitcoin.wallet_address_regex # wallet validation regex for this network
bitcoin.approximate_confirmation_time # 1200 (approx. seconds to confirm)
bitcoin.config # NetworkConfigDto (Pydantic)
bitcoin.__dict__() # Full data: {"config": {...}, "tokens": [...]}
Wallet address validation
Each network includes a wallet_address_regex pattern in its config. Use it to validate addresses for that chain:
from token_network import network, get_network, validate_wallet_address
# Direct property (same style as .decimal / .confirmation_number)
network("ethereum").wallet_address_regex
# ^(0x)[0-9A-Fa-f]{40}$
# Via config
network("ethereum").config.wallet_address_regex
get_network("bitcoin").config.wallet_address_regex
# In full network dict
network("ethereum").to_dict()["config"]["wallet_address_regex"]
# Validate an address
validate_wallet_address("ethereum", "0xdAC17F958D2ee523a2206206994597C13D831ec7") # True
validate_wallet_address("ethereum", "0x123") # False
List tokens on a network
from token_network import network
ethereum = network("ethereum")
tokens = ethereum.tokens # list of TokenOnNetworkDto
for t in tokens:
print(t.token.symbol, t.contract_address or "native", t.decimal)
# ETH None 18
# USDT 0xdAC17F958D2ee523a2206206994597C13D831ec7 6
# ...
Get one token on a network
from token_network import get_token_on_network
usdt = get_token_on_network(network="ethereum", token_abbr="USDT")
usdt.contract_address # "0xdAC17F958D2ee523a2206206994597C13D831ec7"
usdt.decimal # 6
usdt.native # False
usdt.token.symbol # "USDT"
usdt.__dict__() # All fields as dict (or use .model_dump())
Same via attribute access
from token_network import network
# network.ethereum.usdt is the same as get_token_on_network(network="ethereum", token_abbr="USDT")
usdt = network.ethereum.usdt
assert usdt.contract_address == "0xdAC17F958D2ee523a2206206994597C13D831ec7"
Get token or network by identifier (Pydantic models)
from token_network import get_token, get_network, get_token_network
# Token by symbol, slug, or name (case-insensitive)
token = get_token("USDT") # TokenDto
print(token.symbol, token.precision) # USDT 6
# Network with config + tokens
net = get_network("bitcoin") # NetworkDataDto
print(net.config.base_token) # BTC
print(len(net.tokens)) # 1 (e.g. BTC)
# Token on a specific network
ton = get_token_network("USDT", "bsc") # TokenOnNetworkDto
print(ton.contract_address)
List all networks and tokens
from token_network import get_networks, get_tokens
get_networks() # ['bitcoin', 'bsc', 'dogecoin', 'ethereum', 'ripple', 'solana', 'tron']
get_tokens() # ['AAVE', 'BNB', 'BTC', 'ETH', 'USDT', ...]
Testnet config
from token_network import NetworkAccessor
testnet = NetworkAccessor(testnet=True)
bsc = testnet("bsc")
usdt_test = testnet.bsc.usdt # USDT on BSC from token_networks_testnet.yaml
Error handling
from token_network import network, get_token_on_network, TokenNetworkError
try:
network("unknown_chain")
except TokenNetworkError as e:
print(e) # Unknown network: 'unknown_chain'. Known networks: ...
try:
get_token_on_network(network="bitcoin", token_abbr="USDT")
except TokenNetworkError as e:
print(e) # Token 'USDT' is not on network 'bitcoin'. Available on this network: ['BTC']
API summary
| What you want | How |
|---|---|
| Network by name | network("bitcoin") or network.bitcoin |
| Base decimals / confirmations | network("bitcoin").decimal, .confirmation_number, .approximate_confirmation_time |
| Wallet address regex | network("ethereum").wallet_address_regex or .config.wallet_address_regex |
| Validate wallet address | validate_wallet_address("ethereum", "0x...") → True / False |
| Full network data as dict | network("bitcoin").__dict__() or .to_dict() |
| Tokens on a network | network("ethereum").tokens → list of TokenOnNetworkDto |
| One token on a network | get_token_on_network(network="ethereum", token_abbr="USDT") or network.ethereum.usdt |
| Token info | get_token("USDT") → TokenDto |
| Network + tokens | get_network("bitcoin") → NetworkDataDto |
| Token on network by ids | get_token_network("USDT", "bsc") → TokenOnNetworkDto |
All identifiers are case-insensitive. Unknown network/token raises TokenNetworkError.
Pydantic models
TokenDto— Token definition (slug, symbol, name, precision, factor). Fromget_token().NetworkConfigDto— Chain config (slug, name, network_type, base_token_decimal, confirmation_number, wallet_address_regex, …). Fromnetwork("x").configand insideTokenOnNetworkDto.network.TokenOnNetworkDto— Token on a network (network, token, contract_address, decimal, native, type). Fromget_token_on_network(),get_token_network(),network.ethereum.usdt.NetworkDataDto— Result ofget_network():config+tokens(list ofTokenOnNetworkDto).
Use .model_dump() to export any model as a dict.
Data sources
YAML under token_network/data/:
networks.yaml— chain config (includingwallet_address_regexper network)tokens.yaml— token definitionstoken_networks.yaml— mainnet bindings (token + network → contract, decimals)token_networks_testnet.yaml— testnet bindings (used withNetworkAccessor(testnet=True))
Development
pip install -e ".[dev]"
pytest
Metadata
Release files for token-network 0.4.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| token_network-0.4.6.tar.gz | 14.7 kB | Without provenance | Details for token_network-0.4.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| token_network-0.4.6-py3-none-any.whl | Python 3 | none | any | Details for token_network-0.4.6-py3-none-any.whl |
Total release size: 28.4 kB
Release files / token_network-0.4.6.tar.gz
| Download URL | token_network-0.4.6.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d42dff7bae072ae3c9cadf83292b9b09edd9b2db0706559933eeb509b0d35855
|
|
BLAKE2b-256 checksum How to use checksums |
03dcc3bff79d12c652c452670ee70de68a0ac6b1f66aabc9041b88caa5e558d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / token_network-0.4.6-py3-none-any.whl
| Download URL | token_network-0.4.6-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f3c4861a4ea32b12ae02dc7136e8fa52ce6ff6cc8ee3feb8640b3ec4162fa2d
|
|
BLAKE2b-256 checksum How to use checksums |
0fa7e62526524cfb6e6d2cb76b70cdab29e919b98880acb4b7120c69ec67cc32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for token-network 0.4.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.