-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
We are embracing the future: asyncio
support is on its way and it's gonna be legen, wait for it, -dary!
For those of you who don't know what asyncio
does: When calling e.g. bot.send_message(…)
, your code spends a lot of time waiting for the Telegram API to respond. During that waiting time, other code could be running. So far this was achieved in PTB using multi threading. But:
By now asyncio
is a well established standard for concurrency in networking libraries. It can be faster than threaded code and provides some more flexibility. Until the beginning of 2020, PTB still supported Python 2.7, but by now a year has passed and we see an increasing amount of questions on how to integrate asyncio
code with PTB. On top of that, we have some plans for features that would heavily benefit from a switch to asyncio
.
That is why with the release of version 14, python-telegram-bot
will go asyncio
!
We are aware that this will be a major breaking change, as
- all callback definitions will have to change from
def callback …
toasync def callback
, - a lot of calls of bot methods will have to change (e.g.
message = bot.send_message(…)
tomessage = await bot.send_message(…)
) and - projects that use
python-telegram-bot
in a multi-threaded manner will have to be reworked
However, this switch will also mean a lot of work on the internals of our library and trying to make the change backwards compatible would mean a huge additional effort. We will therefore not provide a compatibility layer. Making this decision was not easy for us, but we hope that it enables us to put our energy in further improvements and enhancements of python-telegram-bot
rather than maintaining legacy code for backward of compatibility.
This is why we're making this announcement that early in our development process: We don't know when we will release version 14. It may be in a few months or in 2 years - as you know we don't like to give ETAs. But it's important to us to involve the community in the transition and give you a chance to prepare. We will make another announcement when we have an asyncio
branch ready. We will give you the opportunity to try the new PTB out and will try to support community based compatibility tools. The actual release will happen later and will be announced beforehand as well.
We hope that this switch is in your interest. If you have questions or feedback about the announcement, feel free to comment on this GitHub thread. We will try our best to answer your questions and take your comments into account.
While we prepared the switch to asyncio
, we took the chance and did some much needed spring cleaning in the library. While this means a more consistent user appearance, it also means a lot of breaking changes. We will write a transition guide, as always.
In the meantime you can expect some non-breaking improvements. Should Telegram release another API update, we will update our library before going ahead with version 14.
As of now, all development to the main branch has been stopped. If an API update happens or some mayor bug appears, we will release another version, otherwise the next proper release will be V14.
Your PTB Developer Team
»Dread it. Run from it. asyncio still arrives.« - Thanos, ca. 2018, allegedly