Developer documentation

TDLib language and platform examples

Find TDLib bindings, build instructions and source examples for Python, JavaScript, Go, Java, C++, Swift, Dart and more, with official references on GetTGAPI.

GetTGAPI editorial teamUpdated
TDLib documentationReviewed

Source revision a94b83d67ab4 · TDLib contributors · BSL-1.0

Based on official sources and independently maintained by GetTGAPI. Documentation and glossary →

On this page
  1. GetTGAPI reading notes
  2. TDLib usage and build examples
  3. Using TDLib in Python projects
  4. Using TDLib in JavaScript projects
  5. Using TDLib in Go projects
  6. Using TDLib in Java projects
  7. Using TDLib in Kotlin projects
  8. Using TDLib in C# projects
  9. Using TDLib in C++ projects
  10. Using TDLib in Swift projects
  11. Using TDLib in Objective-C projects
  12. Using TDLib in Object Pascal projects with Delphi and Lazarus
  13. Using TDLib in Dart projects
  14. Using TDLib in Rust projects
  15. Using TDLib in Erlang projects
  16. Using TDLib in PHP projects
  17. Using TDLib in Lua projects
  18. Using TDLib in D projects
  19. Using TDLib in Ruby projects
  20. Using TDLib in Crystal projects
  21. Using TDLib in Haskell projects
  22. Using TDLib in Nim projects
  23. Using TDLib in Clojure projects
  24. Using TDLib in Emacs Lisp projects
  25. Using TDLib in Elixir projects
  26. Using TDLib in Vala projects
  27. Using TDLib from 1С:Enterprise
  28. Using TDLib in C projects
  29. Using TDLib in Assembly projects
  30. Using TDLib from G projects
  31. Using TDLib from other programming languages

GetTGAPI reading notes

Find language bindings and client examples listed in the TDLib documentation. Third-party libraries and clients listed upstream are not necessarily maintained by Telegram, and their current security or compatibility has not been verified by GetTGAPI. Check each repository’s maintenance, license and supported TDLib version before choosing a dependency.

This index identifies interfaces and examples; it does not replace their installation guides. Start with the TDLib overview and build reference, then locate your language. For Python and Java, follow the development guide. Historical development times and project assessments belong to the pinned upstream text.

TDLib usage and build examples

This directory contains basic examples of TDLib usage from different programming languages and examples of library building for different platforms. If you are looking for documentation of all available TDLib methods, see the td_api.tl scheme or the automatically generated HTML documentation for a list of all available TDLib methods and classes. Also, take a look at our Getting Started tutorial for a description of basic TDLib concepts.

TDLib can be easily used from almost any programming language on any platform. See a TDLib build instructions generator for detailed instructions on how to build TDLib. Choose your preferred programming language to see examples of usage and a detailed description:

Using TDLib in Python projects

TDLib can be used from Python through the JSON interface.

Convenient Python wrappers already exist for our JSON interface.

If you use Python >= 3.6, take a look at python-telegram. The wrapper uses the full power of asyncio, has a good documentation and has several examples. It can be installed through pip or used in a Docker container. You can also try a fork python-telegram of this library.

If you want to use TDLib with asyncio and Python >= 3.9, take a look at aiotdlib or Pytdbot (built on AYMENJD/tdjson, a high-performance TDLib binding).

If you want to use TDLib with SidusAI, take a look at sidusai-tdlib.

For older Python versions you can use pytdlib. This wrapper contains generator for TDLib API classes and basic interface for interaction with TDLib.

You can also check out example/python/tdjson_example.py, tdlib-python, or Python Wrapper TDLib for some basic examples of TDLib JSON interface integration with Python.

Using TDLib in JavaScript projects

TDLib can be compiled to WebAssembly and used in a browser from JavaScript. See tdweb as a convenient wrapper for TDLib in a browser and telegram-react as an example of a TDLib-based Telegram client.

See also Svelte-tdweb-starter - Svelte wrapper for tdweb, and Telegram-Photoframe - a web application that displays your preferred group or channel as Photoframe.

TDLib can be used from Node.js through the JSON interface.

Convenient Node.js wrappers already exist for our JSON interface. For example, take a look at Airgram – modern TDLib framework for TypeScript/JavaScript, or at tdl, which provides a convenient, fully-asynchronous interface for interaction with TDLib and contains a bunch of examples.

You can also see TdNode, tglib, node-tdlib, tdlnode, Paper Plane, or node-tlg for other examples of TDLib JSON interface integration with Node.js.

See also the source code of DIBgram - an unofficial Telegram web application which looks like Telegram Desktop.

