EODHD APIs Python Financial Library by Michael Whittle

We recomend to start by creating a Python virtual environment to install the Official EODHD APIs Python Library, alternatively, you can install it by using PIP: “python3 -m pip install eodhd -U” or “pip install eodhd -U”. The “-U” will upgrade the library if it is installed already but out of date.

eodhd-medium % python3 -m venv venv
eodhd-medium % source venv/bin/activate
(venv) eodhd-medium % python3 -m pip install eodhd -U
Collecting eodhd
  Downloading eodhd-1.0.7-py3-none-any.whl (7.9 kB)
Requirement already satisfied: rich==12.5.1 in ./venv/lib/python3.9/site-packages (from eodhd) (12.5.1)
Requirement already satisfied: numpy==1.21.6 in ./venv/lib/python3.9/site-packages (from eodhd) (1.21.6)
Requirement already satisfied: pandas==1.3.5 in ./venv/lib/python3.9/site-packages (from eodhd) (1.3.5)
Requirement already satisfied: websockets==10.3 in ./venv/lib/python3.9/site-packages (from eodhd) (10.3)
Requirement already satisfied: websocket-client==1.3.3 in ./venv/lib/python3.9/site-packages (from eodhd) (1.3.3)
Requirement already satisfied: requests==2.28.1 in ./venv/lib/python3.9/site-packages (from eodhd) (2.28.1)
Requirement already satisfied: pytz>=2017.3 in ./venv/lib/python3.9/site-packages (from pandas==1.3.5->eodhd) (2022.2.1)
Requirement already satisfied: python-dateutil>=2.7.3 in ./venv/lib/python3.9/site-packages (from pandas==1.3.5->eodhd) (2.8.2)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in ./venv/lib/python3.9/site-packages (from requests==2.28.1->eodhd) (1.26.11)
Requirement already satisfied: charset-normalizer<3,>=2 in ./venv/lib/python3.9/site-packages (from requests==2.28.1->eodhd) (2.1.1)
Requirement already satisfied: certifi>=2017.4.17 in ./venv/lib/python3.9/site-packages (from requests==2.28.1->eodhd) (2022.6.15)
Requirement already satisfied: idna<4,>=2.5 in ./venv/lib/python3.9/site-packages (from requests==2.28.1->eodhd) (3.3)
Requirement already satisfied: pygments<3.0.0,>=2.6.0 in ./venv/lib/python3.9/site-packages (from rich==12.5.1->eodhd) (2.13.0)
Requirement already satisfied: commonmark<0.10.0,>=0.9.0 in ./venv/lib/python3.9/site-packages (from rich==12.5.1->eodhd) (0.9.1)
Requirement already satisfied: six>=1.5 in ./venv/lib/python3.9/site-packages (from python-dateutil>=2.7.3->pandas==1.3.5->eodhd) (1.16.0)
Installing collected packages: eodhd
Successfully installed eodhd-1.0.7

1. Use “DEMO” API key to test our data from a limited set of the tickers without registering:
AAPL.US | TSLA.US | VTI.US | AMZN.US | BTC-USD | EUR-USD
Real-Time Data and All of the APIs (except Bulk) are included without limitations on API calls.
2. Register to get your free API key (limitated by 20 API calls per day) with access to:
End-Of-Day Historical Data with only past year for any ticker and List of tickers per Exchange
3. To unlock your API key we recommend to choose subscription which covers your needs

Register & Get Data

To get started, you’ll need to import “APIClient” for the Library.

from eodhd import APIClient

Next is loading the Library.

api = APIClient("<Your_API_Key>")

The code above will require you to pass your API key directly into the APIClient class.

There are nicer ways do this like retrieving the API key from an environment variable.

import os

api_key = os.environ.get("EODHD_API_KEY")
api = APIClient(api_key)

Or retrieving the API key from a config file.

# config.py

API_KEY = "YOUR_API_KEY"

# main.py
import config as cfg
api = APIClient(cfg.API_KEY)

The Library is ready for work now. Next we recommend is to follow into our Academy section where you’ll be able to learn more of how to use it from article “Download EOD, Intraday and Real-time prices for any Cryptocurrency with Python simply” by Michael Whittle.

Python Financial APIs SDK by Lautaro Parada

The Python Financial APis SDK is a library is the Python SDK provided by our clients for our REST API. It’s intended to be used for data extraction for financial valuations, macroeconomic analyses, sentiment analysis, option strategies, technical analysis, development of machine learning models, and more!

You can also use our comprehensive video instruction on How to Use Python Financial APIs SDK.

The library requires Python 3.8+ and can be found and downloaded on GitHub: https://github.com/LautaroParada/eod-data.

APIs are covered with the SDK:

  • Historical Prices, Splits and Dividends Data APIs.
  • Historical Splits, Dividends and Short Interest API.
  • Techinical Indicator API.
  • Intraday Historical API.
  • Options Data API.
  • Fundametnal and Economic Data APIs.
  • Insider Transaction API.
  • Fundamental Data: Stocks, ETFs, Mutual Funds, Indices.
  • Calendar. Upcoming Earnings, Trends, IPOs and Splits.
  • Macroeconomics Data and Macro Indicators API.
  • Bulk API for EOD, Splits and Dividends.
  • Exchanges API with list of tickers and extended data, trading hours and Market Holidays.
  • Stock Market Screener API.
  • Search API for Stocks, ETFs, Mufual Funds and Indices.

More information with examples and a comprehensive readme file you can find on the Github page for the Python Financial APis SDK.

Register & Get Data

And we also have very simple python stock API examples for a quick start below on that page.

Python Stock API Example

It’s easy to download our JSON API with Python scripts, please do not forget to change the API token to yours, which you can get on the settings page after the free registration.

import urllib, json

url = "https://eodhistoricaldata.com/api/eod/AAPL.US?api_token=YOUR_API_TOKEN&order=d&fmt=json"

response = urllib.urlopen(url)

data = json.loads(response.read())

print data

There is also a simple Python example that was written for us by Femto Trader, for 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 = 'https://eodhistoricaldata.com/api/eod/%s' % symbol

params = {"api_token": api_token}

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

if r.status_code == requests.codes.ok:

df = pd.read_csv(StringIO(r.text), skipfooter=0, 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.