Pytdbot (Python TDLib) is an asynchronous TDLib wrapper for Telegram users/bots written in Python.
- Easy, Fast and Powerful
- Fully asynchronous
- Decorator based update handler
- Bound methods
- Supports userbots, Plugins, Filters, TDLib functions and much more.
For better performance, it's recommended to install orjson or ujson.
You can install Pytdbot using pip: To install the development version from Github, use the following command:
pip install git+https://github.com/dev-rio/pytdbot-sync.git
Basic example:
from pytdbot_sync import Client, utils
from pytdbot_sync.types import LogStreamFile, Update
client = Client(
api_id=0,
api_hash="API_HASH",
database_encryption_key="1234echobot$",
token="1088394097:AAQX2DnWiw4ihwiJUhIHOGog8gGOI", # Your bot token or phone number if you want to login as user
files_directory="BotDB", # Path where to store TDLib files
lib_path="/path/to/libtdjson.so", # Path to TDjson shared library
td_log=LogStreamFile("tdlib.log"), # Set TDLib log file path
td_verbosity=2, # TDLib verbosity level
)
@client.on_updateNewMessage()
def print_message(c: Client, message: Update):
print(message)
@client.on_updateNewMessage()
def simple_message(c: Client, message: Update):
if message.is_private:
message.reply_text('Hi! i am simple bot')
if message.is_self and message.text: # Works only for userbots.
if message.text == "!id":
message.edit_text(
"\\- Current chat ID: {}\n\\- {} ID: {}".format(
utils.code(str(message.chat_id)),
utils.bold(c.me["first_name"]),
utils.code(str(message.from_id)),
),
parse_mode="markdownv2",
)
# Run the client
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