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-08-01 |
4.3 |
1 |
2025-07-01 |
4.2 |
2 |
2025-06-01 |
4.1 |
3 |
2025-05-01 |
4.2 |
4 |
2025-04-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()
0 |
2025-10-08 |
1197.11 |
1217.000 |
1192.00 |
1214.25 |
1214.25 |
2846675 |
0.0 |
1.0 |
1 |
2025-10-07 |
1177.79 |
1201.365 |
1177.46 |
1191.06 |
1191.06 |
3309094 |
0.0 |
1.0 |
2 |
2025-10-06 |
1160.37 |
1163.580 |
1145.45 |
1163.31 |
1163.31 |
2968596 |
0.0 |
1.0 |
3 |
2025-10-03 |
1165.00 |
1168.000 |
1143.22 |
1153.32 |
1153.32 |
3137365 |
0.0 |
1.0 |
4 |
2025-10-02 |
1161.50 |
1163.330 |
1134.00 |
1162.53 |
1162.53 |
4685467 |
0.0 |
1.0 |