Download FRED data in Python with or without an API key

FRED is a free database from the Federal Reserve Bank of St. Louis with about 850,000 economic time series, mostly about the US. I show two ways to download FRED’s data into Python. First, as a CSV link without using an API key, and second, via the free FRED API. I mainly focus on downloading the daily 1-, 3-, 5- and 10-year Treasury yields.
Downloading without a key
To get the URL needed for the download, I click “Daily” under each of the four yields on FRED’s Treasury Constant Maturity page. Each series has an ID in the last part of its page address; in my case, with the Treasuries, it is DGS1, DGS3, DGS5, and DGS10.
We can use these IDs as follows. Add “?id=” together with the IDs, separated by commas, to https://fred.stlouisfed.org/graph/fredgraph.csv, such as https://fred.stlouisfed.org/graph/fredgraph.csv?id=DGS1,DGS3,DGS5,DGS10. Then the four daily series come as one CSV file using pd.read_csv. In contrast, when combining daily and monthly series, the data needs to be read as a ZIP file instead.
import pandas as pd
URL = "https://fred.stlouisfed.org/graph/fredgraph.csv"
IDS = "DGS1,DGS3,DGS5,DGS10"
END = "2026-11-19"
rates = pd.read_csv(f"{URL}?id={IDS}", parse_dates=["observation_date"],
index_col="observation_date").loc[:END]
print(rates) DGS1 DGS3 DGS5 DGS10
observation_date
1962-01-02 3.22 3.70 3.88 4.06
1962-01-03 3.24 3.70 3.87 4.03
1962-01-04 3.24 3.69 3.86 3.99
1962-01-05 3.26 3.71 3.89 4.02
1962-01-08 3.31 3.71 3.91 4.03
... ... ... ... ...
2026-11-13 4.65 4.92 4.98 5.15
2026-11-16 4.62 4.87 4.93 5.12
2026-11-17 4.60 4.84 4.90 5.10
2026-11-18 4.62 4.84 4.89 5.07
2026-11-19 4.62 4.81 4.86 5.04
[16928 rows x 4 columns]
Each row is a weekday from 2 January 1962 to 19 November 2026, where values for each series are expressed in percent.
Downloading with the API
Using the API requires a key, which FRED provides for free when you create an account at fredaccount.stlouisfed.org. Then you can request a key under API Keys. Once you have the key, you can save it on your Windows machine instead of in the notebook, which would otherwise expose it if you accidentally shared your notebook with someone else. On Windows, save the key in PowerShell with setx FRED_API_KEY "your key". Then close Jupyter and the program you started it from, reopen both, and run the notebook from the first cell.
Each API download includes the series description and its values.
import os
import requests
API = "https://api.stlouisfed.org/fred"
KEY = os.environ["FRED_API_KEY"]
api_rates = {}
for series_id in IDS.split(","):
response = requests.get(f"{API}/series",
params={"series_id": series_id, "api_key": KEY, "file_type": "json"},
timeout=30)
response.raise_for_status()
series = response.json()["seriess"][0]
print(series_id, "|", series["title"], "|", series["units"], "|", series["frequency"])
response = requests.get(f"{API}/series/observations",
params={"series_id": series_id, "api_key": KEY, "file_type": "json",
"observation_end": END},
timeout=30)
response.raise_for_status()
observations = pd.DataFrame(response.json()["observations"])
api_rates[series_id] = pd.to_numeric(observations["value"], errors="coerce").set_axis(
pd.to_datetime(observations["date"]))
api_rates = pd.DataFrame(api_rates)
print(api_rates)
print(api_rates.equals(rates))DGS1 | Market Yield on U.S. Treasury Securities at 1-Year Constant Maturity, Quoted on an Investment Basis | Percent | Daily
DGS3 | Market Yield on U.S. Treasury Securities at 3-Year Constant Maturity, Quoted on an Investment Basis | Percent | Daily
DGS5 | Market Yield on U.S. Treasury Securities at 5-Year Constant Maturity, Quoted on an Investment Basis | Percent | Daily
DGS10 | Market Yield on U.S. Treasury Securities at 10-Year Constant Maturity, Quoted on an Investment Basis | Percent | Daily
DGS1 DGS3 DGS5 DGS10
date
1962-01-02 3.22 3.70 3.88 4.06
1962-01-03 3.24 3.70 3.87 4.03
1962-01-04 3.24 3.69 3.86 3.99
1962-01-05 3.26 3.71 3.89 4.02
1962-01-08 3.31 3.71 3.91 4.03
... ... ... ... ...
2026-11-13 4.65 4.92 4.98 5.15
2026-11-16 4.62 4.87 4.93 5.12
2026-11-17 4.60 4.84 4.90 5.10
2026-11-18 4.62 4.84 4.89 5.07
2026-11-19 4.62 4.81 4.86 5.04
[16928 rows x 4 columns]
True
As a robustness check, I verify whether using the API gives the same data as using the CSV link, and it is “True”. The descriptions show that these series are daily, have constant maturities, and are quoted in percent on an investment basis.
This product uses the FRED® API but is not endorsed or certified by the Federal Reserve Bank of St. Louis.
Checking the missing days
print(rates.isna().sum())
year_2024 = rates.loc["2024"]
print(year_2024[year_2024["DGS10"].isna()])DGS1 722
DGS3 722
DGS5 722
DGS10 722
dtype: int64
DGS1 DGS3 DGS5 DGS10
observation_date
2024-01-01 NaN NaN NaN NaN
2024-01-15 NaN NaN NaN NaN
2024-02-19 NaN NaN NaN NaN
2024-03-29 NaN NaN NaN NaN
2024-05-27 NaN NaN NaN NaN
2024-06-19 NaN NaN NaN NaN
2024-07-04 NaN NaN NaN NaN
2024-09-02 NaN NaN NaN NaN
2024-10-14 NaN NaN NaN NaN
2024-11-11 NaN NaN NaN NaN
2024-11-28 NaN NaN NaN NaN
2024-12-25 NaN NaN NaN NaN
I also show days when the yields are missing; these are the same 722 weekdays, mostly holidays such as New Year’s Day and Christmas.
Conclusion
FRED is a convenient, easy-to-use macroeconomic database with most data on the US. You can access the data through a URL and a CSV link, or use an API key (also free), and with the API you also get a description of each series when you download it.
References
Board of Governors of the Federal Reserve System (US). (2026a). Market yield on U.S. Treasury securities at 1-year constant maturity, quoted on an investment basis [DGS1]. FRED, Federal Reserve Bank of St. Louis. Retrieved November 22, 2026, from https://fred.stlouisfed.org/series/DGS1
Board of Governors of the Federal Reserve System (US). (2026b). Market yield on U.S. Treasury securities at 3-year constant maturity, quoted on an investment basis [DGS3]. FRED, Federal Reserve Bank of St. Louis. Retrieved November 22, 2026, from https://fred.stlouisfed.org/series/DGS3
Board of Governors of the Federal Reserve System (US). (2026c). Market yield on U.S. Treasury securities at 5-year constant maturity, quoted on an investment basis [DGS5]. FRED, Federal Reserve Bank of St. Louis. Retrieved November 22, 2026, from https://fred.stlouisfed.org/series/DGS5
Board of Governors of the Federal Reserve System (US). (2026d). Market yield on U.S. Treasury securities at 10-year constant maturity, quoted on an investment basis [DGS10]. FRED, Federal Reserve Bank of St. Louis. Retrieved November 22, 2026, from https://fred.stlouisfed.org/series/DGS10