Python API for TON (Telegram Open Network)
Project description
PyTONLib
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 with Ubuntu OS. To install package run
pip install pytonlib
Docker
Also, the library can be installed inside the Docker. To deploy the example of service with Docker Compose run:
docker-compose -f docker-compose.jupyter.yaml build
docker-compose -f docker-compose.jupyter.yaml up -d
This command runs Jupyter Notebook on port 3100 (http://localhost:3100).
Examples
- Connecting to the first LiteServer in mainnet config:
import requests
import asyncio
from pytonlib import TonlibClient
# downloading mainnet config
ton_config = requests.get('https://newton-blockchain.github.io/global.config.json').json()
# get running event loop
loop = asyncio.get_running_loop()
# init TonlibClient
client = TonlibClient(ls_index=0, # choose LiteServer index to connect
config=ton_config,
keystore='/tmp/ton_keystore',
loop=loop)
# init tonlibjson
await client.init(max_restarts=None)
- 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytonlib-0.0.1.tar.gz
(2.2 MB
view details)
Built Distribution
File details
Details for the file pytonlib-0.0.1.tar.gz
.
File metadata
- Download URL: pytonlib-0.0.1.tar.gz
- Upload date:
- Size: 2.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 116c804797c1c4e719167e15dac5077db5e861751cb574666084a67fb8d0d32a |
|
MD5 | e7150569c0310f81817edac2cef9ab86 |
|
BLAKE2b-256 | 31c2d7786423b1dba56cab1739c7993195246b8043f98ce4bcdb0b47b8a96607 |
File details
Details for the file pytonlib-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pytonlib-0.0.1-py3-none-any.whl
- Upload date:
- Size: 2.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 453db4b25720064dd48588c673e7e9c0352944864468e540a18d2b216d708375 |
|
MD5 | b762f3126c7f564260e3ccdd18893a0c |
|
BLAKE2b-256 | 44153d6139d3fec17aa94fddb4180d7997f8261c678fa4eb49ad505fe51f352d |