# tronpy
[![PyPI version](https://badge.fury.io/py/tronpy.svg)](https://pypi.org/project/tronpy/)
TRON Python Client Library. [Documentation](https://tronpy.readthedocs.io/en/latest/index.html)
## How to use
```python
from tronpy23 import Tron
from tronpy23.keys import PrivateKey
client = Tron(network='nile')
# Private key of TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3
priv_key = PrivateKey(bytes.fromhex("8888888888888888888888888888888888888888888888888888888888888888"))
txn = (
client.trx.transfer("TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3", "TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA", 1_000)
.memo("test memo")
.build()
.inspect()
.sign(priv_key)
.broadcast()
)
print(txn)
# > {'result': True, 'txid': '5182b96bc0d74f416d6ba8e22380e5920d8627f8fb5ef5a6a11d4df030459132'}
print(txn.wait())
# > {'id': '5182b96bc0d74f416d6ba8e22380e5920d8627f8fb5ef5a6a11d4df030459132', 'blockNumber': 6415370, 'blockTimeStamp': 1591951155000, 'contractResult': [''], 'receipt': {'net_usage': 283}}
```
### Async Client
```python
import asyncio
from tronpy23 import AsyncTron
from tronpy23.keys import PrivateKey
# private key of TMisHYBVvFHwKXHPYTqo8DhrRPTbWeAM6z
priv_key = PrivateKey(bytes.fromhex("8888888888888888888888888888888888888888888888888888888888888888"))
async def transfer():
async with AsyncTron(network='nile') as client:
print(client)
txb = (
client.trx.transfer("TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3", "TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA", 1_000)
.memo("test memo")
.fee_limit(100_000_000)
)
txn = await txb.build()
print(txn)
txn_ret = await txn.sign(priv_key).broadcast()
print(txn_ret)
# > {'result': True, 'txid': 'edc2a625752b9c71fdd0d68117802860c6adb1a45c19fd631a41757fa334d72b'}
print(await txn_ret.wait())
# > {'id': 'edc2a625752b9c71fdd0d68117802860c6adb1a45c19fd631a41757fa334d72b', 'blockNumber': 10163821, 'blockTimeStamp': 1603368072000, 'contractResult': [''], 'receipt': {'net_usage': 283}}
if __name__ == '__main__':
asyncio.run(transfer())
```
Or close async client manually:
```python
from httpx import AsyncClient, Timeout
from tronpy23.providers.async_http import AsyncHTTPProvider
from tronpy23.defaults import CONF_NILE
async def transfer():
_http_client = AsyncClient(limits=Limits(max_connections=100, max_keepalive_connections=20),
timeout=Timeout(timeout=10, connect=5, read=5))
provider = AsyncHTTPProvider(CONF_NILE, client=_http_client)
client = AsyncTron(provider=provider)
print(client)
priv_key = PrivateKey(bytes.fromhex("8888888888888888888888888888888888888888888888888888888888888888"))
txb = (
client.trx.transfer("TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3", "TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA", 1_000)
.memo("test memo")
.fee_limit(100_000_000)
)
txn = await txb.build()
print(txn)
txn_ret = await txn.sign(priv_key).broadcast()
print(txn_ret)
print(await txn_ret.wait())
await client.close()
if __name__ == '__main__':
asyncio.run(transfer())
```
Raw data
{
"_id": null,
"home_page": "https://github.com/allelementary/tronpy",
"name": "tronpy23",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6.2,<4.0",
"maintainer_email": "",
"keywords": "tron,api,blockchain",
"author": "Mikhail Antonov",
"author_email": "allelementaryfor@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5e/13/f20f2efe94a56d3864e757d40320d612de7b9530e5425c77127e20533809/tronpy23-0.1.0.tar.gz",
"platform": null,
"description": "# tronpy\n\n[![PyPI version](https://badge.fury.io/py/tronpy.svg)](https://pypi.org/project/tronpy/)\n\nTRON Python Client Library. [Documentation](https://tronpy.readthedocs.io/en/latest/index.html)\n\n## How to use\n\n```python\nfrom tronpy23 import Tron\nfrom tronpy23.keys import PrivateKey\n\nclient = Tron(network='nile')\n# Private key of TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3\npriv_key = PrivateKey(bytes.fromhex(\"8888888888888888888888888888888888888888888888888888888888888888\"))\n\ntxn = (\n client.trx.transfer(\"TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3\", \"TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA\", 1_000)\n .memo(\"test memo\")\n .build()\n .inspect()\n .sign(priv_key)\n .broadcast()\n)\n\nprint(txn)\n# > {'result': True, 'txid': '5182b96bc0d74f416d6ba8e22380e5920d8627f8fb5ef5a6a11d4df030459132'}\nprint(txn.wait())\n# > {'id': '5182b96bc0d74f416d6ba8e22380e5920d8627f8fb5ef5a6a11d4df030459132', 'blockNumber': 6415370, 'blockTimeStamp': 1591951155000, 'contractResult': [''], 'receipt': {'net_usage': 283}}\n```\n\n### Async Client\n\n```python\nimport asyncio\n\nfrom tronpy23 import AsyncTron\nfrom tronpy23.keys import PrivateKey\n\n# private key of TMisHYBVvFHwKXHPYTqo8DhrRPTbWeAM6z\npriv_key = PrivateKey(bytes.fromhex(\"8888888888888888888888888888888888888888888888888888888888888888\"))\n\n\nasync def transfer():\n async with AsyncTron(network='nile') as client:\n print(client)\n\n txb = (\n client.trx.transfer(\"TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3\", \"TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA\", 1_000)\n .memo(\"test memo\")\n .fee_limit(100_000_000)\n )\n txn = await txb.build()\n print(txn)\n txn_ret = await txn.sign(priv_key).broadcast()\n print(txn_ret)\n # > {'result': True, 'txid': 'edc2a625752b9c71fdd0d68117802860c6adb1a45c19fd631a41757fa334d72b'}\n print(await txn_ret.wait())\n # > {'id': 'edc2a625752b9c71fdd0d68117802860c6adb1a45c19fd631a41757fa334d72b', 'blockNumber': 10163821, 'blockTimeStamp': 1603368072000, 'contractResult': [''], 'receipt': {'net_usage': 283}}\n\n\nif __name__ == '__main__':\n asyncio.run(transfer())\n```\n\nOr close async client manually:\n\n```python\nfrom httpx import AsyncClient, Timeout\nfrom tronpy23.providers.async_http import AsyncHTTPProvider\nfrom tronpy23.defaults import CONF_NILE\n\n\nasync def transfer():\n _http_client = AsyncClient(limits=Limits(max_connections=100, max_keepalive_connections=20),\n timeout=Timeout(timeout=10, connect=5, read=5))\n provider = AsyncHTTPProvider(CONF_NILE, client=_http_client)\n client = AsyncTron(provider=provider)\n print(client)\n\n priv_key = PrivateKey(bytes.fromhex(\"8888888888888888888888888888888888888888888888888888888888888888\"))\n txb = (\n client.trx.transfer(\"TJzXt1sZautjqXnpjQT4xSCBHNSYgBkDr3\", \"TVjsyZ7fYF3qLF6BQgPmTEZy1xrNNyVAAA\", 1_000)\n .memo(\"test memo\")\n .fee_limit(100_000_000)\n )\n txn = await txb.build()\n print(txn)\n txn_ret = await txn.sign(priv_key).broadcast()\n\n print(txn_ret)\n print(await txn_ret.wait())\n await client.close()\n\n\nif __name__ == '__main__':\n asyncio.run(transfer())\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "TRON Python client library",
"version": "0.1.0",
"split_keywords": [
"tron",
"api",
"blockchain"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a3e72ac54ede0270b056f173987a5eaaf2b60d0177752b4dc9a193f629548309",
"md5": "251256a8d53b0175975b053a072586ab",
"sha256": "5e629dee1825678214275a32a314b4e684651a903f1d46a36a3f538fe29aae5a"
},
"downloads": -1,
"filename": "tronpy23-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "251256a8d53b0175975b053a072586ab",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6.2,<4.0",
"size": 34132,
"upload_time": "2023-01-14T20:23:42",
"upload_time_iso_8601": "2023-01-14T20:23:42.534423Z",
"url": "https://files.pythonhosted.org/packages/a3/e7/2ac54ede0270b056f173987a5eaaf2b60d0177752b4dc9a193f629548309/tronpy23-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5e13f20f2efe94a56d3864e757d40320d612de7b9530e5425c77127e20533809",
"md5": "8a62da5fa112c62dab5712f3bd7c21d8",
"sha256": "4457094e533663031d7599ebeff1ada087b478c647f1f29377320cb6acd4017b"
},
"downloads": -1,
"filename": "tronpy23-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "8a62da5fa112c62dab5712f3bd7c21d8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6.2,<4.0",
"size": 31863,
"upload_time": "2023-01-14T20:23:44",
"upload_time_iso_8601": "2023-01-14T20:23:44.294282Z",
"url": "https://files.pythonhosted.org/packages/5e/13/f20f2efe94a56d3864e757d40320d612de7b9530e5425c77127e20533809/tronpy23-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-14 20:23:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "allelementary",
"github_project": "tronpy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "tronpy23"
}