pandas-datareader icon indicating copy to clipboard operation
pandas-datareader copied to clipboard

asyncio support for http requests.

Open graingert opened this issue 8 years ago • 6 comments

While most of pandas is CPU bound, so would make sense running in a dedicated process. This particular module is very IO heavy.

I would like to make use of some of these methods in a Sanic web app, however the following code would stall the web server for all requests:

import pandas_datareader as pdr

@app.route('yahoo/aapl')
async def aapl():
    return process_response(pdr.get_data_yahoo('AAPL'))  # blocks, and stalls all other requests!

however with this code, I can wait for the yahoo API call while all my other web server requests are processed:

from pandas_datareader import aio as pdr

@app.route('yahoo/aapl')
async def aapl():
    return process_response(await pdr.get_data_yahoo('AAPL'))  # suspends coroutine, other coroutines can process other requests.

graingert avatar May 02 '17 10:05 graingert

Description, reason for adding?

bashtage avatar May 02 '17 10:05 bashtage

@bashtage done

graingert avatar May 02 '17 10:05 graingert

Does this impose minimum Python version? In particular, does it work for 2.7?

bashtage avatar May 07 '17 20:05 bashtage

There's trollius for legacy pythons, but yes it would. I envisaged this as a shared sans-io core with asyncio and synchronous apis made available separately

graingert avatar May 07 '17 20:05 graingert

@graingert with pdr moving to Python3 only, would you offer a prototype PR for this?

gliptak avatar Sep 28 '19 21:09 gliptak

@graingert I'm running into a situation where this would be very useful. Do you know if this was ever implemented, here or elsewhere?

gregbsmith avatar Sep 19 '23 01:09 gregbsmith