Appendix D — The AlphaVantage API

The AlphaVantage API is a wealth of financial and market datasets.

For more information, see the APIs tutorial.

After obtaining an API key, and setting the API Key as a notebook secret, we are able to access the API key in a secure way:

from google.colab import userdata

API_KEY = userdata.get("ALPHAVANTAGE_API_KEY")

Then we supply the API Key value along with our requests.

For example, requesting unemployment rates:

from pandas import read_csv

request_url = f"https://www.alphavantage.co/query?function=UNEMPLOYMENT&apikey={API_KEY}&datatype=csv"
df = read_csv(request_url)
df.head()
timestamp value
0 2025-11-01 4.6
1 2025-10-01 .
2 2025-09-01 4.4
3 2025-08-01 4.3
4 2025-07-01 4.2

Requesting stock prices:

from pandas import read_csv

symbol = "NFLX"
request_url = f"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol={symbol}&apikey={API_KEY}&datatype=csv"
df = read_csv(request_url)
df.head()
timestamp open high low close adjusted_close volume dividend_amount split_coefficient
0 2026-01-09 90.000 90.040 88.32 89.46 89.46 55403077 0.0 1.0
1 2026-01-08 90.450 91.250 89.58 90.53 90.53 40068670 0.0 1.0
2 2026-01-07 91.555 92.419 90.06 90.73 90.73 36525740 0.0 1.0
3 2026-01-06 91.540 91.640 89.74 90.65 90.65 43330972 0.0 1.0
4 2026-01-05 90.920 92.630 90.84 91.46 91.46 39183316 0.0 1.0