Skip to main content

PyTONLib

PyPI PyPI - Python Version Github last commit

This is standalone Python library based on libtonlibjson, the functionality is similar to the ton-http-api with the following restrictions:

  • a client can connect to only one LiteServer;
  • a client is asyncronious;
  • no requests cache.

Installation

From PyPi

Currently, the library works for Windows, Mac and Linux only on Intel CPUs:

  • (Windows) Install OpenSSL v1.1.1 for Win64 from here.
  • Install Python 3 package: pip3 install pytonlib.

Docker

In this repo Compose file is provided to deploy the example of service with pytonlib:

docker-compose -f docker-compose.jupyter.yaml build
docker-compose -f docker-compose.jupyter.yaml up -d

Jupyter Notebook will be available on port 3100 (http://localhost:3100).

Examples

We recommend to use IPython or Jupyter Notebook for prototyping because they allow to run async code. An example of running async code from script could be found in the end of this section.

  • Connecting to the first LiteServer in mainnet config:
import requests
import asyncio
from pathlib import Path

from pytonlib import TonlibClient


# downloading mainnet config
ton_config = requests.get('https://ton.org/global.config.json').json()

# create keystore directory for tonlib
keystore_dir = '/tmp/ton_keystore'
Path(keystore_dir).mkdir(parents=True, exist_ok=True)

# init TonlibClient
client = TonlibClient(ls_index=0, # choose LiteServer index to connect
                      config=ton_config,
                      keystore=keystore_dir)

# init tonlibjson
await client.init()
  • Reading blocks info:
masterchain_info = await client.get_masterchain_info()
block_header = await client.get_block_header(**masterchain_info['last'])
shards = await client.get_shards(master_seqno=masterchain_info['last']['seqno'])
  • Reading Block Transactions for masterchain block:
masterchain_info = await client.get_masterchain_info()
txs = await client.get_block_transactions(**masterchain_info['last'], count=10)
  • Running async code from script:
import requests
import asyncio
from pathlib import Path

from pytonlib import TonlibClient


async def main():
    loop = asyncio.get_running_loop()
    ton_config = requests.get('https://ton.org/global.config.json').json()

    # create keystore directory for tonlib
    keystore_dir = '/tmp/ton_keystore'
    Path(keystore_dir).mkdir(parents=True, exist_ok=True)
    
    # init TonlibClient
    client = TonlibClient(ls_index=0, # choose LiteServer index to connect
                          config=ton_config,
                          keystore=keystore_dir,
                          loop=loop)
    
    # init tonlibjson
    await client.init()
    
    # reading masterchain info
    masterchain_info = await client.get_masterchain_info()

    # closing session
    await client.close()


if __name__ == '__main__':
    asyncio.run(main())

Running tests

To run tests in asyncio mode use the following command:

PYTHONPATH=./ pytest --asyncio-mode=strict tests/

Metadata

Release files for rift-tonlib 0.0.3

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

Source distribution (sdist)

Source distribution for rift-tonlib 0.0.3
File Size Uploaded
rift-tonlib-0.0.3.tar.gz 11.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for rift-tonlib 0.0.3
File Interpreter ABI Platform
rift_tonlib-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 23.1 MB

Release files / rift-tonlib-0.0.3.tar.gz

Download URL rift-tonlib-0.0.3.tar.gz
Size 11.5 MB
Tags Source
SHA-256 checksum
How to use checksums
715b8211c91c6d236565c6d37428f91b071f45d377a8985b0d5a0fe15dfadb4b
BLAKE2b-256 checksum
How to use checksums
2128c7020b460066ba808a2bcc1657f93f80acc846c6e9fecb061b633cfe7d2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / rift_tonlib-0.0.3-py3-none-any.whl

Download URL rift_tonlib-0.0.3-py3-none-any.whl
Size 11.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
9df043cf7342bd9144cb0d386a5368907e85d2a91e5fc50bbc696ba8cb693e1a
BLAKE2b-256 checksum
How to use checksums
e09df03df383752cb3dfb0a2bc3729dc0d6e668e1c85126984a2d6f931e1b66b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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