Post content
We are embracing the future: asyncio support is on its way and it's gonna be legendary! 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 amout 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 … to async def callback, • a lot of calls of bot methods will have to change (e.g. message = bot.send_message(…) to message = await bot.sendmessage(…)) 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 this early in our developement process: We don't know yet, when we can 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 a 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. 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. 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. Your PTB Developer Team »Dread it. Run from it. asyncio still arrives.« - Thanos, ca. 2018, allegedly