Requests: async and await

Created on 3 Oct 2015  ·  1Comment  ·  Source: psf/requests

Python 3.5 introduced coroutines with async and await syntax. Specification about that can be read in PEP 492.

Are there any plans to support this? Because of network lags or slow connections it would make sense to make asynchronous http requests.

Most helpful comment

@screendriver At the current time there are no plans to support async and await. This is not because they aren't a good idea: they are. It's because to use them requires quite substantial code changes.

Right now requests is a purely synchronous library that, at the bottom of its stack, uses httplib to send and receive data. We cannot move to an async model unless we replace httplib. The best we could do is provide a shorthand to run a request in a thread, but asyncio already has just such a shorthand, so I don't believe it would be valuable.

Right now I am quietly looking at whether we can rewrite requests to work just as well in a synchronous environment as in an async one. However, the reality is that doing so will be a lot of work, involving rewriting a lot of our stack, and may not happen for many years, if ever.

>All comments

@screendriver At the current time there are no plans to support async and await. This is not because they aren't a good idea: they are. It's because to use them requires quite substantial code changes.

Right now requests is a purely synchronous library that, at the bottom of its stack, uses httplib to send and receive data. We cannot move to an async model unless we replace httplib. The best we could do is provide a shorthand to run a request in a thread, but asyncio already has just such a shorthand, so I don't believe it would be valuable.

Right now I am quietly looking at whether we can rewrite requests to work just as well in a synchronous environment as in an async one. However, the reality is that doing so will be a lot of work, involving rewriting a lot of our stack, and may not happen for many years, if ever.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

remram44 picture remram44  ·  4Comments

xsren picture xsren  ·  3Comments

Matt3o12 picture Matt3o12  ·  3Comments

jake491 picture jake491  ·  3Comments

avinassh picture avinassh  ·  4Comments