Skip to content

Python Telegram

There are two ways to interact with Telegram through python:

  • Client libraries
  • Bot libraries

Client libraries

Client libraries use your account to interact with Telegram itself through a developer API token.

The most popular to use is Telethon.

Bot libraries

Telegram lists many libraries to interact with the bot API, the most interesting are:

If there comes a moment when we have to create the messages ourselves, telegram-text may be an interesting library to check.

python-telegram-bot

Pros:

  • Popular: 23k stars, 4.9k forks
  • Maintained: last commit 3 days ago
  • They have a developers community to get help in this telegram group
  • I like how they try to minimize third party dependencies, and how you can install the complements if you need them
  • Built on top of asyncio
  • Nice docs
  • Fully supports the Telegram bot API
  • Has many examples

Cons:

  • Interface is a little verbose and complicated at a first look
  • Only to be run in a single thread (not a problem)

References:

  • Package documentation is the technical reference for python-telegram-bot. It contains descriptions of all available classes, modules, methods and arguments as well as the changelog.
  • Wiki is home to number of more elaborate introductions of the different features of python-telegram-bot and other useful resources that go beyond the technical documentation.
  • Examples section contains several examples that showcase the different features of both the Bot API and python-telegram-bot
  • Source

pyTelegramBotAPI

Pros:

Cons:

  • Uses lambdas inside the decorators, I don't know why it does it.
  • The docs are not as throughout as python-telegram-bot one.

References:

aiogram

Pros:

  • Popular: 3.8k stars, 717k forks
  • Maintained: last commit 4 days ago
  • Async support
  • They have a developers community to get help in this telegram group
  • Has type hints
  • Cleaner interface than python-telegram-bot
  • Fully supports the Telegram bot API
  • Has examples

Cons:

  • Less popular than python-telegram-bot
  • Docs are written at a developer level, difficult initial barrier to understand how to use it.

References:

Conclusion

Even if python-telegram-bot is the most popular and with the best docs, I prefer one of the others due to the easier interface. aiograms documentation is kind of crap, and as it's the first time I make a bot I'd rather have somewhere good to look at.

So I'd say to go first with pyTelegramBotAPI and if it doesn't go well, fall back to python-telegram-bot.