Replies: 1 comment 2 replies
-
Thanks for raising this. I've been thinking about implementing an async/await based client since removing the tornado-based async client, but I never got around to put the work in for it 😄 I recently noticed the async fork and wanted to suggest bringing it back here, but as you say, there are a few ways we could go about it. I've been watching what happens in the Python ecosystem, I know of 2 examples which have taken a variation of the approach you suggest:
The function "colouring" (sync vs async) is what bothers me the most. It seems like, either way, we'll have to duplicate a lot of code. There is obvious duplication in the Client, but in our case, this ripple down the resources as well. I'd like to suggest a 3rd -more radical- approach: go full async, as new major version. This library is dealing with network, where async/await is a great choice. Modern Python is going more and more async, after all. If folks don't want async, they can either stay on an older version, before the major bump, or use an |
Beta Was this translation helpful? Give feedback.
-
Since the introduction of the async/await pattern in Python 3.5, more and more open source tools are using async implementations. This is also the case for Music Assistant, where Deezer is already integrated using this library in Music Assistant 2 beta. Since Music Assistant needs to handle many requests in a highly performant way, @Un10ck3d implemented an async version of this library in a fork. We believe it would be better to provide both the sync and async implementations of the client in one project. This would reduce the overall maintenance required to keep both repos up to date, and people would not have to choose between two libraries.
There are several ways to achieve this goal.
Both implementations in one Client class
We could simply introduce an async version for each function. To avoid doing all the work twice, we could implement an additional function that generates the URL, params, and (if needed) body for the request. For example
In addition, we would also implement an AsyncPaginatedList to provide a high performance async iteration. The aiohttp client could also be initiated in the
async_request
function on the first call, if it is not already available. This way, we would not carry an aiohttp client for those, who only want to use the the sync implementation.An AsyncClient and a Client class
Alternatively, we could create an AbstractClient that contains all the URL, params and body generation, and then derive the Client and AsyncClient from it:
In this case, we should also implement classes that provide methods like
Artist
in sync and async to not mix the patterns here.How does the community feel about this? Do you prefer one of these solutions or do you have another approach? And most importantly: Do you think there are good reasons to include an async implementation or should it not be part of this library? Thanks in advance for a good discussion 👍
Beta Was this translation helpful? Give feedback.
All reactions