Skip to main content

Provide access to indexed TON blockchain.

Project description

PyTONAPI

PyPI Python Versions License

Python wrapper for tonapi.io
Note: You need an API key to use it, 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.

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
  • libscrc - Library for calculating CRC-16, CRC-CCITT, CRC-32 checksums APIs
  • websockets - A library for building WebSocket servers and clients in Python

Installation

pip install pytonapi

Usage

Synchronous Example:

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()

Asynchronous Example:

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())

More Examples:
Additional examples can be found in the examples folder.

Donations:


EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess

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.5.tar.gz (35.7 kB view hashes)

Uploaded Source

Built Distribution

pytonapi-0.1.5-py3-none-any.whl (52.1 kB view hashes)

Uploaded Python 3

Supported by

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