This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
Suggestion: use of an async request framework (as replacement for requests
)
#306
Labels
enhancement
New feature or request
Is your feature request related to a problem? Please describe.
The issue is that many (most?) modern python web frameworks are working in an asynchronous fashion (ASGI). The current API you are offering is purely synchronous which make it
"impossible" to use with such frameworks.
Describe the solution you'd like
Most of the time I'm using aiohttp, its interface is very close to
requests
which makes it a good candidate.Describe alternatives you've considered
I'm currently re-writing it for myself.
Remark
Also, that's a bit related so I will answer this remark from your code:
I think it's not too much of a problem, the real problem is underlying. You are creating one session per init (and therefore per inherited class), the code looks a bit like this:
I think you should spawn a single HTTP session for all APIs (unless there is a good reason not to). Then, you could use that unique session in all subclasses (passing it as argument to the
HTTpClient
). You don't even need to have a singleton for that an can simply use a lazy property directly inDuffel
client, like so (the code is already usingaiohttp
because I've already rewrote this part):This way, all HTTP requests will use the same session (single TCP handshake).
You could also directly offer the enduser the opportunity to start the session on its own (for example when the server starts).
The text was updated successfully, but these errors were encountered: