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()
0 |
2025-05-01 |
4.2 |
1 |
2025-04-01 |
4.2 |
2 |
2025-03-01 |
4.2 |
3 |
2025-02-01 |
4.1 |
4 |
2025-01-01 |
4.0 |
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()
0 |
2025-06-24 |
1260.545 |
1282.5710 |
1255.000 |
1279.11 |
1279.11 |
2642105 |
0.0 |
1.0 |
1 |
2025-06-23 |
1238.025 |
1254.8400 |
1215.010 |
1253.54 |
1253.54 |
2667318 |
0.0 |
1.0 |
2 |
2025-06-20 |
1234.450 |
1248.4999 |
1224.349 |
1231.41 |
1231.41 |
5348193 |
0.0 |
1.0 |
3 |
2025-06-18 |
1229.990 |
1241.9999 |
1220.500 |
1222.29 |
1222.29 |
2281047 |
0.0 |
1.0 |
4 |
2025-06-17 |
1219.950 |
1232.3569 |
1216.090 |
1220.67 |
1220.67 |
1892126 |
0.0 |
1.0 |