Python implementation of TON Public API for The Open Network (TON).
- TON.sh - full
- TON Center - partial, will be extended
- TON Center Testnet - partial, will be extended
- TON API - partial, will be extended
- TON API Testnet - partial, will be extended
- TON CAT - partial, will be extended
Installation using pip (a Python package manager):
$ pip install pyTONPublicAPI
Everything is as simple as the API itself.
- Create pyTONPublicAPI instance
- Access API methods in pythonic notation (getAddressInformation -> get_address_information)
from pyTONPublicAPI import pyTONPublicAPI
client = pyTONPublicAPI()
print(client.get_address_balance(address = "EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N"))
If you want to work with a single address - you can pre-set it on init and avoid in functions.
from pyTONPublicAPI import pyTONPublicAPI
client = pyTONPublicAPI(address = "EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N")
print(client.get_address_balance())
print(client.get_transactions())
You can also check tests.py.
Exceptions are rised using pyTONException class.
By default all calls are sent to TON.sh server. To select API server you should:
- Create server object
- Pass it to pyTONPublicAPI constructor via api_server parameter
from pyTONPublicAPI import pyTONPublicAPI, pyTONAPIServerTonCenter
api_server=pyTONAPIServerTonCenter()
client = pyTONPublicAPI(api_server=api_server)
Site: https://ton.sh/api/
Class: pyTONAPIServerTonSh
Additional constructor paramters:
- blockchain_id - Identifier of target blockchain ID, either "mainnet" or "test". Default is "None", so default begaviour is up to API server.
Site: https://toncenter.com/api/v2/
Class: pyTONAPIServerTonCenter
Additional constructor paramters:
- api_key - Authentication key. Using API without API key is limited to 1 request per second. Default is "None", so API is used without API key.
Site: https://testnet.toncenter.com/api/v2/
Class: pyTONAPIServerTonCenterTest
Additional constructor paramters:
- api_key - Authentication key. Using API without API key is limited to 1 request per second. Default is "None", so API is used without API key.
Site: https://tonapi.io/
Class: pyTONAPIServerTonAPI
Additional constructor paramters:
- api_key - Authentication key. Using API without API key is limited to 1 request per second. Default is "None", so API is used without API key.
Site: https://testnet.tonapi.io/
Class: pyTONAPIServerTonAPITest
Additional constructor paramters:
- api_key - Authentication key. Using API without API key is limited to 1 request per second. Default is "None", so API is used without API key.
Site: https://ton.cat/
Class: pyTONAPIServerCAT
- API servers support different subset of commands. Check correspondent API specification before use.
- API servers have different reply formats! Currently it's up to you to deal with it. May be once there will be a reply parser for unification.