Caching Queries

In some cases it is sensible to cache queries to avoid overloading the IEX servers. iexfinance supports the caching of queries through requests_cache_.


Install requests-cache using pip:

$ pip install requests-cache

To use a cached session, pass a requests_cache.Session object to the top-level function you are using:

import datetime
from iexfinance.stocks import Stock
import requests_cache

expiry = datetime.timedelta(days=3)
session = requests_cache.CachedSession(cache_name='cache',

f = Stock("AAPL", session=session)

A SQLite file named cache.sqlite will be created in the working directory, storing the request until the expiry date.

For more information about requests-cache, see its Documentation.

Caching mechanism similar to Pandas Datareader.