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.0.0.tar.gz (5.7 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.0.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: telebot_mtproto-1.0.0.tar.gz
  • Upload date:
  • Size: 5.7 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.0.0.tar.gz
Algorithm Hash digest
SHA256 7e0b1044a95380cf2680c96e9175bb3eb3df01c371e32841a056a1c5baa08ce8
MD5 1a1e2cb62cc0fabd7717565c82524f93
BLAKE2b-256 0d39c08c3373a34e2e464de3df8836cb875711a6513c936128fd1b61e44e7c5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for telebot_mtproto-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bab33e7108a5cd9da2a7b121bdc9c5fc0a2a87dd7bffbf3ac85709bd82361d49
MD5 c688cd47bca83f344aae178491bc0bcb
BLAKE2b-256 1b2a6d9e3afd4a96b25659f3c43d058a55795279e38a533f18f63a2587005593

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