Loading repository data…
Loading repository data…
pytdbot / repository
Easy-to-use asynchronous TDLib wrapper for Python.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
Pytdbot is an asynchronous TDLib wrapper for Telegram users/bots written in Python.
Pytdbot offers numerous advantages, including:
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
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.
You for viewing or using this project.
@levlam for maintaining TDLib and for the help to create Pytdbot.
MIT License