Add support for concurrent requests via asyncio and aiohttp #207
As suggested in #187
This is my first public PR, so please be gentle ;)
There are a significant amount of new classes here, because it's generally considered a bad idea to mix asynchronous and synchronous code. However, I've tried to keep the usage similar between the Client and the new AsyncClient where possible. I've also tried to inherit from existing classes to minimise impact, where it seemed logical to do so.
The major difference is that to instantiate the AsyncClient, you need to run AsyncClient.create() which is both a coroutine and a classmethod and returns the client instance. This my preferred way of working around the need to await coroutines in init() (see ).
Once your AsyncClient is instantiated, you can call client.service.operation() as normal, but this is now a coroutine which needs to be awaited. I've included an example showing usage (examples/async_example.py).
There are however a few caveats of which I'm aware:
First of all, this looks really cool! Thanks. So the issue now is that this uses 3.5+ only syntax, so we need to see if can we can make this work as something like a plugin that can optionally be enabled. However to be honest, I first want to get a stable 1.0 release out before making these changes.
I will keep this PR and might build upon it for a later version.
Again really appreciated!
Absolutely - I imagine there would need to be some sort of difficult decision made in that regard.
You could make this compatible with python 3.4 by instead coding the coroutines using the old
Also, the 3.4 asyncio was backported to 3.3, it's just not in the standard libs for that version.
I've seen trollius discussed on other packages where python 2.7 support is needed, but unfortunately it's no longer maintained. Sorry, I have no real expertise in that area as I pretty much exclusively work in 3.4 or later.
So, lots of different ways you could approach this down the line, each with their pros and cons. With that in mind, I completely understand your desire to reach 1.0 before dealing with all that!