Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Pytdbot

Version TDLib version Downloads Telegram Chat

Buy me a Cup of TON

Pytdbot is an asynchronous TDLib wrapper for Telegram users/bots written in Python.

Features

Pytdbot offers numerous advantages, including:

  • Easy to Use: Designed with simplicity in mind, making it accessible for developers
  • Performance: Fast and powerful, making it ready to fight
  • Asynchronous: Fully asynchronous that allows for non-blocking requests and improved responsiveness
  • Scalable: Easily scalable using TDLib Server
  • Well-typed: Provides clear and well-defined methods and types to enhance developer experience
  • Decorator-Based Updates: Simplifies the implementation of update handlers through a decorator pattern
  • Bound Methods: Features types bound methods for improved usability
  • Unlimited Support: Supports Plugins, filters, TDLib types/functions and much more

Requirements

Installation

For better performance, it's recommended to install orjson or ujson.

You can install Pytdbot with TDLib included using pip:

pip install --upgrade pytdbot[tdjson]

If the installation fails, then install without pre-built TDLib:

pip install pytdbot

Then you need to build TDLib from source and pass it to Client.lib_path.

You could also install the development version using the following command:

pip install --pre pytdbot

Examples

Basic example:

import asyncio
import logging

from pytdbot import Client, types

logging.basicConfig(
    level=logging.INFO,
    format="[%(levelname)s][p %(process)d %(threadName)s][%(created)f][%(filename)s:%(lineno)d][%(funcName)s][%(name)s]  %(message)s",
)
client = Client(
    token="1088394097:AAQX2DnWiw4ihwiJUhIHOGog8gGOI",  # Your bot token
    api_id=0,
    api_hash="API_HASH",
    files_directory="BotDB",  # Path where to store TDLib files
    database_encryption_key="1234echobot$",
    td_verbosity=2,  # TDLib verbosity level
    td_log=types.LogStreamFile("tdlib.log", 104857600),  # Set TDLib log file path
)


@client.on_updateNewMessage()
async def print_message(c: Client, message: types.UpdateNewMessage):
    print(message)


@client.on_message()
async def say_hello(c: Client, message: types.Message):
    msg = await message.reply_text(f"Hey {await message.mention(parse_mode='html')}! I'm cooking up a surprise... 🍳👨‍🍳", parse_mode="html")

    async with message.action("choose_sticker"):
        await asyncio.sleep(5)

        await msg.edit_text("Boo! 👻 Just kidding.")



# Run the client
asyncio.run(client.run())

For more examples, check the examples folder.

Using AI agents

Pytdbot includes a skill and a local docs CLI so coding agents can use the library correctly (bound methods, helpers, TDLib types, and so on)

  1. Install Pytdbot
  2. Point your agent at the skill file:
    • In this repo: pytdbot/ai/SKILL.md
    • or using curl -O "https://raw.githubusercontent.com/pytdbot/client/refs/heads/main/pytdbot/ai/SKILL.md"
  3. Register it the way your tool expects (project skill, agent rule, or “read this file first”)

The skill explains how Pytdbot is meant to be used; the CLI returns live signatures from your installed version.

Thanks to

  • You for viewing or using this project.

  • @levlam for maintaining TDLib and for the help to create Pytdbot.

License

MIT License

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytdbot-0.10.2.dev2.tar.gz (844.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytdbot-0.10.2.dev2-py3-none-any.whl (866.2 kB view details)

Uploaded Python 3

File details

Details for the file pytdbot-0.10.2.dev2.tar.gz.

File metadata

  • Download URL: pytdbot-0.10.2.dev2.tar.gz
  • Upload date:
  • Size: 844.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytdbot-0.10.2.dev2.tar.gz
Algorithm Hash digest
SHA256 0fc2dffebba340cc986e50636a7fa1821e4484ffa2e1b14d16bb12994dc8fca5
MD5 90da28cb3f54b0d7387421cf6d1f5c08
BLAKE2b-256 bdcbdf1405362078085c8f505396dbbdfa51d25eae999408eb79c50b3011d02d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytdbot-0.10.2.dev2.tar.gz:

Publisher: publish-to-pypi.yml on pytdbot/client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytdbot-0.10.2.dev2-py3-none-any.whl.

File metadata

  • Download URL: pytdbot-0.10.2.dev2-py3-none-any.whl
  • Upload date:
  • Size: 866.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytdbot-0.10.2.dev2-py3-none-any.whl
Algorithm Hash digest
SHA256 e014802c34b843fa5b61c6b354d6ae6fc19d5d750b168e6bf86ce42d84a0a3c2
MD5 bd5f79240fb20ca1cd88e5ba6943497d
BLAKE2b-256 3c6379da9be92f71bd47886902c15dfe0f974fa93d7505d588b7eb2453d42304

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytdbot-0.10.2.dev2-py3-none-any.whl:

Publisher: publish-to-pypi.yml on pytdbot/client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page