TDLib can be used also from NativeScript through the JSON interface. See nativescript-tglib as an example of a NativeScript library for building Telegram clients.

TDLib can also be used from React Native on iOS and Android. See react-native-tdlib as an example of a React Native library for building Telegram clients.

Using TDLib in Go projects

TDLib can be used from the Go programming language through the JSON interface and Cgo, and can be linked either statically or dynamically.

Convenient Go wrappers already exist for our JSON interface. For example, take a look at github.com/AshokShau/gotdbot, github.com/zelenin/go-tdlib, or github.com/Arman92/go-tdlib, which provide a convenient TDLib client, a generator for TDLib API classes and contain many examples.

You can also see github.com/aliforever/go-tdlib for another examples of TDLib JSON interface integration with Go.

Using TDLib in Java projects

TDLib can be used from the Java programming language through native JNI binding.

We provide a generator for JNI bridge methods and Java classes for all TDLib API methods and objects. See example/java for an example of using TDLib from desktop Java along with detailed building and usage instructions. See example/android for detailed build instructions for Android.

Using TDLib in Kotlin projects

TDLib can be used from the Kotlin/JVM programming language through same way as in Java.

See tdl-coroutines - Kotlin Multiplatform coroutine-based wrapper for TDLib.

See also td-ktx - Kotlin coroutines wrapper for TDLib.

You can also use ktd library with Kotlin-specific bindings.

Using TDLib in C# projects

TDLib provides a native .NET interface through C++/CLI and C++/CX. See tdlib-netcore for a SWIG-like binding with automatically generated classes for TDLib API. See example/uwp for an example of building TDLib SDK for the Universal Windows Platform and an example of its usage from C#. See example/csharp for an example of building TDLib with C++/CLI support and an example of TDLib usage from C# on Windows.

If you want to write a cross-platform C# application using .NET Core, see tdsharp. It uses our JSON interface, provides an asynchronous interface for interaction with TDLib, automatically generated classes for TDLib API and has some examples.

Also, see Unigram, which is a full-featured client rewritten from scratch in C# using TDLib SDK for Universal Windows Platform in less than 2 months, egram.tel – a cross-platform Telegram client written in C#, .NET Core, ReactiveUI and Avalonia, or telewear - a Telegram client for Samsung watches.

Using TDLib in C++ projects

TDLib has a simple and convenient C++11-interface for sending and receiving requests and can be statically linked to your application.

See example/cpp for an example of TDLib usage from C++. td_example.cpp contains an example of authorization, processing new incoming messages, getting a list of chats and sending a text message.

See also the source code of Fernschreiber and Depecher – Telegram apps for Sailfish OS, TELEports – a Qt-client for Ubuntu Touch, tdlib-purple - Telegram plugin for Pidgin, or MeeGram - a Telegram client for Nokia N9, TDLib Native Sciter Extension - a Sciter native extension for TDLib's JSON interface, all of which are based on TDLib.

Using TDLib in Swift projects

TDLib can be used from the Swift programming language through the JSON interface and can be linked statically or dynamically.

See example/ios for an example of building TDLib for iOS, watchOS, tvOS, visionOS, and macOS.

See TDLibKit, tdlib-swift, or TDLib-iOS, which provide convenient TDLib clients with automatically generated and fully-documented classes for all TDLib API methods and objects.

See also the source code of Moc - a native and powerful macOS and iPadOS Telegram client, optimized for moderating large communities and personal use.

See example/swift for an example of a macOS Swift application.

Using TDLib in Objective-C projects

TDLib can be used from the Objective-C programming language through JSON interface and can be linked statically or dynamically.

See example/ios for an example of building TDLib for iOS, watchOS, tvOS, visionOS, and macOS.

Using TDLib in Object Pascal projects with Delphi and Lazarus

TDLib can be used from the Object Pascal programming language through the JSON.

See tdlib-delphi for an example of TDLib usage from Delphi.

See tdlib-lazarus for an example of TDLib usage from Lazarus.

Using TDLib in Dart projects

TDLib can be used from the Dart programming language through the JSON interface and a Dart Native Extension or Dart FFI.

See tdlib-dart, which provide convenient TDLib client with automatically generated and fully-documented classes for all TDLib API methods and objects.

See also dart_tdlib, flutter_libtdjson, Dart wrapper for TDLib, or tdlib_bindings for an example of a TDLib Dart bindings through FFI.

See Telegram Client library, project.scarlet, tdlib, tdlib-dart, FluGram, or telegram-service for examples of using TDLib from Dart.

