A lightweight wrapper that brings pyTelegramBotAPI (Telebot) syntax to the powerful MTProto protocol using Telethon under the hood
Project description
Telebot MTProto for Python
A lightweight wrapper that brings the simple and familiar decorator-based syntax of pyTelegramBotAPI (Telebot) to the high-performance MTProto protocol (using Telethon under the hood).
Why Telebot MTProto?
When building Telegram bots with pyTelegramBotAPI (telebot), you are limited by the HTTP-based Bot API:
- Cannot download files larger than 20MB.
- Cannot upload files larger than 50MB.
- HTTP overhead slows down responses.
Telebot MTProto solves this! By running directly over MTProto (TCP):
- Send & Download files up to 2GB (or 4GB with Telegram Premium).
- Run as a Bot (using bot token) or as a Userbot (using phone login session).
- Enjoy direct TCP speed with zero-change friendly Telebot syntax.
Installation
Install using pip:
pip install telebot-mtproto
Quick Start
1. Run as a Bot Account (with Token)
from telebot_mtproto import MTProtoTeleBot
# Get api_id and api_hash from https://my.telegram.org
bot = MTProtoTeleBot(
api_id=123456,
api_hash="your_api_hash",
bot_token="your_bot_token_from_botfather"
)
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Hello! I am running on MTProto protocol.")
@bot.message_handler(func=lambda message: True)
def echo_all(message):
bot.reply_to(message, f"You said: {message.text}")
# Start the bot
bot.run()
2. Run as a Userbot Account (with Phone Login)
If you don't provide a bot_token, it will act as a Userbot. During the first run, it will prompt you in the terminal to enter your phone number and the OTP code sent by Telegram.
from telebot_mtproto import MTProtoTeleBot
bot = MTProtoTeleBot(
api_id=123456,
api_hash="your_api_hash",
session_name="my_userbot_session"
)
@bot.message_handler(commands=['ping'])
def ping(message):
bot.reply_to(message, "Pong from userbot!")
bot.run()
3. Send and Download Large Files (> 20MB)
@bot.message_handler(commands=['download'])
def get_large_file(message):
if message.reply_to_message:
bot.reply_to(message, "Downloading large file... (up to 2GB supported)")
# Download file directly over MTProto TCP
dest = "./downloads/large_file.zip"
bot.download_file(message.reply_to_message, dest)
bot.reply_to(message, f"File saved to {dest}")
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file telebot_mtproto-1.1.0.tar.gz.
File metadata
- Download URL: telebot_mtproto-1.1.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c40d4768058e58d9869342c233abb06963b6e88205df06af15aabdc4cabfd85e
|
|
| MD5 |
2cb31c9df5b03e18dcf6e2a12b1e7333
|
|
| BLAKE2b-256 |
926fa318d059a662e26e0757503f9609ef09ef685b783a52a4b66e5d9221153f
|
File details
Details for the file telebot_mtproto-1.1.0-py3-none-any.whl.
File metadata
- Download URL: telebot_mtproto-1.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acda792a9d9f71466ab66709972672a79c4581c618315b4829eeb00cef3b4540
|
|
| MD5 |
82c0840065c6c364f6a042fe18e8e0c9
|
|
| BLAKE2b-256 |
628d6e32200355cd723719047535ea94d47be2042bdd45a8a69d981f5eaf7501
|