python-telegram
Python API for the tdlib library. It helps you build your own Telegram clients.
tdlib connects to Telegram over MTProto, the same protocol the official apps use.
This library signs in as a full Telegram account with a phone number, and it can do what a regular client can do.
It is not a wrapper around the HTTP Bot API.
If you only need a bot, python-telegram-bot is a better fit.
You can still sign in as a bot here by passing bot_token instead of phone.
Installation
This library requires Python 3.10+. Windows is not supported.
pip install python-telegram
See documentation for more details.
tdlib
Four wheels bundle a tdlib binary. Each one works on Python 3.10 through 3.14:
| Platform | Wheel | Needs at least |
|---|---|---|
| Linux x86_64 | manylinux_2_28_x86_64 |
glibc 2.28 |
| Linux aarch64 | manylinux_2_28_aarch64 |
glibc 2.28 |
| macOS arm64 | macosx_11_0_arm64 |
macOS 11 |
| macOS x86_64 | macosx_10_15_x86_64 |
macOS 10.15 |
Those binaries link OpenSSL and zlib statically, so they need nothing from the system.
Anywhere else, pip installs the source distribution, which carries no binary. On musl, on
32-bit ARM, or with an older glibc, compile tdlib
yourself.
python-telegram looks for the library in this order, and logs which one it used:
- the
library_pathargument - the
PYTHON_TELEGRAM_TDLIB_PATHenvironment variable - a system-wide
tdjson - the bundled binary
A system-wide tdlib therefore wins over the bundled one. To point at a specific build,
pass its path. The file is called libtdjson.so on Linux and libtdjson.dylib on macOS:
tg = Telegram(
# ...
library_path="/usr/local/lib/libtdjson.so",
)
If nothing can be found, TDJson() raises TDLibNotFoundError, an OSError subclass whose
message names the platform, the paths tried and the overrides.
Docker
This library has a docker image:
docker run -i -t --rm \
-v /tmp/docker-python-telegram/:/tmp/ \
akhmetov/python-telegram \
python3 /app/examples/send_message.py $API_ID $API_HASH $PHONE $CHAT_ID $TEXT
How to use the library
First, register a new Telegram application to get your api_id and api_hash.
Check out the tutorial for more details.
Basic example:
from telegram.client import Telegram
from telegram.text import Spoiler
tg = Telegram(
api_id=123456,
api_hash="api_hash",
phone="+31611111111", # you can pass 'bot_token' instead
database_encryption_key="changekey123",
files_directory="/tmp/.tdlib_files/",
)
tg.login()
# The chat must be in the tdlib database before you can send a message to it.
# `get_chats` loads up to `limit` chats from the main chat list.
result = tg.get_chats(limit=100)
result.wait()
chat_id = 123456789
result = tg.send_message(chat_id, Spoiler("Hello world!"))
# `tdlib` is asynchronous, so `python-telegram` always returns an `AsyncResult` object.
# You can receive a result with the `wait` method of this object.
result.wait()
print(result.update)
tg.stop() # You must call `stop` at the end of the script.
You can also use call_method to call any tdlib method:
tg.call_method("getUser", params={"user_id": user_id})
More examples can be found in the /examples/ directory.
More information is available in the documentation.
Development
See CONTRIBUTING.md.
Release files for python-telegram 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python_telegram-2.0.0.tar.gz | 26.3 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| python_telegram-2.0.0-py3-none-manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.28+ x86-64 | Details |
| python_telegram-2.0.0-py3-none-manylinux_2_28_aarch64.whl | Python 3 | none | Linux glibc 2.28+ ARM64 | Details |
| python_telegram-2.0.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details |
| python_telegram-2.0.0-py3-none-macosx_10_15_x86_64.whl | Python 3 | none | macOS 10.15+ x86-64 | Details |
Total release size: 53.6 MB
Release files / python_telegram-2.0.0.tar.gz
| Download URL | python_telegram-2.0.0.tar.gz |
|---|---|
| Size | 26.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e024306fdb1c633ed2ab02981f3d36bca73d759cf776e3940f36babbc999002
|
|
BLAKE2b-256 checksum How to use checksums |
6d61310fe14c1e6700940d2bb4c79d7cb91e256fa4c02c148b4646924b70c42a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 23, 2026.
Transparency logRelease files / python_telegram-2.0.0-py3-none-manylinux_2_28_x86_64.whl
| Download URL | python_telegram-2.0.0-py3-none-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 15.8 MB |
| Tags | Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
36f7264be8eb6a9ec727d6ea78ca4b9828aaad491995eb5cb91aa24b76d1ef19
|
|
BLAKE2b-256 checksum How to use checksums |
21ac0963c95583dfee246e5364b50980d799c59d0d148f27d4d5587aa1df7021
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 23, 2026.
Transparency logRelease files / python_telegram-2.0.0-py3-none-manylinux_2_28_aarch64.whl
| Download URL | python_telegram-2.0.0-py3-none-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 15.6 MB |
| Tags | Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
7edd4367fa1a597a654e38c86c964494629fb6d03f4cb2d7ba4a7193b6847e30
|
|
BLAKE2b-256 checksum How to use checksums |
4032c294e26bc0d48d818fe192af3ae415a86a79924d67cdeee62c0d229da77e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 23, 2026.
Transparency logRelease files / python_telegram-2.0.0-py3-none-macosx_11_0_arm64.whl
| Download URL | python_telegram-2.0.0-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 10.6 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
67491bc97235cc93165068aa2f37b5eeb53206bdeb64cd0020c1f21fb951caed
|
|
BLAKE2b-256 checksum How to use checksums |
525e91858b231e4383c6a5d207b9458ff1e2ebdffd4a84f09b09ff9d3dd7d10d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 23, 2026.
Transparency logRelease files / python_telegram-2.0.0-py3-none-macosx_10_15_x86_64.whl
| Download URL | python_telegram-2.0.0-py3-none-macosx_10_15_x86_64.whl |
|---|---|
| Size | 11.5 MB |
| Tags | Python 3 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
0abaea7a48e494260c384490d1fa5938ab838dfa285a97098440a8f3dc469e55
|
|
BLAKE2b-256 checksum How to use checksums |
960ae1dd574af0ec1cb0f29a4aaa1e7de0ab7eb10d9befddc5076aa6ff2d1333
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 23, 2026.
Transparency log