See also telegram-flutter - Telegram client written in Dart, and f-Telegram - Flutter Telegram client.

Using TDLib in Rust projects

TDLib can be used from the Rust programming language through the JSON interface.

See rust-tdlib, or tdlib, which provide convenient TDLib clients with automatically generated and fully-documented classes for all TDLib API methods and objects.

See rtdlib, tdlib-rs, tdlib-futures, tdlib-sys, tdjson-rs, rust-tdlib, or tdlib-json-sys for examples of TDLib Rust bindings.

Also, see Paper Plane – a Telegram client written in Rust and GTK.

Using TDLib in Erlang projects

TDLib can be used from the Erlang programming language through the JSON interface.

See erl-tdlib for an example of TDLib Erlang bindings.

Using TDLib in PHP projects

If you use modern PHP >= 7.4, you can use TDLib via a PHP FFI extension. For example, take a look at ffi-tdlib, tdlib-php-ffi, or tdjson_example - FFI-based TDLib wrappers.

See also tdlib-schema - a generator for TDLib API classes.

For older PHP versions you can use TDLib by wrapping its functionality in a PHP extension.

See phptdlib, tdlib, or PIF-TDPony for examples of such extensions which provide access to TDLib from PHP.

See tdlib-bundle – a Symfony bundle based on phptdlib.

Using TDLib in Lua projects

TDLib can be used from the Lua programming language through the JSON interface.

See luajit-tdlib, tdlua, or luajit-tdlib for examples of TDLib Lua bindings and basic usage examples.

See also tdbot, which makes all TDLib features available from Lua scripts.

Using TDLib in D projects

TDLib can be used from the D programming language through the JSON interface.

See d-tdlib-service for an example of TDLib D bindings.

Using TDLib in Ruby projects

TDLib can be used from the Ruby programming language through the JSON interface.

See tdlib-ruby for examples of Ruby bindings and a client for TDLib.

Using TDLib in Crystal projects

TDLib can be used from the Crystal programming language through the JSON interface.

See Proton for examples of Crystal bindings with automatically generated types for all TDLib API methods and objects.

Using TDLib in Haskell projects

TDLib can be used from the Haskell programming language.

See haskell-tdlib or tdlib for examples of such usage and Haskell wrappers for TDLib. This library contains automatically generated Haskell types for all TDLib API methods and objects.

Using TDLib in Nim projects

TDLib can be used from the Nim programming language.

See telenim for example of such usage and a Nim wrapper for TDLib.

Using TDLib in Clojure projects

TDLib can be used from the Clojure programming language through the JSON interface.

See clojure-tdlib-json-wrapper for an example of TDLib Clojure bindings.

Using TDLib in Emacs Lisp projects

TDLib can be used from the Emacs Lisp programming language.

See telega.el for an example of a GNU Emacs Telegram client.

Using TDLib in Elixir projects

TDLib can be used from the Elixir programming language.

See Elixir TDLib for an example of such usage and an Elixir client for TDLib. The library contains automatically generated and fully-documented classes for all TDLib API methods and objects.

Using TDLib in Vala projects

TDLib can be used from the Vala programming language.

See TDLib Vala for an example of such usage.

Using TDLib from 1С:Enterprise

TDLib can be used from the 1С programming language.

See TDLib bindings for 1С:Enterprise and e1c.tAgents for examples of such usage.

Using TDLib in C projects

TDLib can be used from the C programming language through the JSON interface and can be linked statically or dynamically.

See easy-tg for an example of such usage.

You can also try to use our C client, which was used by the private TDLib-based version of telegram-cli.

Using TDLib in Assembly projects

TDLib can be used from Assembly through the JSON interface.

See nasm_tdjson_example.

You can also see gas_tdjson_example, arm_tdjson_example, arm64_tdjson_example.

Using TDLib from G projects

TDLib can be used from the G graphical programming language in LabVIEW development environment.

See TDLib bindings for LabVIEW for examples of such usage.

Using TDLib from other programming languages

You can use TDLib from any other programming language using tdbot or TDLib JSON CLI, which provide a command line tool for interaction with TDLIb using the JSON interface through stdin and stdout. You can use this method to use TDLib, for example, from Brainfuck (unfortunately, we haven't seen examples of sending a Telegram message through TDLib on Brainfuck yet).

Alternatively, you can use the TDLib JSON interface directly from your programming language.

Feel free to create an issue, if you have created a valuable TDLib binding or a TDLib client in some programming language and want it to be added to this list of examples.

Source license and attribution · BSL-1.0

TDLib contributors · Full license file

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.