Fully-typed Python SDK for the Tronsave v2 API (TRON Energy & Bandwidth).
Project description
tronsave (Python)
Fully-typed Python SDK for the Tronsave v2 API (TRON Energy & Bandwidth).
Python 3.9+, built on httpx.
Install
pip install tronsave
Quick start
import os
from tronsave import TronsaveClient, Network
sdk = TronsaveClient(api_key=os.environ["TRONSAVE_API_KEY"], network=Network.MAINNET)
me = sdk.get_user_info()
print(me.balance, "SUN")
est = sdk.estimate_buy_resource({
"receiver": "TFwUFWr3QV376677Z8VWXxGUAMFSrq1MbM",
"resourceType": "ENERGY",
"resourceAmount": 65000, # ENERGY must be > 64000
"durationSec": 3600,
})
order = sdk.buy_resource(
{"receiver": "TFwUFWr3QV376677Z8VWXxGUAMFSrq1MbM", "resourceAmount": 65000, "durationSec": 3600},
{"allowPartialFill": True, "maxPriceAccepted": 100},
)
status = sdk.get_order(order.order_id)
print(status.fulfilled_percent) # 100 = fully delegated
Errors
All exceptions subclass tronsave.TronsaveError (.code, .status, .raw):
TronsaveAuthError (401), TronsaveValidationError / TronsaveBusinessError (400),
TronsaveRateLimitError (429, .retry_after_ms), TronsaveNetworkError (transport).
from tronsave import TronsaveBusinessError, TronsaveRateLimitError
try:
sdk.buy_resource({"receiver": "T...", "resourceAmount": 65000})
except TronsaveRateLimitError as e:
print("retry after", e.retry_after_ms, "ms")
except TronsaveBusinessError as e:
print(e.code, e.status)
Notes
- Defaults:
ENERGY,MEDIUM,durationSec=259200. - ENERGY
resourceAmountmust be > 64000 (rejected client-side). extendTois a Unix timestamp in seconds.- Rate limits enforced client-side (15/s; 1/s for
get_extendable_delegates).
Develop
pip install -e ".[dev]"
pytest # runs the shared conformance suite (needs Node.js for the mock server)
See ../../spec/PARITY.md for cross-language parity.
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 tronsave-2.0.0.tar.gz.
File metadata
- Download URL: tronsave-2.0.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b5085ca89a1b8e1533a69a100530476ef80113b3909479e19e47bd7e12adee7
|
|
| MD5 |
835dc90e8b4a239844a0cbee03821fb5
|
|
| BLAKE2b-256 |
d2a38d8644fe9743de23d0d5b714fea2056fc16804d2ee157ba01aaf88325063
|
File details
Details for the file tronsave-2.0.0-py3-none-any.whl.
File metadata
- Download URL: tronsave-2.0.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b23b05080cdadd0ff313bedaabde63bf80bc89d3681fc37ccbb8518511c33d17
|
|
| MD5 |
245fc5edbf893c8deb470a5b77a33861
|
|
| BLAKE2b-256 |
1a4cb3df2abf31501f0cbeaed39fab80e57e1432496712e16c4d5836ce31786e
|