Skip to main content

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


Download files

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

Source Distribution

telebot_mtproto-1.2.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

telebot_mtproto-1.2.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file telebot_mtproto-1.2.0.tar.gz.

File metadata

  • Download URL: telebot_mtproto-1.2.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for telebot_mtproto-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e82368d70b46b54afdec3f730937a003f03052e3d5b29b3d72ed7d5206a29763
MD5 148f690f8cc7ef4362a1c7f0e53ba37e
BLAKE2b-256 01927555acca7b8ac1bbb77ea86bf5a817e776ecab0a9e3f9f00d79f8a2937b9

See more details on using hashes here.

File details

Details for the file telebot_mtproto-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for telebot_mtproto-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be7e82e62d31120bcc40d06858f60a07ada5f6cad5d890a4dfae4823a8d085f5
MD5 ba302374e2a1f2be8c1afb5a2e5fd377
BLAKE2b-256 4051dae19634a1058e5fd818feac276a85bc833cebeb9ab4ce62cd5b6fe05500

See more details on using hashes here.

Supported by

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