FRED data in Python

About 850,000 economic time series from the Federal Reserve Bank of St. Louis.
Published

November 25, 2026

Updated

November 29, 2026

FRED’s CSV link is free and needs no account or key. Run pip install pandas. The script saves one long-format CSV in FOLDER (default Downloads), overwriting any file of the same name.

If a script does not work as it should, email me.

Any series by its ID

One row per date and series, in each series’ units. The example takes the daily 1-, 3-, 5- and 10-year Treasury yields in percent (DGS1, DGS3, DGS5 and DGS10) from 2 January 1962. Dates without a value are left out.

Choose these settings in the code:

  • IDS, the series IDs, all of one frequency, from their pages on fred.stlouisfed.org.
  • START and END, the first and last dates. END = None takes the latest date.
  • FOLDER, the output folder.
from pathlib import Path

import pandas as pd

URL = "https://fred.stlouisfed.org/graph/fredgraph.csv"
IDS = "DGS1,DGS3,DGS5,DGS10"         # series IDs of the same frequency, from each series' page on fred.stlouisfed.org
START, END = "1962-01-01", None      # the first and last dates to keep (None keeps the latest)
FOLDER = Path.home() / "Downloads"   # change this to the folder for the CSV file

# Step 1. Download the series, one column per series
rates = pd.read_csv(f"{URL}?id={IDS}", parse_dates=["observation_date"],
                    index_col="observation_date", na_values=["."]).loc[START:END]

# Step 2. Long format, one row per date and series (dates without a value left out), saved as one CSV file
panel = (rates.rename_axis("date").reset_index()
         .melt(id_vars="date", var_name="series", value_name="value").dropna())
FOLDER.mkdir(parents=True, exist_ok=True)
panel.to_csv(FOLDER / f"fred_{IDS.replace(',', '_')}.csv", index=False)
print(len(panel), "rows saved")

Full post: Download FRED data in Python with or without an API key