Skip to main content

Provide access to indexed TON blockchain.

Project description

📦 PyTONAPI

TON PyPI Python Versions License

Image

Downloads Downloads Downloads

Python SDK for tonapi.io.
Information about the API can be found in the documentation.
To use the API you need an API key, you can get it here tonconsole.com.

Features

  • Asynchronous and Synchronous Calls:
    Enjoy the flexibility of both asynchronous and synchronous variants for API calls.

  • Response Validation with Pydantic Models:
    All response data is validated using Pydantic models, ensuring that you receive structured and validated information.

  • Convenient Data Manipulation:
    The wrapper facilitates seamless manipulation of data, such as converting balances to nanotons or amounts.

  • Extensive Examples:
    Explore a variety of examples in the examples folder to help you get started and understand different use cases.

Usage

Installation

pip install pytonapi

Examples

Asynchronous
from pytonapi import AsyncTonapi


# Declare an asynchronous function for using await
async def main():
    # Create a new Tonapi object with the provided API key
    tonapi = AsyncTonapi(api_key="Your API key")

    # Specify the account ID
    account_id = "EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess"  # noqa

    # Retrieve account information asynchronously
    account = await tonapi.accounts.get_info(account_id=account_id)

    # Print account details
    print(f"Account Address (raw): {account.address.to_raw()}")
    print(f"Account Address (userfriendly): {account.address.to_userfriendly(is_bounceable=True)}")
    print(f"Account Balance (nanoton): {account.balance.to_nano()}")
    print(f"Account Balance (amount): {account.balance.to_amount()}")


if __name__ == '__main__':
    import asyncio

    # Run the asynchronous function
    asyncio.run(main())
Synchronous
from pytonapi import Tonapi


def main():
    # Create a new Tonapi object with the provided API key
    tonapi = Tonapi(api_key="Your API key")

    # Specify the account ID
    account_id = "EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess"  # noqa

    # Retrieve account information
    account = tonapi.accounts.get_info(account_id=account_id)

    # Print account details
    print(f"Account Address (raw): {account.address.to_raw()}")
    print(f"Account Address (userfriendly): {account.address.to_userfriendly(is_bounceable=True)}")
    print(f"Account Balance (nanoton): {account.balance.to_nano()}")
    print(f"Account Balance (amount): {account.balance.to_amount()}")


if __name__ == '__main__':
    main()
More
  • Additional examples can be found examples folder.

Dependencies

  • httpx - A fully featured HTTP client for Python 3, which provides sync and async
  • pydantic - Data validation and settings management using Python type hints
  • websockets - A library for building WebSocket servers and clients in Python

Contribution

We welcome your contributions! If you have ideas for improvement or have identified a bug, please create an issue or submit a pull request.

Support

Supported by TONAPI and TON Society (Grants and Bounties program).

Donations

TON - EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess

USDT (TRC-20) - TJjADKFT2i7jqNJAxkgeRm5o9uarcoLUeR

License

This repository is distributed under the MIT License. Feel free to use, modify, and distribute the code in accordance with the terms of the license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytonapi-0.1.8.tar.gz (36.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytonapi-0.1.8-py3-none-any.whl (53.6 kB view details)

Uploaded Python 3

File details

Details for the file pytonapi-0.1.8.tar.gz.

File metadata

  • Download URL: pytonapi-0.1.8.tar.gz
  • Upload date:
  • Size: 36.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.31.0 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for pytonapi-0.1.8.tar.gz
Algorithm Hash digest
SHA256 e46aa9a40f8205435e55369ed3f0c441c617ac0665d402c2012e3058286cffd0
MD5 07c397e5f3ed958cfb31cf21e9f36957
BLAKE2b-256 7ef0779d9096547919e64655cd3262c43530b0bfe418da85ce1ee1863e6bebaf

See more details on using hashes here.

File details

Details for the file pytonapi-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: pytonapi-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 53.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.31.0 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for pytonapi-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 43428ac4a6eca72a1b2c672a4fced30bf4ffb6e7301df1d52d6309070b269ee2
MD5 0f5c6c76d4c8c9a47915bebf9a237907
BLAKE2b-256 9f87f4dafc89accef12afcab968878e558b00bc137d5cec3f929c479064ad339

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page