<!-- iframe showing the search results (closed by default) -->
<divid="MSearchResultsWindow">
<iframesrc="javascript:void(0)"frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<divclass="PageDoc"><divclass="header">
<divclass="headertitle">
<divclass="title">TDLib </div></div>
</div><!--header-->
<divclass="contents">
<divclass="textblock"><p>TDLib (Telegram Database library) is a cross-platform library for building <ahref="https://telegram.org">Telegram</a> clients. It can be easily used from almost any programming language.</p>
<h2>Table of Contents</h2>
<ul>
<li><ahref="#features">Features</a></li>
<li><ahref="#usage">Examples and documentation</a></li>
<li><ahref="#dependencies">Dependencies</a></li>
<li><ahref="#building">Building</a></li>
<li><ahref="#using-cxx">Using in CMake C++ projects</a></li>
<li><ahref="#using-java">Using in Java projects</a></li>
<li><ahref="#using-dotnet">Using in .NET projects</a></li>
<li><ahref="#using-json">Using with other programming languages</a></li>
<li><b>Cross-platform</b>: <code>TDLib</code> can be used on Android, iOS, Windows, macOS, Linux, FreeBSD, OpenBSD, NetBSD, illumos, Windows Phone, WebAssembly, watchOS, tvOS, visionOS, Tizen, Cygwin. It should also work on other *nix systems with or without minimal effort.</li>
<li><b>Multilanguage</b>: <code>TDLib</code> can be easily used with any programming language that is able to execute C functions. Additionally, it already has native Java (using <code>JNI</code>) bindings and .NET (using <code>C++/CLI</code> and <code>C++/CX</code>) bindings.</li>
<li><b>High-performance</b>: in the <ahref="https://core.telegram.org/bots/api">Telegram Bot API</a>, each <code>TDLib</code> instance handles more than 25000 active bots simultaneously.</li>
<li><b>Well-documented</b>: all <code>TDLib</code> API methods and public interfaces are fully documented.</li>
<li><b>Consistent</b>: <code>TDLib</code> guarantees that all updates are delivered in the right order.</li>
<li><b>Reliable</b>: <code>TDLib</code> remains stable on slow and unreliable Internet connections.</li>
<li><b>Secure</b>: all local data is encrypted using a user-provided encryption key.</li>
<li><b>Fully-asynchronous</b>: requests to <code>TDLib</code> don't block each other or anything else, responses are sent when they are available.</li>
</ul>
<p><aclass="anchor"id="usage"></a></p><h2>Examples and documentation</h2>
<p>See our <ahref="https://core.telegram.org/tdlib/getting-started">Getting Started</a> tutorial for a description of basic TDLib concepts.</p>
<p>Take a look at our <ahref="https://github.com/tdlib/td/blob/master/example/README.md#tdlib-usage-and-build-examples">examples</a>.</p>
<p>See a <ahref="https://tdlib.github.io/td/build.html">TDLib build instructions generator</a> for detailed instructions on how to build TDLib.</p>
<p>See description of our <ahref="#using-json">JSON</a>, <ahref="#using-cxx">C++</a>, <ahref="#using-java">Java</a> and <ahref="#using-dotnet">.NET</a> interfaces.</p>
<p>See the <ahref="https://github.com/tdlib/td/blob/master/td/generate/scheme/td_api.tl">td_api.tl</a> scheme or the automatically generated <ahref="https://core.telegram.org/tdlib/docs/td__api_8h.html">HTML documentation</a> for a list of all available <code>TDLib</code><ahref="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html">methods</a> and <ahref="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_object.html">classes</a>.</p>
<p>The simplest way to build <code>TDLib</code> is to use our <ahref="https://tdlib.github.io/td/build.html">TDLib build instructions generator</a>. You need only to choose your programming language and target operating system to receive complete build instructions.</p>
<p>In general, you need to install all <code>TDLib</code><ahref="#dependencies">dependencies</a>, enter directory containing <code>TDLib</code> sources and compile them using CMake:</p>
<divclass="fragment"><divclass="line">mkdir build</div><divclass="line">cd build</div><divclass="line">cmake -DCMAKE_BUILD_TYPE=Release ..</div><divclass="line">cmake --build .</div></div><!-- fragment --><p>To build <code>TDLib</code> on low memory devices you can run <ahref="https://github.com/tdlib/td/blob/master/SplitSource.php">SplitSource.php</a> script before compiling main <code>TDLib</code> source code and compile only needed targets: </p><divclass="fragment"><divclass="line">mkdir build</div><divclass="line">cd build</div><divclass="line">cmake -DCMAKE_BUILD_TYPE=Release ..</div><divclass="line">cmake --build . --target prepare_cross_compiling</div><divclass="line">cd ..</div><divclass="line">php SplitSource.php</div><divclass="line">cd build</div><divclass="line">cmake --build . --target tdjson</div><divclass="line">cmake --build . --target tdjson_static</div><divclass="line">cd ..</div><divclass="line">php SplitSource.php --undo</div></div><!-- fragment --><p> In our tests clang 6.0 with libc++ required less than 500 MB of RAM per file and GCC 4.9/6.3 used less than 1 GB of RAM per file.</p>
<p><aclass="anchor"id="using-cxx"></a></p><h2>Using in CMake C++ projects</h2>
<p>For C++ projects that use CMake, the best approach is to build <code>TDLib</code> as part of your project or to install it system-wide.</p>
<p>There are several libraries that you could use in your CMake project:</p>
<ul>
<li>Td::TdJson, Td::TdJsonStatic— dynamic and static version of a JSON interface. This has a simple C interface, so it can be easily used with any programming language that is able to execute C functions. See <ahref="https://core.telegram.org/tdlib/docs/td__json__client_8h.html">td_json_client</a> documentation for more information.</li>
<li>Td::TdStatic — static library with C++ interface for general usage. See <ahref="https://core.telegram.org/tdlib/docs/classtd_1_1_client_manager.html">ClientManager</a> and <ahref="https://core.telegram.org/tdlib/docs/classtd_1_1_client.html">Client</a> documentation for more information.</li>
<p>For example, part of your CMakeLists.txt may look like this: </p><divclass="fragment"><divclass="line">add_subdirectory(td)</div><divclass="line">target_link_libraries(YourTarget PRIVATE Td::TdStatic)</div></div><!-- fragment --><p>Or you could install <code>TDLib</code> and then reference it in your CMakeLists.txt like this: </p><divclass="fragment"><divclass="line">find_package(Td 1.8.36 REQUIRED)</div><divclass="line">target_link_libraries(YourTarget PRIVATE Td::TdStatic)</div></div><!-- fragment --><p> See <ahref="https://github.com/tdlib/td/blob/master/example/cpp/CMakeLists.txt">example/cpp/CMakeLists.txt</a>.</p>
<p><aclass="anchor"id="using-java"></a></p><h2>Using in Java projects</h2>
<p><code>TDLib</code> provides native Java interface through JNI. To enable it, specify option <code>-DTD_ENABLE_JNI=ON</code> to CMake.</p>
<p>See <ahref="https://github.com/tdlib/td/tree/master/example/java">example/java</a> for example of using <code>TDLib</code> from Java and detailed build and usage instructions.</p>
<p><aclass="anchor"id="using-dotnet"></a></p><h2>Using in .NET projects</h2>
<p><code>TDLib</code> provides native .NET interface through <code>C++/CLI</code> and <code>C++/CX</code>. To enable it, specify option <code>-DTD_ENABLE_DOTNET=ON</code> to CMake. .NET Core supports <code>C++/CLI</code> only since version 3.1 and only on Windows, so if older .NET Core is used or portability is needed, then <code>TDLib</code> JSON interface should be used through P/Invoke instead.</p>
<p>See <ahref="https://github.com/tdlib/td/tree/master/example/csharp">example/csharp</a> for example of using <code>TDLib</code> from C# and detailed build and usage instructions. See <ahref="https://github.com/tdlib/td/tree/master/example/uwp">example/uwp</a> for example of using <code>TDLib</code> from C# UWP application and detailed build and usage instructions for Visual Studio Extension "TDLib for Universal Windows Platform".</p>
<p>When <code>TDLib</code> is built with <code>TD_ENABLE_DOTNET</code> option enabled, <code>C++</code> documentation is removed from some files. You need to checkout these files to return <code>C++</code> documentation back: </p><divclass="fragment"><divclass="line">git checkout td/telegram/Client.h td/telegram/Log.h td/tl/TlObject.h</div></div><!-- fragment --><p><aclass="anchor"id="using-json"></a></p><h2>Using from other programming languages</h2>
<p><code>TDLib</code> provides efficient native C++, Java, and .NET interfaces. But for most use cases we suggest to use the JSON interface, which can be easily used with any programming language that is able to execute C functions. See <ahref="https://core.telegram.org/tdlib/docs/td__json__client_8h.html">td_json_client</a> documentation for detailed JSON interface description, the <ahref="https://github.com/tdlib/td/blob/master/td/generate/scheme/td_api.tl">td_api.tl</a> scheme or the automatically generated <ahref="https://core.telegram.org/tdlib/docs/td__api_8h.html">HTML documentation</a> for a list of all available <code>TDLib</code><ahref="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html">methods</a> and <ahref="https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_object.html">classes</a>.</p>
<p><code>TDLib</code> JSON interface adheres to semantic versioning and versions with the same major version number are binary and backward compatible, but the underlying <code>TDLib</code> API can be different for different minor and even patch versions. If you need to support different <code>TDLib</code> versions, then you can use a value of the <code>version</code> option to find exact <code>TDLib</code> version to use appropriate API methods.</p>
<p>See <ahref="https://github.com/tdlib/td/blob/master/example/python/tdjson_example.py">example/python/tdjson_example.py</a> for an example of such usage.</p>
<p><code>TDLib</code> is licensed under the terms of the Boost Software License. See <ahref="http://www.boost.org/LICENSE_1_0.txt">LICENSE_1_0.txt</a> for more information. </p>