botocore icon indicating copy to clipboard operation
botocore copied to clipboard

Support asyncio

Open jamesls opened this issue 10 years ago • 107 comments

This is a tracking issue for the feature request of supporting asyncio in botocore, originally asked about here: https://github.com/boto/botocore/issues/452

There's no definitive timeline on this feature, but feel free to +1 (thumbs up 👍) this issue if this is something you'd like to see. Also, if you have any additional information about asyncio you'd like to share (even just about your specific use case) feel free to chime in.

jamesls avatar Feb 12 '15 18:02 jamesls

Thanks for logging this! Currently I'm only calling list_distributions(..) and create_distribution(..) on a boto3.client('cloudfront') instance, which I know is a small fraction of the boto3 API, but it'd be nice if those calls cooperatively yielded in between making the request and receiving the response so that other coroutines in my app could run in the meantime. (I could always just roll my own client using aiohttp too since I'm using so little of the API, but figured it was worth asking about anyway.)

In case it helps, aiodns provides an example of supporting asyncio on Python 2.6+ (see https://github.com/saghul/aiodns#python-versions).

If boto3 was already written with the assumption of blocking rather than asynchronous I/O throughout, I'm not sure how disruptive a change this would be.

jab avatar Feb 12 '15 20:02 jab

I'm not that familiar with the internals of botocore, but I think the right approach is to create a custom version of endpoint.py and client.py that used aiohttp under the hood and yielded as you want.

I would probably start by subclassing Endpoint and making an aiohttp version of _send_request and _get_request. I'd also subclass ClientCreator and override _create_api_method (that is where the calls to the endpoint come from). I haven't yet figured out how i'd get from a service object to a client created with my ClientCreator subclass.

Does that sound right, @jamesls? I might have a go...

Jc2k avatar Feb 14 '15 11:02 Jc2k

I've started a port of botocore to asyncio, at:

https://github.com/rdbhost/botocore

So far, the S3 integration tests pass, as do about 2/3 of the unit tests. I hope to have all tests converted and passing by a week from now.

The port depends on yieldfrom.requests and yieldfrom.urllib3 , asyncio ports of the requests and urllib3 libraries.

rdbhost avatar Mar 04 '15 16:03 rdbhost

@rdbhost Awesome! Thanks for working on this. Definitely interested to follow your progress. @jamesls / botocore maintainers, had a chance to check this out / evaluate for merge potential?

jab avatar Mar 14 '15 16:03 jab

+1

koliyo avatar Jun 15 '15 12:06 koliyo

+1

AlexNigl avatar Jun 18 '15 12:06 AlexNigl

This issue has gotten a couple of +1s in the last few days, so I thought I would point out that the work is done, at:

https://github.com/rdbhost/yieldfromBotocore

It implements an asyncio version of botocore, not boto3. I may eventually convert boto3, but my own needs have been satisfied by botocore, so other things now have priority.

David

On Thu, Jun 18, 2015 at 6:59 AM, AlexNigl [email protected] wrote:

+1

— Reply to this email directly or view it on GitHub https://github.com/boto/botocore/issues/458#issuecomment-113148024.

rdbhost avatar Jun 18 '15 13:06 rdbhost

+1

amatthies avatar Jul 09 '15 10:07 amatthies

@rdbhost, thanks for tackling that! It seems, however, that https://github.com/rdbhost/yieldfromBotocore is 271 commits behind upstream. Are you actively maintaining it?

jmehnle avatar Jul 09 '15 17:07 jmehnle

My intention has been to do a merge when upstream reached v1.0; that seems to have happened without my noticing.

I will be merging commits from upstream, this weekend.

rdbhost avatar Jul 09 '15 18:07 rdbhost

+1 @jamesls are you planning on pulling rdbhost's changes into botocore itself? We are very interested in this feature.

r39132 avatar Jul 10 '15 22:07 r39132

It is not a very promising candidate for merging back into botocore.

The changes are numerous, and the changes needed to make botocore functional within asyncio make it non-functional outside asyncio. I expect it to be a seperate product indefinitely, with a parallel API, meaning an API as similar as possible within the asyncio constraints.

rdbhost avatar Jul 16 '15 18:07 rdbhost

One thing that also complicates things is that botocore supports as far back as python 2.6.5, so we'll need to figure out how we can support asyncio and still maintain py2 support. I see that there are asyncio backports to python2, so perhaps something could be done there.

jamesls avatar Jul 16 '15 21:07 jamesls

Trollius (asyncio port to Python 2.x) is complete and stable.

jmehnle avatar Jul 16 '15 21:07 jmehnle

+1

harai avatar Sep 13 '15 02:09 harai

I have working port of botocore for asyncio: https://github.com/jettify/aiobotocore using aiohttp for async http requests. I am trying to reuse as much botocore code as possible, so I patched only several classes and just import rest of the code as result library has few hundreds lines of code. And this approach helps to keep up with upstream, but obvious downside, I rely on internal interfaces which is subject of change for new libs. API almost the same as botocore just yield from or awaite (python 3.5) should be added before calls.

For now I am using aiobotocore with s3 and ported almost all s3 test, except I need to work more on pagination since it is not easy to implement iterator protocol with yield from.

jettify avatar Sep 13 '15 08:09 jettify

+1 integrating aiobotocore might be doable

mpaolini avatar Sep 14 '15 18:09 mpaolini

+1

balihoo-gens avatar Oct 09 '15 21:10 balihoo-gens

+1

mikeplavsky avatar Nov 25 '15 22:11 mikeplavsky

+1

cgst avatar Dec 10 '15 01:12 cgst

+1

thomascellerier avatar Jan 28 '16 08:01 thomascellerier

OK guys, I've written a production ready, and hopefully useful to the community, asyncio extension to botocore. The library is currently included in https://github.com/quantmind/pulsar-cloud in the asyncbotocore module but it is self-contained and could be striped out if needed.

The API is the same as botocore but with the addition of http_session keyword which is an optional asyncio compatible HTTP client (it must expose the _loop attribute) and API similar to requests. As far as I know there are two of such clients:

  • pulsar http client
  • aiohttp http client (@asvetlov does aihttp client/session have the _loop attribute?)

If used with pulsar, the library can also use greenlet in an implicit asynchronous fashion. Check https://github.com/quantmind/pulsar-cloud for more info

By the way, thanks to @jettify for the initial effort from which I leveraged from

Feedbacks welcome!

lsbardel avatar Feb 04 '16 21:02 lsbardel

@lsbardel yes, aiohttp.ClientSession has _loop but I don't encourage using private attributes. BTW we use https://github.com/jettify/aiobotocore as aiohttp-based library.

asvetlov avatar Feb 04 '16 21:02 asvetlov

@asvetlov cool, I understand the private attribute thing, but the _loop attribute should be (almost) a standard for asyncio objects ;-) maybe we should ask guido.

I would be happy to use https://github.com/jettify/aiobotocore has low level async botocore library but currently it does not work with pulsar http client. At the moment it clearly requires aiohttp while cloud.asyncbototore does not require an asyncio library as such.

So maybe we should converge to a library that allows for different http clients?

lsbardel avatar Feb 05 '16 23:02 lsbardel

By the way all that is python 3.4 or above

lsbardel avatar Feb 05 '16 23:02 lsbardel

@lsbardel At asyncio active development times Guido was against public loop attribute, he motivated it as "user always may pass explicit loop if needed". I don't think the decision has changed now.

asvetlov avatar Feb 05 '16 23:02 asvetlov

+1

nadad avatar Feb 15 '16 09:02 nadad

+1

jmorris0x0 avatar Feb 22 '16 10:02 jmorris0x0

+1

frnkvieira avatar Apr 28 '16 14:04 frnkvieira

+1

Nath-P avatar May 10 '16 07:05 Nath-P