Developer documentation

TDLib Python and Java development guide

Prepare shared libraries, call tdjson from Python, build Java JNI and JSON examples, and troubleshoot dependency errors with this TDLib development guide.

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 Python example
  3. TDLib Java example

GetTGAPI reading notes

This guide covers TDLib integration with Python and Java, including shared-library preparation, JNI/JSON builds and running examples. Replace <path to TDLib sources>, <full path to TDLib sources> and <VCPKG_DIR> with your real paths before running commands.

The upstream JDK >= 1.6 statement is preserved; it is not a recommendation to deploy an obsolete JDK. Verify your selected TDLib release with its build generator and a currently supported JDK. Match the shared library, JVM architecture and dependencies.

Configure your application with your own API ID and API Hash. A GetTGAPI access code cannot replace them. See credential differences, or gettgapi.com for developer-portal assistance.

TDLib Python example

To run this example you need to build TDLib and copy built tdjson shared library to this directory.

After this you can run the example:

python tdjson_example.py

Description of all available classes and methods can be found at td_json_client and td_api documentation.

TDLib Java example

To run this example, you will need installed JDK >= 1.6. For Javadoc documentation generation PHP is needed.

You can find complete build instructions for your operating system at https://tdlib.github.io/td/build.html?language=Java.

In general, the build process looks as follows.

TDLib should be prebuilt with JNI bindings and installed to local subdirectory td/ as follows:

cd <path to TDLib sources>
mkdir jnibuild
cd jnibuild
cmake -DCMAKE_BUILD_TYPE=Release -DTD_ENABLE_JNI=ON -DCMAKE_INSTALL_PREFIX:PATH=../example/java/td ..
cmake --build . --target install

If you want to compile TDLib for 32-bit/64-bit Java on Windows using MSVC, you will also need to add -A Win32/-A x64 option to CMake.

In Windows, use vcpkg toolchain file by adding parameter -DCMAKE_TOOLCHAIN_FILE=<VCPKG_DIR>/scripts/buildsystems/vcpkg.cmake

After this you can compile the example source code:

cd <path to TDLib sources>/example/java
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DTd_DIR=<full path to TDLib sources>/example/java/td/lib/cmake/Td -DCMAKE_INSTALL_PREFIX:PATH=.. ..
cmake --build . --target install

If you want to build JsonClient.java wrapper for JSON interface instead of the native JNI interface, add -DTD_JSON_JAVA=ON option to CMake when building the example.

Compiled TDLib shared library and Java example after that will be placed in bin/ and Javadoc documentation in docs/.

After this you can run the Java example:

cd <path to TDLib sources>/example/java/bin
java '-Djava.library.path=.' org/drinkless/tdlib/example/Example

If you built JSON interface example using -DTD_JSON_JAVA=ON option, then use the command java '-Djava.library.path=.' org/drinkless/tdlib/example/JsonExample instead.

If you receive "Could NOT find JNI ..." error from CMake, you need to specify to CMake path to the installed JDK, for example, "-DJAVA_HOME=/usr/lib/jvm/java-8-oracle/".

If you receive java.lang.UnsatisfiedLinkError with "Can't find dependent libraries", you may also need to copy some dependent shared OpenSSL and zlib libraries to bin/.

Make sure that you compiled the example for the same architecture as your JVM.

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.