Python Stock API Example

A simple Python example was written for us by Femto Trader. There is a small example, more information you can find on GitHub, check python-eodhistoricaldata.

import requests

import pandas as pd

from io import StringIO

def get_eod_data(symbol=”AAPL.US”, api_token=”xxxx”, session=None):

if session is None:

session = requests.Session()

url = ‘’ % symbol

params = {“api_token”: api_token}

r = session.get(url, params=params)

if r.status_code ==

df = pd.read_csv(StringIO(r.text), skipfooter=1, parse_dates=[0], index_col=0, engine=’python’)

return df

else:raise Exception(r.status_code, r.reason, url)

You can download data simply using

df = get_eod_data(“AAPL.US”)

And if you want to avoid too much data consumption, you can use a cache mechanism

import datetime

import requests_cache

expire_after = datetime.timedelta(days=1)

session = requests_cache.CachedSession(cache_name=’cache’, backend=’sqlite’, expire_after=expire_after)

df = get_eod_data(“AAPL.US“, session=session)

Register & Get Data

Great thanks to Femto Trader (Github) and don’t forget about the full python example python-eodhistoricaldata.