lichess-org / berserk

Python client for the lichess API
https://lichess-org.github.io/berserk/
GNU General Public License v3.0
86 stars 43 forks source link

Support asynchronous requests (accept `aiohttp.ClientSession` in `berserk.Client`?) #18

Open jacksonthall22 opened 1 year ago

jacksonthall22 commented 1 year ago

I'm writing a discord bot in PyCord, where the docs suggest performing all requests asynchronously. To be able to use berserk for my bot I would love if something like this worked out of the box:

async with aiohttp.ClientSession() as session:
    client = berserk.Client(session=session)
    ...  # Make api calls etc.
icp1994 commented 1 year ago

https://lichess.org/api#section/Introduction/Rate-limiting mentions: "Only make one request at a time."

benediktwerner commented 1 year ago

Yeah, there probably are not a lot of cases where async is really beneficial when using the Lichess API. Though it might still be useful to handle timeouts and stuff like that nicer or when already using async for other things.

It looks like it should theoretically be possible to transparently use an async client but getting streams and types to work properly might be a bit tricky. But if anybody can find a nice solution, I'd be open to merging it.