Skip to main content

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 2026-10-01 4.1
1 2026-09-01 4.2
2 2026-08-01 4.1
3 2026-07-01 4.1
4 2026-06-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()
{
"Information": "Thank you for using Alpha Vantage! Please consider spreading out your free API requests more sparingly (1 request per second). You may subscribe to any of the premium plans at https://www.alphavantage.co/premium/ to lift the free key rate limit (25 requests per day) raise the per-second burst limit and instantly unlock all premium endpoints"
} NaN NaN