Easy-to-use asynchronous TDLib wrapper for Python.
Project description
Pytdbot
Pytdbot (Python TDLib) is an asynchronous TDLib wrapper for Telegram users/bots written in Python.
Features
- Easy, Fast and Powerful
- Fully asynchronous
- Decorator based update handler
- Bound methods
- Supports userbots, Plugins, Filters, TDLib functions and much more.
Requirements
Installation
For better performance, it's recommended to install orjson or ujson.
You can install Pytdbot using pip:
pip install pytdbot
To install the development version from Github, use the following command:
pip install git+https://github.com/pytdbot/client.git
Examples
Basic example:
from pytdbot import Client, utils
from pytdbot.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()
async def print_message(c: Client, message: Update):
print(message)
@client.on_updateNewMessage()
async def simple_message(c: Client, message: Update):
if message.is_private:
await message.reply_text('Hi! i am simple bot')
if message.is_self and message.text: # Works only for userbots.
if message.text == "!id":
await 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.
Thanks to
-
You for viewing or using this project.
-
@levlam for maintaining TDLib and for the help to create Pytdbot.
License
MIT License
Project details
Release history Release notifications | RSS feed
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.8.8.tar.gz
(439.1 kB
view details)
File details
Details for the file Pytdbot-0.8.8.tar.gz
.
File metadata
- Download URL: Pytdbot-0.8.8.tar.gz
- Upload date:
- Size: 439.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ee8fb06d2e28818f5869936794666e94c2e8d07a5edf52d20bc3e51f15a5c44 |
|
MD5 | 2ca60562900fcc49ed58bca077ad57ae |
|
BLAKE2b-256 | f023aba5cae8321df85dab61c92556ac8e0b22efbd9653c1474e12dd2753085b |