Essential Libraries and Tools for Python on TON

Article image

According to Statista, Python is the 3rd most popular programming language in the world, with over 49% of developers in 2023 using Python. With this in mind, and knowing our goal of building the world’s most used blockchain ecosystem, we can not afford to overlook Python’s importance and potential in building The Open Network (TON).

Although the Tact programming language lies at the core of TON, our community continuously develops new Python libraries to allow Python developers to contribute to the growth of the TON Ecosystem.

In this article, we’ll share the most popular Python libraries you can leverage on TON. Please note that some of these libraries are still being developed by their authors but regardless provide a vault of precious information, while others might be abandoned.

Before you start, we recommend reading our article on setting up a development environment on TON.

Python Libraries for The Open Network

We will not list out the libraries in any particular order of how they should be used, so feel free to scroll through to find what you’re looking for.

ADNL Transport

Abstract Datagram Network Layer (ADNL) is the cornerstone of TON. This decentralized network protocol built atop UDP in the current IPv4 framework, set to transition to IPv6 in the future, facilitates swift and lightweight data transfers. You have an option to switch to the more reliable TCP if UDP becomes inaccessible. ADNL prioritizes speed and direct peer interactions over guaranteed delivery. You can find more info in the ADNL Protocol documentation

  • Pythoniq by Yungwine – A Python SDK for the TON Blockchain that extends pytoniq-core with native LiteClient and ADNL over UDP, DHT, and RLDP (in the future). It is considered by many as the flagship Python library for TON.

  • mytonlib by Igroman787 – Another excellent native library for working with The Open Network without using libtonlibjson.so. As it is a native library, the speed is slightly throttled. This library was written based on the TON Deep by xssnick.

TonLib Wrapper

TonLib Wrapper is a library that allows you to interact with TON directly via the ADNL protocol without using any HTTP API. It is based on tonlibjson, which is a JSON interface to tonlib, a library that implements TON’s lite client functionality.

There are different TonLib Wrappers for different programming languages, such as Python, .NET, and JavaScript.

  • PyTONLib – This is a standalone Python library based on libtonlibjson. The functionality is similar to the ton-http-api, but with a few restrictions - a client can connect to only one LiteServer; a client is asynchronous; no requests cache.

HTTP API or TonLib Wrapper (both supported)

The following libraries can be used with both TonLib Wrapper or directly with HTTP API; whichever you prefer.

  • TonTools by Yungwine – A high-level OOP library for Python that offers a ton of functionality, such as scanning custom contracts and running get methods, creating, deploying and scanning wallets, NFT collections scanning, scanning of Jettons and Jetton wallets, transaction scanning in raw and user-friendly forms, and much more.

  • TONsdk by sasha1618 (tonfactory), Yungwine, Psylopunk– This low-level library contains a lot of useful information, but the code is unfinished and messy. Unfortunately, this library seems to be no longer under development, and it is now abandoned.

TON C++ Wrapper

  • Tonpy by Disintar – A Python package that provides data structures and API to interact with TON. Tonpy is separated into two packages: C++ bindings and the main package that takes pre-built binaries compiled by workflow and creates a complete Python package with some Python code on top of C++ bindings.

TON Connect

TON Connect is a communication protocol between wallets and apps in the TON ecosystem. Wallets do not need to build walled-garden ecosystems themselves, while the apps do not need to take the risk of holding end users’ accounts. TON Connect aims to offer a seamless user experience between the wallets and the apps. Read our recent article, TON Connect – The Future Without Passwords, to better understand the concept and its benefits. Click here for the TON Connect Github repo.

  • PyTon Connect by XaBbl4 – A Python SDK for TON Connect 2.0. This library is the analog of the @tonconnect/sdk library, and you can use it to connect your app to TON wallets via the TON Connect protocol. You can find more details and the protocol specification in the docs.

  • TON Connect for Python by ClickoTON Foundation – Another library for connecting TON Connect to Python apps. The library contains 34 commits and seems to be under active development, with the last activity just over two weeks ago.

Developments for TON on Python

Here, you can find a few more handy tools to help you with Python on TON.

  • TON Indexer - Helps you store blocks, transactions, and messages in the Postgres database and provides a convenient API.

  • MyTonCtrl – A console application that is a convenient wrapper for fift, lite-client, and validator-engine-console. It has been specifically developed to streamline wallet, domain, and validator management tasks on the Linux operating system.

  • HTTP API for The Open Network – Since TON nodes use their own ADNL binary transport protocol, an intermediate service is needed for an HTTP connection. TON HTTP API is such an intermediate service; receiving requests via HTTP, it accesses the lite servers of the TON network using tonlibjson. You can use the ready-made toncenter.com service or start your own instance.

Deprecated Libraries

While we do not recommend using these libraries as they’re now obsolete and abandoned, you can still search through them to see if there is any valuable information.

  • TVM Value Types – Now replaced by Pythoniq, this library works with basic primitives of TON (Cell, HashMap). The library is a collection of utilities that work with seven value types of TON virtual machine - Integer, Cell, Tuple, Null, Slice, Builder, and Continuation.

  • Pytonlib by Psylopunk - Now completely abandoned, this library allows you to work with the TON API from Python. It offers a range of functionalities such as creating and importing wallets, getting wallet balances and transactions, transferring coins, executing methods of smart contracts, and transferring NFTs.

Others

Last but not least, a library that doesn’t fit any of the above-mentioned categories but still packs a collection of useful features.

  • Rift – A full-stack development framework for TON that makes it easy for developers to use Python to develop, test, and deploy smart contracts on TON. With Rift, you can leverage the simplicity and versatility of Python to build and interact with TON without having to learn the complexities of FunC or Fift. For examples of how Rift simplifies these processes, visit Rift's website.