Skip to content

PTB goes asyncio in v20 and breaks a lot on the way! #2352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Bibo-Joshi opened this issue Jan 31, 2021 · 0 comments
Closed

PTB goes asyncio in v20 and breaks a lot on the way! #2352

Bibo-Joshi opened this issue Jan 31, 2021 · 0 comments
Labels
🛠 breaking change type: breaking 🛠 refactor change type: refactor
Milestone

Comments

@Bibo-Joshi
Copy link
Member

Bibo-Joshi commented Jan 31, 2021

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 … 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.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

@Bibo-Joshi Bibo-Joshi added enhancement 🛠 refactor change type: refactor 🛠 breaking change type: breaking labels Jan 31, 2021
@Bibo-Joshi Bibo-Joshi added this to the v14 milestone Jan 31, 2021
@Bibo-Joshi Bibo-Joshi pinned this issue Jan 31, 2021
@python-telegram-bot python-telegram-bot locked and limited conversation to collaborators Jan 31, 2021
@Poolitzer Poolitzer changed the title PTB goes asyncio in v14! PTB goes asyncio in v14 and breaks a lot on the way! Oct 19, 2021
@harshil21 harshil21 changed the title PTB goes asyncio in v14 and breaks a lot on the way! PTB goes asyncio in v20 and breaks a lot on the way! Apr 26, 2022
@Bibo-Joshi Bibo-Joshi unpinned this issue May 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🛠 breaking change type: breaking 🛠 refactor change type: refactor
Projects
None yet
Development

No branches or pull requests

1 participant