python-telegram icon indicating copy to clipboard operation
python-telegram copied to clipboard

async/await syntax

Open Pegorino82 opened this issue 4 years ago • 4 comments

is it possible to use async/await with the library? if it is, does any have examples of usage? it will be greate for me)

Pegorino82 avatar Mar 26 '20 08:03 Pegorino82

Hi,

No, the library officially doesn't support async/await syntax, you'll have to write a wrapper if you want to use it.

alexander-akhmetov avatar Apr 12 '20 12:04 alexander-akhmetov

After seeing this, I thought it should be possible to use async/await with tdlib. So I tried it and I managed to get a low-level async tdjson wrapper working; by low-level I mean: await tdlib.send_request({'@type': 'sendMessage', ...})

However, looking at the current API of python-telegram and how it's implemented, I don't think it would be possible to support async/await and keep compatibility with the existing API...

nicolas17 avatar May 14 '20 05:05 nicolas17

Probably, it should be possible to have both the current synchronous client and a new async API, and the synchronous client could be migrated to use the new async-await API under the hood

alexander-akhmetov avatar May 14 '20 07:05 alexander-akhmetov

This is what I wrote, in case it helps: https://gist.github.com/nicolas17/c8330da13512c9743a3da4b7c7688a3b

nicolas17 avatar May 14 '20 22:05 nicolas17