Validate input and return token network config (e.g. network.bitcoin, network.bsc.usdt)
Project description
token-network
Python library that validates input and returns token network config. Use attribute access like network.bitcoin or network.bsc.usdt to get network and token data.
Install
From PyPI (after publishing):
pip install token-network
From source (development):
pip install -e .
Publishing to PyPI (so others can pip install token-network)
-
Create an account on pypi.org (and optionally test.pypi.org for testing).
-
Install build and twine:
pip install build twine
-
Build the package:
cd /path/to/token-network python -m build
-
Upload to PyPI (you’ll be prompted for your PyPI username and password or token):
twine upload dist/*
To try Test PyPI first:
twine upload --repository testpypi dist/*, then install with:pip install --index-url https://test.pypi.org/simple/ token-network -
After that, anyone can run:
pip install token-network
Usage
from token_network import network, TokenNetworkError
Get all config for a network
# Network config only
network.bitcoin.config
# {'network_type': 'UTXO', 'token_standard': 'BTC', 'base_token': 'BTC', ...}
# Tokens on that network (with contract_address, decimal, native, token_info)
network.bitcoin.tokens
# Full payload: config + tokens
network.bitcoin.to_dict()
# {"config": {...}, "tokens": [...]}
Get data for a token on a network
# All data for USDT on BSC: network config, token info, contract_address, decimal, native
network.bsc.usdt
# {
# 'network': {...},
# 'token': {'slug': 'usdt', 'symbol': 'USDT', 'name': 'tether', ...},
# 'contract_address': '0x55d398326f99059fF775485246999027B3197955',
# 'decimal': 18,
# 'native': False
# }
network.ethereum.usdt
network.tron.usdt
Validation
Unknown network or token raises TokenNetworkError:
try:
network.unknown_chain
except TokenNetworkError as e:
print(e) # Unknown network: 'unknown_chain'. Known networks: bitcoin, bsc, ...
try:
network.bsc.unknown_token
except TokenNetworkError as e:
print(e) # Token 'UNKNOWN_TOKEN' is not defined on network 'bsc'. Available tokens: [...]
Data sources
Config is loaded from YAML inside the package:
networks.yaml— chain config (network_type, token_standard, base_token, confirmation_number, …)tokens.yaml— token definitions (symbol, name, precision, factor)token_networks.yaml— which token exists on which network (contract_address, decimal, native)
To change data, edit the YAML files in token_network/data/ (or the repo root and sync into the package).
Development
pip install -e ".[dev]"
pytest
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file token_network-0.1.0.tar.gz.
File metadata
- Download URL: token_network-0.1.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bfa1b8fe986115bb9adb65c571740513e830a422295d8c414641296bab9fc82
|
|
| MD5 |
55a8e20820fb5ed8341b1779022f30ee
|
|
| BLAKE2b-256 |
915bcb35f3e381d9f790a993c8e5bfac1012830dfd1c786e3f91bebbd1aceba4
|
File details
Details for the file token_network-0.1.0-py3-none-any.whl.
File metadata
- Download URL: token_network-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33b322e7e13bca388337b5afdb84fd96ac354f7786683c5822754648df01a20d
|
|
| MD5 |
1922ca00ad84c1dd6668a25168219c13
|
|
| BLAKE2b-256 |
f002a480d75b017c233551af555801f40e5e03457208fed07bd8d776fc31bf29
|