A type-safe Python SDK for TDL (Telegram Downloader). The package wraps the external tdl CLI binary with subprocess execution and exposes a Pydantic-powered Python API for login, chat export, download, upload, forward, backup, recover, migrate, and extension operations.
Other Languages: English | 繁體中文 | 简体中文
Features
- Python facade for the main
tdlcommand groups. - Pydantic option models for validation and CLI flag serialization.
- Enum types for common mode and output parameters.
- Structured
TDLResultresponses with stdout, stderr, and return code. - Custom exceptions for missing binaries, command failures, and timeouts.
Requirements
- Python 3.11 or newer. CI currently validates Python 3.11, 3.12, and 3.13.
- The TDL CLI binary installed separately.
Install tdl first:
# macOS / Linux
curl -sSL https://docs.iyear.me/tdl/install.sh | bash
# or via Go
go install github.com/iyear/tdl@latest
Verify that the binary is available:
tdl version
Installation
pip install tdl-python-sdk
# or with uv
uv add tdl-python-sdk
Quick Start
from tdl_sdk import GlobalOptions, LoginOptions, LoginType, TDL
client = TDL(global_options=GlobalOptions(ns="my_session", proxy="socks5://127.0.0.1:1080"))
client.login(LoginOptions(login_type=LoginType.QR))
Use tdl_path when the binary is not on PATH:
from tdl_sdk import TDL
client = TDL(tdl_path="/usr/local/bin/tdl", timeout=600)
Common Usage
Login
TDL supports desktop, verification code, and QR login flows.
from tdl_sdk import LoginOptions, LoginType, TDL
client = TDL()
client.login(LoginOptions(login_type=LoginType.QR))
client.login(LoginOptions(login_type=LoginType.DESKTOP))
client.login(
LoginOptions(
login_type=LoginType.DESKTOP, desktop="/path/to/Telegram Desktop", passcode="your_passcode"
)
)
client.login(LoginOptions(login_type=LoginType.CODE))
Chat
from tdl_sdk import (
ChatExportOptions,
ChatListOptions,
ChatUsersOptions,
ExportType,
ListOutput,
TDL,
)
client = TDL()
result = client.chat_ls(ChatListOptions(output=ListOutput.JSON, chat_filter="Type == 'channel'"))
print(result.stdout)
client.chat_export(
ChatExportOptions(
chat="my_channel",
export_type=ExportType.LAST,
export_input=[100],
output="export.json",
with_content=True,
)
)
client.chat_users(ChatUsersOptions(chat="my_channel", output="users.json"))
Download
from tdl_sdk import DownloadOptions, TDL
client = TDL()
client.download(
DownloadOptions(
url=["https://t.me/channel/123", "https://t.me/channel/456"], download_dir="./downloads"
)
)
client.download(
DownloadOptions(
file=["export.json"],
download_dir="./media",
include=["mp4", "mkv"],
skip_same=True,
takeout=True,
template="{{ .DialogID }}_{{ .MessageID }}_{{ filenamify .FileName }}",
)
)
client.download(DownloadOptions(file=["export.json"], serve=True, port=9090))
Upload
from tdl_sdk import TDL, UploadOptions
client = TDL()
client.upload(UploadOptions(path=["/data/video.mp4", "/data/photos/"]))
client.upload(UploadOptions(path=["./images/"], chat="my_channel", photo=True))
client.upload(UploadOptions(path=["./temp_files/"], chat="my_channel", rm=True))
Forward
from tdl_sdk import ForwardMode, ForwardOptions, TDL
client = TDL()
client.forward(
ForwardOptions(forward_from=["https://t.me/source_channel/123"], to="target_channel")
)
client.forward(
ForwardOptions(
forward_from=["https://t.me/source/123", "export.json"],
to="target_channel",
mode=ForwardMode.CLONE,
silent=True,
)
)
result = client.forward(
ForwardOptions(forward_from=["export.json"], to="target_channel", dry_run=True)
)
print(result.stdout)
Backup, Recover, And Migrate
from tdl_sdk import BackupOptions, MigrateOptions, RecoverOptions, TDL
client = TDL()
client.backup(BackupOptions(dst="./my_backup.tdl"))
client.recover(RecoverOptions(file="./my_backup.tdl"))
client.migrate(MigrateOptions(to={"type": "file", "path": "/new/storage"}))
Extensions
from tdl_sdk import ExtInstallOptions, TDL
client = TDL()
client.ext_install("github.com/user/tdl-ext-name")
client.ext_install("github.com/user/tdl-ext-name", ExtInstallOptions(force=True))
result = client.ext_list()
print(result.stdout)
client.ext_upgrade("ext-name")
client.ext_remove("ext-name")
Error Handling
from tdl_sdk import DownloadOptions, TDL
from tdl_sdk import TDLCommandError, TDLError, TDLNotFoundError, TDLTimeoutError
client = TDL(timeout=300)
try:
client.download(DownloadOptions(url=["https://t.me/channel/123"]))
except TDLNotFoundError:
print("tdl binary not found. Please install tdl first.")
except TDLTimeoutError as e:
print(f"Command timed out: {e}")
except TDLCommandError as e:
print(f"Command failed (exit code {e.return_code}): {e.stderr}")
except TDLError as e:
print(f"Unexpected error: {e}")
Global Options
Global options are serialized before the command path and apply to every tdl command invoked by a client.
from tdl_sdk import GlobalOptions, TDL
client = TDL(
global_options=GlobalOptions(
ns="work_session",
proxy="socks5://127.0.0.1:1080",
threads=8,
limit=4,
pool=16,
debug=True,
reconnect_timeout="10m",
storage={"type": "bolt", "path": "/custom/data"},
),
tdl_path="/usr/local/bin/tdl",
timeout=600,
)
Resources
License
MIT
Metadata
Release files for tdl-python-sdk 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tdl_python_sdk-0.0.2.tar.gz | 127.3 kB | Without provenance | Details for tdl_python_sdk-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tdl_python_sdk-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for tdl_python_sdk-0.0.2-py3-none-any.whl |
Total release size: 139.6 kB
Release files / tdl_python_sdk-0.0.2.tar.gz
| Download URL | tdl_python_sdk-0.0.2.tar.gz |
|---|---|
| Size | 127.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e622ca49dd12ddcc43e598cbec464e7f1135d7f4d221be2bc2383f8c4907351
|
|
BLAKE2b-256 checksum How to use checksums |
ed92d111be7661c2c685d7a590d0d059fc67d20006cdb1f5d747c10b7c09cd3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / tdl_python_sdk-0.0.2-py3-none-any.whl
| Download URL | tdl_python_sdk-0.0.2-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4a3013a156cce5440fd4c816aa8f3b000b29d4b3c6db4dab84953be8296eb2f
|
|
BLAKE2b-256 checksum How to use checksums |
1d4f8b885a1d3714940569658e8da6e81dd3ed038d078d22eeceffbc0f0ee32b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for tdl-python-sdk 0.0.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.