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 pytonlib 0.0.72

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

Source distribution (sdist)

Source distribution for pytonlib 0.0.72
File Size Uploaded
pytonlib-0.0.72.tar.gz 33.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytonlib 0.0.72
File Interpreter ABI Platform
pytonlib-0.0.72-py3-none-any.whl Python 3 none any Details

Total release size: 66.8 MB

Release files / pytonlib-0.0.72.tar.gz

Download URL pytonlib-0.0.72.tar.gz
Size 33.3 MB
Tags Source
SHA-256 checksum
How to use checksums
377ad3f8490f5f4eae9a09085851d2c57a4c94f5dde6f1db5830a10228254989
BLAKE2b-256 checksum
How to use checksums
a03585aa09ab554ba1fe5308ef54f14c5440bb0aa65e5007eb176616c2ef71c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / pytonlib-0.0.72-py3-none-any.whl

Download URL pytonlib-0.0.72-py3-none-any.whl
Size 33.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
815d0762af2e2953c837c8318e8bf06611d54df5d0e6e04c2afdeb0c08bc3b14
BLAKE2b-256 checksum
How to use checksums
678d7d04d0d3d4f84a324da253b3790d263d1f89fae1d773a912a469b5a70f85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.0.72 This release

2 release files

0.0.71

2 release files

0.0.69

2 release files

0.0.67

2 release files

0.0.65

2 release files

0.0.64

2 release files

0.0.61

2 release files

0.0.58

2 release files

0.0.57

2 release files

0.0.54

2 release files

0.0.51

2 release files

0.0.50

2 release files

0.0.49

2 release files

0.0.48

2 release files

0.0.47

2 release files

0.0.46

2 release files

0.0.45

2 release files

0.0.44

2 release files

0.0.43

2 release files

0.0.39

2 release files

0.0.38

2 release files

0.0.37

2 release files

0.0.36

2 release files

0.0.32

2 release files

0.0.30

2 release files

0.0.29

2 release files

0.0.28

2 release files

0.0.27

2 release files

0.0.26

2 release files

0.0.25

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

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