Skip to main content

TON Client

TON SDK Client library Python bindings. Works for Python 3.6+

PyPI TonClient Ubuntu 20.04 TonClient MacOS Latest

Installation

  1. Create python virtual environment using pipenv or virtualenv
  2. Activate created environment
  3. Run pip install ton-client-py

If you encounter problems while installing aiounittest just skip this step. It is needed only for running asyncio test.

Tests

  1. Create python virtual environment using pipenv or virtualenv and activate it
  2. Clone git repository and enter it
  3. Run python setup.py install
  4. Run python -m unittest

Client

Core client library has sync and async request modes. Some core methods are available only in async request mode and this mode is more prefferable, so python client is created with async core requests by default.

Create client

from tonclient.client import TonClient

client = TonClient()

# If you need sync core requests for some reason
client_sync_core = TonClient(is_core_async=False)

Client is created with default config

{
    'network': {
        'server_address': 'http://localhost',
        'message_retries_count': 5,
        'message_processing_timeout': 40000,
        'wait_for_timeout': 40000,
        'out_of_sync_threshold': 15000,
        'access_key': ''
    },
    'crypto': {
        'fish_param': ''
    },
    'abi': {
        'message_expiration_timeout': 40000,
        'message_expiration_timeout_grow_factor': 1.5
    }
}

You can override initial config while creating a client

from tonclient.client import TonClient, DEVNET_BASE_URL

client = TonClient(network={'server_address': DEVNET_BASE_URL}, abi={'message_expiration_timeout': 30000})
version = client.version()

Client contains all core modules and its' methods. You can get full list of modules and methods here: https://github.com/tonlabs/TON-SDK/blob/master/docs/modules.md
Module method is called by template client.[module].[method]

from tonclient.client import TonClient, DEVNET_BASE_URL

client = TonClient(network={'server_address': DEVNET_BASE_URL})

# Generate random signing keys
keypair = client.crypto.generate_random_sign_keys()
# Parse account
parsed = client.boc.parse_account(boc='Account base64 BOC')

You always can get information about method and its' arguments in method docstring.

Net module and GraphQL queries

To create GraphQL query for net module methods use builtin factory.
collection and result are required for all queries, other filters are optional.

from tonclient.net import TonQLQuery

# Create query collection
query = TonQLQuery(collection='messages')

# Set filter
# `set_filter` methods accepts any number of kwargs for filtering data.
# kwarg name contains field name and condition separated by __.
# E.g. field__gt=111 is equal to GraphQL {'field': {'gt': 111}}
query = query.set_filter(field__gt=111, field__eq='0:')

# Set result
query = query.set_result('id boc')
# or you can set result fields as separate args
query = query.set_result('id', 'boc')
# or you can combine all of this
query = query.set_result('id boc', 'field')

# Set order (you can pass arguments in the same way as for `set_result`)
query = query.set_order('created_at')  # ASC sorting
query = query.set_order('-created_at')  # DESC sorting

# Set limit
query = query.set_limit(5)

Methods with events

Some library methods net.subscribe_collection, proccessing.send_message, processing.wait_for_transaction, processing.process_message may return either result or generator.

  • net.subscribe_collection always returns a generator
  • proccessing.send_message, processing.wait_for_transaction, processing.process_message return generator only if send_events argument is set to True

Please, dig in tonclient/test/test_net.py, tonclient/test/test_processing.py to get example how to work with generators.

Client and asyncio

from tonclient.client import TonClient, DEVNET_BASE_URL

# Create client with `is_async=True` argument.
client = TonClient(network={'server_address': DEVNET_BASE_URL}, is_async=True)

# Get version (simple method with result)
version = await client.version()

# Generators
generator = client.net.subscribe_collection(query=TonQLQuery)
async for event in generator:
    # Work with event
    pass

Please, dig in tonclient/test/test_async.py to get more info.

Metadata

Release files for ton-client-py 1.0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ton-client-py 1.0.0.4
File Size Uploaded Provenance Actions
ton-client-py-1.0.0.4.tar.gz 14.5 MB Without provenance Details for ton-client-py-1.0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ton-client-py 1.0.0.4
File Interpreter ABI Platform Actions
ton_client_py-1.0.0.4-py3-none-any.whl Python 3 none any Details for ton_client_py-1.0.0.4-py3-none-any.whl

Total release size: 29.1 MB

Release files / ton-client-py-1.0.0.4.tar.gz

Download URL ton-client-py-1.0.0.4.tar.gz
Size 14.5 MB
Tags Source
SHA-256 checksum
How to use checksums
a198d1b9936f2a88c6ccd6561a180ab996cd63d9b8f9d64a206033965fffd57b
BLAKE2b-256 checksum
How to use checksums
4d433445f945f44f19685c42f6093acdd1a749913ea0907c224f8e7c89ca875a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

Release files / ton_client_py-1.0.0.4-py3-none-any.whl

Download URL ton_client_py-1.0.0.4-py3-none-any.whl
Size 14.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
29ab6205b07d6956856eda234cf4c3d2cb4dc33ec897540cd5b0e8d2d1b69566
BLAKE2b-256 checksum
How to use checksums
7a4e757a3bd6efc0fe61dd221fb83dd10e25d03486bc71ce6a0183f29070901a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

Security for ton-client-py 1.0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page