TON (The Open Network) Python SDK
Mehdi Baneshi
Remote Full-stack Contractor | Rust, Python, TypeScript | Next.js, FastAPI, Actix-web | Open to Crypto Payments
Python SDK options available for developing applications on the TON (The Open Network) blockchain. We'll focus on the most prominent and actively maintained libraries, examining their capabilities, community, and other relevant information.
Key Python SDKs for TON Development
1. ton-py (Official Python SDK by TON Foundation)
Capabilities:
*Low-Level Interaction:** Provides direct access to the TON blockchain's RPC API. This means you can perform core functions like:
* Sending and receiving transactions.
* Querying account balances, history, and state.
* Working with smart contracts (TON Smart Contracts are typically written in FunC or Tact, and you use this SDK to interact with them).
* Creating and managing wallets.
* Deploying smart contracts.
*BOC (Bag of Cells) Manipulation:** Includes tools to work with BOCs which is the fundamental data serialization format on TON.
*TON Client Interface:** This is the lowest level interface, it talks directly to a TON node via the TON API.
*High-level abstractions**: Provides higher-level classes and functions that reduce boilerplate code.
*Support for TL-B Schema:** Facilitates encoding and decoding data according to TON's TL-B schema.
*Support for TACT and Func:** It has support for interaction with smart contracts written in func and tact.
*Community:**
*Official and Active:** It's the official Python SDK, so it enjoys direct support from the TON Foundation and has an active community of contributors.
*Good Documentation:** The documentation is fairly comprehensive, making it easier to learn the core concepts.
*Examples:** A good number of examples are provided to make the learning curve easier.
*Strong Support Channel:** Typically, active discussions and assistance are available in the official TON developer community channels (e.g., Telegram).
*Pros:**
*Official Support**: Backed by the TON Foundation for long-term support and development
*High performance**: Provides a direct low-level API, that translates to a high performance.
*Completeness**: It aims to implement all features necessary for TON development.
*Cons:**
*Steeper Learning Curve:** Due to its low-level nature, it can have a steeper learning curve for beginners compared to higher abstraction libraries.
*Verbosity:** Might require writing more code for common tasks compared to libraries that have higher levels of abstractions.
2. **tonsdk (by Disintar)**
*Documentation:** [https://tonsdk.readthedocs.io/en/latest/](https://tonsdk.readthedocs.io/en/latest/)
*Capabilities:**
*Higher Level Abstractions**: Provides a higher level of abstraction compared to ton-py. Which makes development faster and simpler
*Smart Contract Interaction**: Simplifies interaction with smart contracts using classes.
*Account Management**: Manages Keypair generation and account addresses effectively
*Transaction Building**: Simplified functions to create transactions easily.
*Integration**: Good integration with other Python libraries (e.g., asyncio).
*Community:**
*Active:** Has an active community of users and developers.
*Good Documentation:** Comes with comprehensive and readable documentation.
*Well Maintained:** The library is usually well-maintained and has frequent updates.
*Good Examples:** It provides good examples of usage.
*Pros:**
*Faster Development:** High level APIs means faster development time.
*Easier to learn**: Easier to learn and quicker to get started for people new to TON development.
*Good Abstractions**: Good balance between control and ease of use.
*Cons:**
*Dependence on the Underlying Library**: If the ton-py library has some problem or bug, it would indirectly affect tonsdk.
*Less direct control**: As this is not a low level library you have less direct control over the TON API.
3. **pytonlib**
*Documentation:** [https://ton-blockchain.github.io/pytonlib/](https://ton-blockchain.github.io/pytonlib/)
*Capabilities**
*Low Level Access**: Provides low-level API access via tonlib-json library
*Direct Calls**: Facilitates direct calls to TonLib methods.
*Data Handling**: Handles BOC data effectively.
*Multithreading Support**: Supports asynchronous operations using asyncio.
*Integration**: Good integration with the underlying TON C++ library.
*Community:**
*Official**: As it's maintained by TON Foundation, it is more actively developed and maintained.
*Active**: Community support is available through official TON channels.
*Good Documentation**: It has well maintained documentation.
*Examples**: Provides good examples to start.
*Pros:**
*Performance**: Because it's based on the C++ library, it is faster in terms of performance
*Stability**: Good stability and reliability, due to backing from TON Foundation.
*Low Level Access**: Gives fine control over the low level API.
*Cons**:
*More Complex Usage:** More complex and harder to use than higher-level libraries.
*Steeper learning curve**: Due to its low-level nature it has a steeper learning curve.
**Comparison Table**
| Feature | ton-py (Official) | tonsdk (Disintar) | pytonlib |
| --------------------- | ---------------------------------- | ------------------------------ | -----------|
| **Abstraction Level** | Low-level | Higher-level | Low Level |
| **Ease of Use** | Moderate to Difficult | Easier | Difficult |
| **Performance** | Very Good | Good | Very Good |
| **Community** | Strong, Official Support | Active, Good Support | Official, Good |
| **Documentation** | Good | Good | Good |
| **Maintained by** | TON Foundation | Disintar | TON Foundation |
| **Use Cases** | Core blockchain interaction, advanced contract ops, building libraries/tools | Rapid development, simpler apps, faster onboarding | High Performance usage |
| **Pros** | Official, low-level access, feature completeness | Faster development, easier to learn, good abstractions| Fast, Stable, Direct access |
| **Cons** | Steeper learning curve, verbosity | Might hide some underlying complexity, dependency| Complex API, Steep learning curve |
**General Technical Information**
*TON Architecture:** TON is a sharded blockchain with a unique architecture that differs from Ethereum and other platforms. Understanding this architecture is key to effective development.
*TON Smart Contracts:** TON uses its own programming languages, FunC and Tact, for writing smart contracts. Python SDKs are used to interact with these compiled contracts.
*BOC (Bag of Cells):** Understanding the binary serialization format used in TON is essential, especially if you're working with lower-level APIs.
*Network Interaction:** You'll need a TON node endpoint (a local one or a service like GetBlock) to interact with the blockchain.
*Wallet Management:** Python libraries provide methods to manage TON wallets (key generation, address derivation, etc.).
*Transaction Fees:** TON has its own gas model (fees are paid in TON coins). Understanding transaction fees is important for building efficient applications.
*Asynchronous Programming:** Many TON SDKs utilize asyncio for better concurrency. You'll likely encounter this when working with these libraries.
*Testing Environment:** TON provides a test network for developers to test their applications before deploying them to the main network.
**General Information (Non-Technical)**
*Ecosystem Growth:** The TON ecosystem is growing rapidly, meaning that tooling and libraries will continue to improve.
*Community Support:** Active communities are available on Telegram, Reddit, and other platforms where developers discuss development and can help each other.
*Documentation Updates:** Always check official documentation and resources for the latest information, as updates are common in evolving projects like TON.
**Which SDK should you choose?**
*For most use cases, especially when starting out:** tonsdk is a good option because it balances ease of use with enough control.
*For more advanced use cases or if you need direct low-level access:** ton-py is the go-to choice.
*For high-performance apps that need low-level control**: Use pytonlib, though be aware of the higher learning curve.
**Final Recommendations**
1. **Start with tonsdk:** It has a more beginner-friendly API.
2. **Explore ton-py:** Once you have a grasp of TON fundamentals, learn how to use ton-py for more advanced use cases.
3. **Stay Updated:** TON is actively developing. Follow the official GitHub repos, documentation, and community channels to get the latest information and contribute.
4. **Explore pytonlib:** For specific projects that demand the best performance, and if you are comfortable using low level APIs you should explore pytonlib.
By analyzing each library, you can make an educated decision based on the demands of your app and your level of development expertise. Good luck with your TON development journey!