Skip to main content

Provide access to indexed TON blockchain.

Project description

PyTONAPI

PyPI Python Versions License

Python wrapper for tonapi.io v2
You need an api key to use it, get it here tonconsole.com

Dependencies

Installation

pip install pytonapi

Examples

Get account info:

# Importing required package
from pytonapi import Tonapi


def main():
    # Creating new Tonapi object
    tonapi = Tonapi(api_key="Your api key")

    account_id = "EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess"  # noqa
    account = tonapi.accounts.get_info(account_id=account_id)

    # print account address (raw)
    print(account.address.to_raw())
    # output: 0:bede2955afe5b451cde92eb189125c12685c6f8575df922400dc4c1d5411cd35

    # print account address (userfriendly)
    print(account.address.to_userfriendly())
    # output: EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess

    # print account balance (nanoton)
    print(account.balance.to_nano())
    # output: 1500000000

    # print account balance (amount)
    print(account.balance.to_amount())
    # output: 1.5


if __name__ == '__main__':
    main()

Asynchronous example:

# Importing required package
import asyncio

from pytonapi import AsyncTonapi


# Declaring asynchronous function for using await
async def main():
    # Creating new Tonapi object
    tonapi = AsyncTonapi(api_key="Your api key")

    account_id = "EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess"  # noqa
    account = await tonapi.accounts.get_info(account_id=account_id)

    # print account address (raw)
    print(account.address.to_raw())
    # output: 0:bede2955afe5b451cde92eb189125c12685c6f8575df922400dc4c1d5411cd35

    # print account address (userfriendly)
    print(account.address.to_userfriendly())
    # output: EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess

    # print account balance (nanoton)
    print(account.balance.to_nano())
    # output: 1500000000

    # print account balance (amount)
    print(account.balance.to_amount())
    # output: 1.5


if __name__ == '__main__':
    # Running asynchronous function
    asyncio.run(main())


Get account transactions:

# Importing required package
from pytonapi import Tonapi
from pytonapi.utils import nano_to_amount


def main():
    # Creating new Tonapi object
    tonapi = Tonapi(api_key="Your api key")

    account_id = "EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess"  # noqa
    result = tonapi.blockchain.get_account_transactions(
        account_id=account_id, limit=100,
    )
    for transaction in result.transactions:

        # print transaction value (nanoton)
        print(transaction.in_msg.value)
        # output: 1000000000

        # print transaction value (amount)
        print(nano_to_amount(transaction.in_msg.value))
        # output: 1.0

        # print transaction text comment
        if transaction.in_msg.decoded_op_name == "text_comment":
            print(transaction.in_msg.decoded_body["Text"])
            # output: Hello, World!


if __name__ == '__main__':
    main()


Get NFT items from collection by collection address:

# Importing required package
from pytonapi import Tonapi


def main():
    # Creating new Tonapi object
    tonapi = Tonapi(api_key="Your api key")

    account_id = "EQAUxYSo-UwoqAGixaD3d7CNLp9PthgmEZfnr6BvsijzJHdA"  # noqa
    result = tonapi.nft.get_items_by_collection_address(
        account_id=account_id, limit=100, offset=0
    )
    for nft in result.nft_items:
        # print nft address (raw)
        print(nft.address.to_raw())
        # output: 0:74c15fd0695c4706213ded4ac45eb7a2f87ff4c8f5d6bc904fe7dd1b735936e4

        # print nft address (userfriendly)
        print(nft.address.to_userfriendly())
        # output: EQB0wV_QaVxHBiE97UrEXrei-H_0yPXWvJBP590bc1k25KtT

        # print nft owner address
        print(nft.owner.address.to_userfriendly())
        # output: EQCOF6xKqliQjY1yrwwn7qm8OjyEJBpH_sqVCe-XgMak5MDN

        # print nft previews url
        print(nft.previews[0].url)
        # output: https://cache.tonapi.io/imgproxy/c0wiqWVwr79OCcmR7qD-4WIKWOnk8t4vX_cqmohhE8s/rs:fill:100:100:1/g:no/aHR0cHM6Ly9uZnQudG9ubWVuZG9uLmNvbS9jb2xsZWN0aW9ucy9jYXJkcy8zMi5wbmc.webp


if __name__ == '__main__':
    main()


Get NFT items by owner address:

# Importing required package
from pytonapi import Tonapi


def main():
    # Creating new Tonapi object
    tonapi = Tonapi(api_key="Your api key")

    account_id = "EQC-3ilVr-W0Uc3pLrGJElwSaFxvhXXfkiQA3EwdVBHNNess"  # noqa
    result = tonapi.accounts.get_nfts(
        account_id=account_id, limit=10, offset=0
    )
    for nft in result.nft_items:
        # print nft address (raw)
        print(nft.address.to_raw())
        # output: 0:74c15fd0695c4706213ded4ac45eb7a2f87ff4c8f5d6bc904fe7dd1b735936e4

        # print nft address (userfriendly)
        print(nft.address.to_userfriendly())
        # output: EQB0wV_QaVxHBiE97UrEXrei-H_0yPXWvJBP590bc1k25KtT

        # print nft collection address
        print(nft.collection.address.to_userfriendly())
        # output: EQCA14o1-VWhS2efqoh_9M1b_A9DtKTuoqfmkn83AbJzwnPi

        # print nft previews url
        print(nft.previews[0].url)
        # output: https://cache.tonapi.io/imgproxy/c0wiqWVwr79OCcmR7qD-4WIKWOnk8t4vX_cqmohhE8s/rs:fill:100:100:1/g:no/aHR0cHM6Ly9uZnQudG9ubWVuZG9uLmNvbS9jb2xsZWN0aW9ucy9jYXJkcy8zMi5wbmc.webp


if __name__ == '__main__':
    main()

And more . . .


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.0.6.tar.gz (17.0 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.0.6-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytonapi-0.0.6.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pytonapi-0.0.6.tar.gz
Algorithm Hash digest
SHA256 4f1a112da05c1c33bfac8b510bb990141a390608420c946b2dceb08cff7be36b
MD5 7c0a3fecec1ba3580f708b53c529245b
BLAKE2b-256 075ddd00dba95f28d2a730703b984aaec3c95a79f369e33f57f0d91f842af9e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytonapi-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pytonapi-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ed3dcc0805794db1f76433eceab09b6e8ca19bc8781634254af87c8c01070484
MD5 ad36a05f267a2bd79ee3984e94ce2042
BLAKE2b-256 8e65697c109bd5cbe61b29060c8463b97c65f55710cc3f52ad998f1beb65b8f5

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