# Python telegram bot libraries

Python Telegram bot libraries receive messages and commands from Telegram and send replies from Python code. An MTProto client connects to Telegram directly as a bot or a user account rather than through the HTTP Bot API. These libraries let developers run support bots, notification bots, and AI assistants inside Telegram chats.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [python-telegram-bot](#python-telegram-bot) | 7.8M | 29.6K | Jun 2026 | LGPL-3.0-only |
| [Telethon](#telethon) | 4.1M | 12.1K | Sep 2026 | MIT |
| [aiogram](#aiogram) | 3.3M | 5.9K | Nov 2026 | MIT |
| [pyTelegramBotAPI](#pytelegrambotapi) | 906.4K | 8.8K | Oct 2026 | GPL-2.0 |
| [Pyrogram](#pyrogram) | 402.0K | 4.6K | Apr 2023 | LGPL-3.0 |
| [telebot](#telebot) | 112.7K | 53 | Feb 2023 | MIT |
| [Telepot](#telepot) | 14.0K | 2.4K | May 2018 | MIT |
| [python-telegram](#python-telegram) | 6.2K | 725 | Aug 2026 | MIT |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[python-telegram-bot](#python-telegram-bot) has the most monthly downloads in this comparison, at 7.8M.

## Capabilities

| Library | Async request API | Webhook registration |
| --- | --- | --- |
| [python-telegram-bot](#python-telegram-bot) | Yes | Yes |
| [Telethon](#telethon) | Yes | No |
| [aiogram](#aiogram) | Yes | Yes |
| [pyTelegramBotAPI](#pytelegrambotapi) | Yes | Yes |
| [Pyrogram](#pyrogram) | Yes | No |
| [telebot](#telebot) | No | No |
| [Telepot](#telepot) | Yes | Yes |
| [python-telegram](#python-telegram) | No | No |

## Libraries

### python-telegram-bot

[GitHub](https://github.com/python-telegram-bot/python-telegram-bot) · [PyPI](https://pypi.org/project/python-telegram-bot) · [Docs](https://docs.python-telegram-bot.org/en/stable/)

Provides an asynchronous Python interface to the Telegram Bot API.

- Downloads / mo: 7.8M
- Stars: 29.6K
- Last release: 22.8
- License: LGPL-3.0-only
- Capabilities: [From the python-telegram-bot docs](https://docs.python-telegram-bot.org/en/stable/)

**Strengths**

- **Organizes multi-step conversations.** Use ConversationHandler to organize handlers for a conversation.
- **Supports polling and webhooks.** Receive updates through polling or an optional webhook server.

**Watch out for**

- **Conversations need sequential updates.** Disable concurrent_updates when using ConversationHandler.
- **Webhook hosting needs an extra.** Install the webhooks extra for the supplied webhook server.

```sh
pip install python-telegram-bot --upgrade
```

**freqtrade/freqtrade** (56.9K stars)

[freqtrade/freqtrade](https://github.com/freqtrade/freqtrade) 

```python
async def _send_msg(
    self,
    msg: str,
    parse_mode: str = ParseMode.MARKDOWN,
    disable_notification: bool = False,
    keyboard: list[list[InlineKeyboardButton]] | None = None,
    callback_path: str = "",
    reload_able: bool = False,
    query: CallbackQuery | None = None,
) -> None:
    """
    Send given markdown message
    :param msg: message
    :param bot: alternative bot
    :param parse_mode: telegram parse mode
    :return: None
    """
    reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup
    if query:
        await self._update_msg(
            query=query,
            msg=msg,
            parse_mode=parse_mode,
            callback_path=callback_path,
            reload_able=reload_able,
        )
        return
    if reload_able and self._config["telegram"].get("reload", True):
        reply_markup = InlineKeyboardMarkup(
            [[InlineKeyboardButton("Refresh", callback_data=callback_path)]]
        )
    else:
        if keyboard is not None:
            reply_markup = InlineKeyboardMarkup(keyboard)
        else:
            reply_markup = ReplyKeyboardMarkup(self._keyboard, resize_keyboard=True)
    try:
        try:
            await self._app.bot.send_message(
                self._config["telegram"]["chat_id"],
                text=msg,
                parse_mode=parse_mode,
                reply_markup=reply_markup,
                disable_notification=disable_notification,
                message_thread_id=self._config["telegram"].get("topic_id"),
            )
        except NetworkError as network_err:
            # Sometimes the telegram server resets the current connection,
            # if this is the case we send the message again.
            logger.warning(
                "Telegram NetworkError: %s! Trying one more time.", network_err.message
            )
            await self._app.bot.send_message(
                self._config["telegram"]["chat_id"],
                text=msg,
                parse_mode=parse_mode,
                reply_markup=reply_markup,
                disable_notification=disable_notification,
                message_thread_id=self._config["telegram"].get("topic_id"),
            )
    except TelegramError as telegram_err:
        logger.warning("TelegramError: %s! Giving up on that message.", telegram_err.message)

```

[freqtrade/rpc/telegram.py](https://github.com/freqtrade/freqtrade/blob/7eb798c29314c46d76d4d87df2744c5669fcb515/freqtrade/rpc/telegram.py#L2201-L2262) · [More projects using python-telegram-bot →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20python-telegram-bot%20for%20reliable%20message%20updates%2C%20scoped%20command%20menus%20and%20editable%20media%20messages&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import asyncio
import telegram

async def main():
    bot = telegram.Bot("TOKEN")
    async with bot:
        print(await bot.get_me())

if __name__ == '__main__':
    asyncio.run(main())

```

From [conversationbot.py](https://github.com/python-telegram-bot/python-telegram-bot/wiki/Introduction-to-the-API)

### Telethon

[GitHub](https://github.com/LonamiWebs/Telethon) · [PyPI](https://pypi.org/project/Telethon) · [Docs](https://docs.telethon.dev/en/stable/)

Provides an asyncio MTProto client for Telegram user or bot accounts.

- Downloads / mo: 4.1M
- Stars: 12.1K
- Last release: 1.45.0
- License: MIT
- Capabilities: [From the Telethon docs](https://docs.telethon.dev/en/stable/)

**Strengths**

- **Connects through the full API.** Use MTProto with a user account or a bot account.
- **Tracks a per-chat conversation.** Wait for replies within a conversation scoped to one chat.

**Watch out for**

- **Needs application API credentials.** Provide an API ID and hash, including for bot accounts.
- **Development moved to Codeberg.** The former GitHub repository can disappear.

```sh
python3 -m pip install --upgrade telethon
```

**chigwell/telegram-mcp** (2.1K stars)

[chigwell/telegram-mcp](https://github.com/chigwell/telegram-mcp) 

```python
@mcp.tool(
    annotations=ToolAnnotations(
        title="Set Bot Commands", openWorldHint=True, destructiveHint=True, idempotentHint=True
    )
)
@with_account(readonly=False)
@flood_category("admin_action")
async def set_bot_commands(
    bot_username: str, commands: list, account: Optional[str] = None
) -> str:
    """
    Set bot commands for a bot you own.
    Note: This function can only be used if the Telegram client is a bot account.
    Regular user accounts cannot set bot commands.

    Args:
        bot_username: The username of the bot to set commands for.
        commands: List of command dictionaries with 'command' and 'description' keys.
    """
    try:
        cl = get_client(account)
        # First check if the current client is a bot
        me = await cl.get_me()
        if not getattr(me, "bot", False):
            return (
                "Error: This function can only be used by bot accounts. "
                "Your current Telegram account is a regular user account, not a bot."
            )

        # Import required types
        from telethon.tl.types import BotCommand, BotCommandScopeDefault
        from telethon.tl.functions.bots import SetBotCommandsRequest

        # Create BotCommand objects from the command dictionaries
        bot_commands = [
            BotCommand(command=c["command"], description=c["description"]) for c in commands
        ]

        # Get the bot entity
        await resolve_entity(bot_username, cl)

        # Set the commands with proper scope
        await cl(
            SetBotCommandsRequest(
                scope=BotCommandScopeDefault(),
                lang_code="en",  # Default language code
                commands=bot_commands,
            )
        )

        return f"Bot commands set for {bot_username}."
    except ImportError as ie:
        return log_and_format_error("set_bot_commands", ie)
    except Exception as e:
        return log_and_format_error("set_bot_commands", e, bot_username=bot_username)

```

[telegram_mcp/tools/profile.py](https://github.com/chigwell/telegram-mcp/blob/0d27284a5e99d788ffe4f857d9df8d9d668e2820/telegram_mcp/tools/profile.py#L452-L506) · [More projects using Telethon →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20Telethon%20for%20reliable%20message%20updates%2C%20scoped%20command%20menus%20and%20editable%20media%20messages&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import os
from telethon.sync import TelegramClient

with TelegramClient("bot", int(os.environ["TELEGRAM_API_ID"]), os.environ["TELEGRAM_API_HASH"]).start(
    bot_token=os.environ["TELEGRAM_BOT_TOKEN"]
) as bot:
    print(bot.get_me())

```

From [print_messages.py](https://docs.telethon.dev/en/stable/basic/signing-in.html)

### aiogram

[GitHub](https://github.com/aiogram/aiogram) · [PyPI](https://pypi.org/project/aiogram) · [Docs](https://docs.aiogram.dev/en/latest/)

Provides an asynchronous framework for the Telegram Bot API.

- Downloads / mo: 3.3M
- Stars: 5.9K
- Last release: 3.32.0
- License: MIT
- Capabilities: [From the aiogram docs](https://docs.aiogram.dev/en/latest/)

**Strengths**

- **Provides finite-state bot workflows.** Organize multi-step interactions with the finite-state machine.
- **Separates handlers through routers.** Group update handlers into reusable routers.

**Watch out for**

- **Memory storage loses restart state.** Use persistent storage when conversations must survive restarts.
- **Polling needs one process.** Use webhooks to scale one bot across processes.

```sh
pip install -U aiogram
```

**Tishka17/aiogram_dialog** (899 stars)

[Tishka17/aiogram_dialog](https://github.com/Tishka17/aiogram_dialog) 

```python
async def edit_text(
        self, bot: Bot, new_message: NewMessage, old_message: OldMessage,
) -> Message:
    logger.debug("edit_text to %s", new_message.chat)
    return await bot.edit_message_text(
        message_id=old_message.message_id,
        chat_id=old_message.chat.id,
        business_connection_id=new_message.business_connection_id,
        text=new_message.text,
        reply_markup=new_message.reply_markup,
        parse_mode=new_message.parse_mode,
        link_preview_options=new_message.link_preview_options,
    )

```

[src/aiogram_dialog/manager/message_manager.py](https://github.com/Tishka17/aiogram_dialog/blob/0831da4a90d543bcb7c64636f7a3d01e8f2588d8/src/aiogram_dialog/manager/message_manager.py#L352-L364) · [More projects using aiogram →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20aiogram%20for%20reliable%20message%20updates%2C%20scoped%20command%20menus%20and%20editable%20media%20messages&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import asyncio
import os
from aiogram import Bot

async def main():
    bot = Bot(token=os.environ["TELEGRAM_BOT_TOKEN"])
    async with bot.context():
        print(await bot.get_me())

asyncio.run(main())

```

From [finite_state_machine.py](https://docs.aiogram.dev/en/latest/api/bot.html)

### pyTelegramBotAPI

[GitHub](https://github.com/eternnoir/pyTelegramBotAPI) · [PyPI](https://pypi.org/project/pyTelegramBotAPI) · [Docs](https://pytba.readthedocs.io/en/latest/)

Provides synchronous and asynchronous interfaces to the Telegram Bot API.

- Downloads / mo: 906.4K
- Stars: 8.8K
- Last release: 4.37.1
- License: GPL-2.0
- Capabilities: [From the pyTelegramBotAPI docs](https://pytba.readthedocs.io/en/latest/)

**Strengths**

- **Offers synchronous and asynchronous APIs.** Choose a synchronous or asynchronous bot implementation.
- **Provides an integrated webhook receiver.** Use run_webhooks to receive and process webhook updates.

**Watch out for**

- **State examples need durable storage.** Replace the sample’s in-memory state storage for production use.

```sh
pip install pyTelegramBotAPI
```

**SideCloudGroup/BetterForward** (737 stars)

[SideCloudGroup/BetterForward](https://github.com/SideCloudGroup/BetterForward) 

```python
def _set_bot_commands(self):
    """Set bot commands for different scopes."""
    self.bot.set_my_commands([
        types.BotCommand("delete", _("Delete a message")),
        types.BotCommand("help", _("Show help")),
    ], scope=types.BotCommandScopeAllPrivateChats())

    self.bot.set_my_commands([
        types.BotCommand("help", _("Show help")),
        types.BotCommand("ban", _("Ban a user")),
        types.BotCommand("unban", _("Unban a user")),
        types.BotCommand("delete", _("Delete a message")),
        types.BotCommand("terminate", _("Terminate a thread")),
        types.BotCommand("verify", _("Set verified status")),
        types.BotCommand("setnote", _("Set or clear topic note")),
        types.BotCommand("getnote", _("Show topic note")),
        types.BotCommand("refresh", _("Refresh user info")),
        types.BotCommand("allow", _("Allow user permissions")),
        types.BotCommand("disallow", _("Disallow user permissions")),
        types.BotCommand("permissions", _("Show user permissions")),
        types.BotCommand("resetpermissions", _("Reset user permission overrides")),
        types.BotCommand("stats", _("Show statistics")),
        types.BotCommand("info", _("Show user info")),
        types.BotCommand("r", _("Send a reply template")),
    ], scope=types.BotCommandScopeChat(self.group_id))

```

[src/bot.py](https://github.com/SideCloudGroup/BetterForward/blob/bcfd8619821d98e27b6a5b0421ea18562f43a337/src/bot.py#L175-L199) · [More projects using pyTelegramBotAPI →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20pyTelegramBotAPI%20for%20reliable%20message%20updates%2C%20scoped%20command%20menus%20and%20editable%20media%20messages&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import os
from telebot import TeleBot

bot = TeleBot(os.environ["TELEGRAM_BOT_TOKEN"])
print(bot.get_me())

```

From [custom_states.py](https://pytba.readthedocs.io/en/latest/sync_version/index.html)

### Pyrogram

[GitHub](https://github.com/pyrogram/pyrogram) · [PyPI](https://pypi.org/project/Pyrogram) · [Docs](https://docs.pyrogram.org/)

Provides an asynchronous Telegram MTProto API framework for users and bots.

- Downloads / mo: 402.0K
- Stars: 4.6K
- Last release: 2.0.106
- License: LGPL-3.0
- Capabilities: [From the Pyrogram docs](https://docs.pyrogram.org/)

```sh
pip3 install pyrogram
```

**Quickstart**

```python
import asyncio
import os
from pyrogram import Client

async def main():
    async with Client("bot", int(os.environ["TELEGRAM_API_ID"]), os.environ["TELEGRAM_API_HASH"],
                      bot_token=os.environ["TELEGRAM_BOT_TOKEN"]) as app:
        print(await app.get_me())

asyncio.run(main())

```

From [client.py](https://docs.pyrogram.org/api/client) · [Find projects using Pyrogram →](https://dashboard.exa.ai/playground/search?q=Pyrogram%20GitHub%20projects)

### telebot

[GitHub](https://github.com/KyleJamesWalker/telebot) · [PyPI](https://pypi.org/project/telebot)

Builds Telegram bots with route decorators.

- Downloads / mo: 112.7K
- Stars: 53
- Last release: 0.0.5
- License: MIT
- Capabilities: [From the telebot docs](https://github.com/KyleJamesWalker/telebot)

```sh
pip install telebot
```

**Quickstart**

```python
import os
from telebot_router import TeleBot

app = TeleBot(__name__)
app.config["api_key"] = os.environ["TELEGRAM_BOT_TOKEN"]
print(app.get_me())

```

From [__init__.py](https://github.com/KyleJamesWalker/telebot/blob/master/README.rst) · [Find projects using telebot →](https://dashboard.exa.ai/playground/search?q=telebot%20GitHub%20projects)

### Telepot

[GitHub](https://github.com/nickoala/telepot) · [PyPI](https://pypi.org/project/telepot) · [Docs](https://telepot.readthedocs.io/en/latest/)

Provides a framework for the Telegram Bot API.

- Downloads / mo: 14.0K
- Stars: 2.4K
- Last release: 12.7
- License: MIT
- Capabilities: [From the Telepot docs](https://telepot.readthedocs.io/en/latest/)

```sh
pip install telepot
```

**Quickstart**

```python
import telepot
bot = telepot.Bot('***** PUT YOUR TOKEN HERE *****')
bot.getMe()

```

From [index.rst](https://telepot.readthedocs.io/en/latest/) · [Find projects using Telepot →](https://dashboard.exa.ai/playground/search?q=telepot%20GitHub%20projects)

### python-telegram

[GitHub](https://github.com/alexander-akhmetov/python-telegram) · [PyPI](https://pypi.org/project/python-telegram)

Builds Telegram clients in Python.

- Downloads / mo: 6.2K
- Stars: 725
- Last release: 2.0.0
- License: MIT
- Capabilities: [From the python-telegram docs](https://github.com/alexander-akhmetov/python-telegram)

```sh
pip install python-telegram
```

**Quickstart**

```python
import argparse

from telegram.client import Telegram


def bot_get_me(api_id, api_hash, token):
    tg = Telegram(
        api_id=api_id,
        api_hash=api_hash,
        bot_token=token,
        database_encryption_key="changeme1234",
    )
    # you must call login method before others
    tg.login()

    result = tg.get_me()
    result.wait()
    print(result.update)
    tg.stop()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("api_id", help="API id")  # https://my.telegram.org/apps
    parser.add_argument("api_hash", help="API hash")
    parser.add_argument("token", help="Bot token")
    args = parser.parse_args()
    bot_get_me(args.api_id, args.api_hash, args.token)

```

From [bot_login.py](https://github.com/alexander-akhmetov/python-telegram/blob/main/examples/bot_login.py) · [Find projects using python-telegram →](https://dashboard.exa.ai/playground/search?q=python-telegram%20GitHub%20projects)

## FAQ

### Which Python Telegram bot library should I use?

[python-telegram-bot](#python-telegram-bot) suits async bots with multi-step conversations, polling, and webhooks. [aiogram](#aiogram) suits async bots organized with routers and finite-state workflows. [Telethon](#telethon) suits user accounts or bots that need Telegram's full MTProto API.

### What is Telethon?

[Telethon](#telethon) is an asyncio MTProto client for Telegram user and bot accounts. It needs an application API ID and hash even for a bot account.

### What is Pyrogram?

[Pyrogram](#pyrogram) is an asynchronous Telegram MTProto API framework for users and bots.

### What is aiogram?

[aiogram](#aiogram) is an asynchronous framework for the Telegram Bot API, with routers and finite-state workflows. Only one polling process can use a given bot token.

### What is pyTelegramBotAPI?

[pyTelegramBotAPI](#pytelegrambotapi) offers synchronous and asynchronous interfaces to the Telegram Bot API, with an integrated webhook receiver.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python Telegram bot libraries python-telegram-bot pyTelegramBotAPI aiogram Telethon examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
