tronpy


Nametronpy JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/andelf/tronpy
SummaryTRON Python client library
upload_time2024-03-15 17:58:53
maintainer
docs_urlNone
authorandelf
requires_python>=3.8
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # tronpy

[![PyPI version](https://badge.fury.io/py/tronpy.svg)](https://pypi.org/project/tronpy/)
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/andelf/tronpy/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/andelf/tronpy/tree/master)

TRON Python Client Library. [Documentation](https://tronpy.readthedocs.io/en/latest/index.html)

> Note: in case you want to use cryptocurrency functions in an universal way or e.g. reliably calculate transaction fees for BTC, ETH, Tron and many others, check out the [Bitcart project](https://bitcart.ai)

## How to use

```python
from tronpy import Tron
from tronpy.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 tronpy import AsyncTron
from tronpy.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 tronpy.providers.async_http import AsyncHTTPProvider
from tronpy.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/andelf/tronpy",
    "name": "tronpy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "andelf",
    "author_email": "andelf@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/af/5e/0c4d025c1b99743f984df3b875b81195e1968235c8c407a598f5a25610a4/tronpy-0.5.0.tar.gz",
    "platform": null,
    "description": "# tronpy\n\n[![PyPI version](https://badge.fury.io/py/tronpy.svg)](https://pypi.org/project/tronpy/)\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/andelf/tronpy/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/andelf/tronpy/tree/master)\n\nTRON Python Client Library. [Documentation](https://tronpy.readthedocs.io/en/latest/index.html)\n\n> Note: in case you want to use cryptocurrency functions in an universal way or e.g. reliably calculate transaction fees for BTC, ETH, Tron and many others, check out the [Bitcart project](https://bitcart.ai)\n\n## How to use\n\n```python\nfrom tronpy import Tron\nfrom tronpy.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 tronpy import AsyncTron\nfrom tronpy.keys import PrivateKey\n\n# private key of TMisHYBVvFHwKXHPYTqo8DhrRPTbWeAM6z\npriv_key = PrivateKey(bytes.fromhex(\"8888888888888888888888888888888888888888888888888888888888888888\"))\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\nif __name__ == '__main__':\n    asyncio.run(transfer())\n```\n\nOr close async client manually:\n\n```python\nfrom httpx import AsyncClient, Timeout\nfrom tronpy.providers.async_http import AsyncHTTPProvider\nfrom tronpy.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\nif __name__ == '__main__':\n    asyncio.run(transfer())\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "TRON Python client library",
    "version": "0.5.0",
    "project_urls": {
        "Homepage": "https://github.com/andelf/tronpy"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a574469d878482182d49d068f506b44e85cadd3e4e838becf6e75cfbdc6e49dd",
                "md5": "4928971069d9847b32ce82c46c46ecbc",
                "sha256": "04b28bc9bd49255ee48757db39c3df48affe8ab36bd7674c2e369ea34e02fc21"
            },
            "downloads": -1,
            "filename": "tronpy-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4928971069d9847b32ce82c46c46ecbc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 42930,
            "upload_time": "2024-03-15T17:58:51",
            "upload_time_iso_8601": "2024-03-15T17:58:51.506360Z",
            "url": "https://files.pythonhosted.org/packages/a5/74/469d878482182d49d068f506b44e85cadd3e4e838becf6e75cfbdc6e49dd/tronpy-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "af5e0c4d025c1b99743f984df3b875b81195e1968235c8c407a598f5a25610a4",
                "md5": "8e0ab114fca50ccd04e396e03c864a41",
                "sha256": "2fe9bb26992dfc6a590dc30f3dcc4e631a91c2b5fa89eb785e9389e32d4891cb"
            },
            "downloads": -1,
            "filename": "tronpy-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8e0ab114fca50ccd04e396e03c864a41",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 44801,
            "upload_time": "2024-03-15T17:58:53",
            "upload_time_iso_8601": "2024-03-15T17:58:53.813652Z",
            "url": "https://files.pythonhosted.org/packages/af/5e/0c4d025c1b99743f984df3b875b81195e1968235c8c407a598f5a25610a4/tronpy-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-15 17:58:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "andelf",
    "github_project": "tronpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "lcname": "tronpy"
}
        
Elapsed time: 0.21919s