td
Cross-platform library for building Telegram clients
TDLib is a cross-platform C++ library that handles all the low-level Telegram networking, encryption, and local storage so you can build Telegram clients or bots in virtually any programming language.
TDLib, short for Telegram Database library, is a C++ library that handles the low-level work of connecting to Telegram. If you want to build your own Telegram client app or bot, TDLib takes care of the network connection, message encryption, and storing chat data locally, so you do not have to implement those details yourself.
Although the library is written in C++, it is designed to be called from almost any programming language. It exposes a JSON interface based on a simple C function, which means you can drive it from Python, Go, JavaScript, or anything else that can call C functions. For Java and .NET projects, native bindings are available through JNI and C++/CLI respectively, avoiding the need to go through JSON. All API requests are fully asynchronous, so calls to TDLib do not block each other.
The library runs on a wide range of platforms: Android, iOS, Windows, macOS, Linux, FreeBSD, WebAssembly, watchOS, tvOS, Tizen, and others. All locally stored data is encrypted with a key you supply. The library is also used internally by Telegram for their Bot API server, where a single instance handles more than 37,000 active bots at the same time.
Building TDLib requires a C++17 compiler, OpenSSL, zlib, CMake, and gperf. The project provides an online build instructions generator where you select your target language and operating system and receive a step-by-step build guide. Examples for C++, Java, and C# are included in the repository. The API follows semantic versioning, so libraries built against one minor version remain binary compatible with others sharing the same major version number.
Where it fits
- Build a custom Telegram client for desktop, mobile, or web that connects to Telegram's servers without implementing the protocol yourself.
- Create a Telegram bot in Python or JavaScript by calling TDLib's JSON API from your preferred language.
- Integrate Telegram messaging into an existing business application using TDLib as the low-level engine.
- Run a bot management service that handles thousands of concurrent bots inside a single TDLib instance.