Prism Data Lab

Every analysis here ships its dataset and the code that produced every figure. Nothing on this site is investment advice.

Data SourcesUpdated 2,070 words, 9 minutes

Pulling FRED series without an API key: fredgraph.csv in Python

FRED's fredgraph.csv URL needs no key: a standard-library script to download and merge series, plus cosd, coed, fq, fam, transformation and vintage_date tested.

The FRED web service needs a key. The documentation says so in one sentence: "All web service requests require an API key to identify requests." What most tutorials skip is that the CSV behind the Download button on every series page does not. It is a stable URL with the series id as its only parameter, it returns the full history in two columns, and it is the endpoint every analysis on this site uses. This article is the tool we use to pull it, the three problems the raw file gives you, and a coverage check that catches the fourth. Updated October 30, 2026 with a tested reference for the URL's own parameters (cosd, coed, fq, fam, transformation, fgst, vintage_date and more): 33 requests, every response saved, and what each one returned.

The endpoint

https://fred.stlouisfed.org/graph/fredgraph.csv?id=DGS10

That is all the script needs; the optional parameters are tested further down. The response is a text file with a header row (observation_date,DGS10) and one row per observation. Daily series carry a row for every weekday including market holidays; monthly series carry the first of the month; quarterly series carry the first day of the quarter. When this article was first written we described a missing value as a single period, .. In the files we saved on October 30, 2026, a missing value was an empty cell. We kept no raw file from the first download to say which form it had then. The script handles both forms.

The script fetches each id with urllib.request, parses it with the csv module, replaces any . with an empty string, and returns a dictionary from date to value. Nothing outside the standard library is needed for the download; pandas (3.0.2 here) is imported only for the coverage table at the end.

BASE = "https://fred.stlouisfed.org/graph/fredgraph.csv?id="

def fetch(series_id: str) -> dict[str, str]:
    req = urllib.request.Request(BASE + series_id, headers={"User-Agent": "prism-data-lab/1.0 (research)"})
    with urllib.request.urlopen(req, timeout=60) as r:
        text = r.read().decode("utf-8")
    rows = list(csv.reader(io.StringIO(text)))
    header = rows[0]
    if len(header) < 2:
        raise SystemExit(f"{series_id}: unexpected header {header!r} (bad id?)")
    return {row[0]: ("" if row[1] == "." else row[1]) for row in rows[1:] if row}

When this article was first published we described a wrong series id as returning a page that is not a two-column CSV. On October 30, 2026 it returned HTTP 404 with a 29,491-byte HTML error page, which urlopen raises as an error before the header check runs. The header check stays for the cases that still arrive with status 200 and are not a two-column CSV, such as the ZIP archive described in the parameter section below.

Merging series that do not share a calendar

Two series pulled this way rarely line up. DGS10 is daily from the Federal Reserve's H.15 release; T10Y2Y is a daily spread FRED computes; CPIAUCSL is monthly. The script takes the union of all dates across the requested ids, sorts it, and writes one wide CSV with a blank cell wherever a series has no observation on that date. It does not forward-fill. Forward-filling a monthly CPI onto daily Treasury dates is a modelling decision, and it belongs in the analysis script where it can be seen, not in the download step where it cannot.

The --since flag trims the union of dates to a start date. It is applied after the download, so the full history is fetched regardless. The endpoint does take a start and end date (cosd and coed, tested below), but the files are small enough that trimming client-side costs little and keeps the script to one URL shape: the full daily DGS10 history back to 1962 was 269,219 bytes on October 30, 2026.

Running it

python code/fred-series-python-no-api-key.py DGS10 DGS2 T10Y2Y \
    --out datasets/fred-series-python-no-api-key.csv --since 2000-01-01

Output on 2026-09-06:

series first date last date observations empty cells in merged file
DGS10 2000-01-03 2026-09-03 6672 288
DGS2 2000-01-03 2026-09-03 6672 288
T10Y2Y 2000-01-03 2026-09-04 6673 287

The merged file has 6,960 rows. The 288 empty cells in DGS10 are the market holidays FRED lists without a value, plus one more: on 2026-09-06 the two constant-maturity yields ended on 2026-09-03 while the spread had a 2026-09-04 observation of 0.41. The H.15 yields and the spread FRED derives from Treasury's own curve are posted on different schedules, and for a day or two the derived series can be ahead of its components. Nobody warns you about this; the coverage table is what surfaces it.

The last rows of the file make the point concretely:

date DGS10 DGS2 T10Y2Y
2026-09-02 4.79 4.39 0.40
2026-09-03 4.77 4.34 0.43
2026-09-04 0.41

A script that computed DGS10 - DGS2 and compared it to T10Y2Y on the last row would compare a blank to a number. A script that dropped rows with any blank would silently lose the newest spread observation. Neither is wrong; both should be chosen on purpose.

The four problems, named

  1. The missing marker. A missing observation arrives as an empty cell, as it did on October 30, 2026, or as a single period, ., as this article first described it. pandas.read_csv(..., na_values=".") handles both; a plain float() handles neither. The script turns . into an empty cell, so downstream code sees a standard blank either way.
  2. The calendar. Daily series include holidays as rows with no value; monthly series are dated on the first of the month even when the release describes the whole month; weekly series such as MORTGAGE30US are dated on the survey's Thursday. Joining on date without knowing this produces a file that is mostly blanks and looks broken.
  3. Units. DGS10 is in percent; T10Y2Y is in percentage points; SP500 is an index level; PAYEMS is in thousands of persons. The CSV header carries none of this. The series page does, and the citation in an article should carry the series id and the retrieval date so that the units can be checked.
  4. Coverage and licensing. Some series are truncated by agreement with their owner. The SP500 series notes state that FRED "will include 10 years of daily history" for S&P Dow Jones Indices series, and that "since this is a price index and not a total return index, the S&P 500 index here does not contain dividends." A ten-year window that rolls forward every day means the first row of your file changes with each download, and a study that quotes "since 2016" today will not reproduce next year.

fredgraph.csv, parameter by parameter

FRED publishes no reference page for this URL, so on October 30, 2026 we tested it. After reading FRED's robots.txt (a one-second crawl delay, nothing disallowed for these paths), we sent 32 requests to fredgraph.csv, at least two seconds apart, and one to ALFRED for comparison, and saved every response. fredgraph-csv-parameters.py sends the same requests, saves them, and checks each answer against the plain file. For example, it recomputes a monthly average from the daily values. Its summary, one row per request, is fredgraph-csv-parameters.csv. Every request starts with https://fred.stlouisfed.org/graph/fredgraph.csv?.

request what came back
id=DGS10 16,912 daily rows, 1962-01-02 to 2026-10-28, 721 of them empty and none written as .; 269,219 bytes
id=DGS10&cosd=2026-01-01 214 rows, from 2026-01-02
id=DGS10&coed=1962-12-31 260 rows, 1962 only
id=DGS10&cosd=2026-01-01&coed=2026-03-31 63 rows, 2026-01-02 to 2026-03-31
the same two dates swapped the same 63 rows, byte for byte
id=DGS10&cosd=20260101 the full 16,912-row file: a date without dashes was ignored
...&fq=Monthly on the 2025 daily window 12 rows dated on the first of each month, each the month's mean (12 of 12 recomputed): fam=avg is the default
...&fq=Monthly&fam=eop the month's last daily value, 12 of 12
...&fq=Monthly&fam=sum the sum of the month's daily yields, 12 of 12 (97.21 for January 2025)
...&fq=Weekly,%20Ending%20Friday&fam=avg on January to March 2026 14 rows dated on Fridays, 2026-01-02 to 2026-04-03, each the mean of the seven days ending that Friday (14 of 14)
id=DGS10&cosd=2016-01-01&coed=2025-12-31&fq=Annual&fam=avg 10 rows dated January 1, each the calendar-year mean (10 of 10)
id=GDPC1&cosd=2025-01-01&fq=Monthly the 7 quarterly rows, unchanged
...&fq=Fortnightly the daily window, byte for byte
id=PAYEMS&cosd=2025-01-01&coed=2025-12-01&transformation=chg header PAYEMS_CHG; the month-on-month change, 12 of 12 equal to the level differences
id=CPIAUCSL&...&transformation=pch header CPIAUCSL_PCH; percent change from the month before, to five decimals, 10 of 10 computable months
id=CPIAUCSL&...&transformation=pc1 header CPIAUCSL_PC1; percent change from a year earlier, 11 of 11
id=CPIAUCSL&...&transformation=log header still CPIAUCSL; the natural log rounded to one decimal, so every month of 2025 reads 5.8
id=CPIAUCSL&...&transformation=xyz the plain index levels, HTTP 200
id=PAYEMS&cosd=2025-01-01&coed=2025-12-01&fgst=chg the chg values, under the plain header PAYEMS
id=PAYEMS&cosd=2026-01-01&vintage_date=2026-09-04 byte-identical to the same request without vintage_date, running to September 2026
id=DGS10,DGS2&cosd=2026-09-01&coed=2026-09-30 one CSV of 13,152 rows: the dates applied to DGS10 only, and DGS2 came back in full from 1976-06-01
id=DGS10,DGS2&cosd=2026-09-01,2025-01-01&coed=2026-09-30,2025-01-31 44 rows: September 2026 for DGS10, January 2025 for DGS2
id=DGS10,PAYEMS&cosd=2026-09-01&coed=2026-09-30 not a CSV: a ZIP archive (application/zip) holding README.txt, daily.csv and monthly.csv, with PAYEMS in full from 1939
id=DGS10,DGS2&cosd=2026-09-01&coed=2026-09-30&fml=a-b byte-identical to the request without fml
id=dgs10&cosd=2026-09-01&coed=2026-09-30 the DGS10 file: the id is not case-sensitive
id=NOTASERIES123 HTTP 404, a 29,491-byte HTML page

Five requests came back as HTTP 200 and looked like a normal answer while quietly ignoring what was asked: the undashed date, the unknown frequency, the unknown transformation, vintage_date and fml. A sixth, fq=Monthly on a quarterly series, returned the quarterly rows unchanged: frequency goes down, never up. Two requests changed the numbers without changing the column name: fgst=chg returns month-on-month changes under the header PAYEMS, and transformation=log returns a log rounded to one decimal under the header CPIAUCSL. The header check in the script above passes all of them.

Three findings matter most for anyone automating this endpoint.

  • vintage_date does nothing here. The fredgraph answer had July 2026 payrolls at 158,882 thousand and August at 159,015 and ran to September. ALFRED's own 2026-09-04 vintage, fetched the same morning, ends in August and has July at 158,913 and August at 159,075. For a past vintage, use alfredgraph.csv, tested in our ALFRED vintages article.
  • Several ids share one date pair only if you repeat the dates. With one cosd/coed, the window applied to the first id alone. With one date per id, separated by commas, each id got its own window.
  • Mixed frequencies come back as a ZIP archive. A daily and a monthly id in one request returned a ZIP archive instead of a CSV. The first line of the response begins with PK, so the script's header check stops it.

Weekly aggregation also reaches past the window. The first row, Friday 2026-01-02, reads 4.16, the mean of December 29 to January 2 (January 2 alone was 4.19), and the last row is dated Friday 2026-04-03, after the coed date of March 31. One more detail from the CPI requests: CPIAUCSL has no October 2025 value in the file, so pch is blank for both October and November 2025, and pc1 for October.

A safer pattern refuses any parameter outside the tested set and checks the answer's type and column name before reading a number:

TESTED = {"cosd", "coed", "fq", "fam", "transformation"}
SUFFIX = {"chg": "_CHG", "pch": "_PCH", "pc1": "_PC1"}   # 'log' is refused: one decimal only


def fredgraph(series: str, **params: str) -> str:
    bad = set(params) - TESTED
    if bad or params.get("transformation", "chg") not in SUFFIX:
        raise ValueError(f"untested parameter(s): {sorted(bad) or params['transformation']}")
    for k in ("cosd", "coed"):
        if k in params and len(params[k]) != 10:
            raise ValueError(f"{k} must be YYYY-MM-DD, got {params[k]!r}")
    url = BASE + series + "".join(f"&{k}={urllib.parse.quote(v)}" for k, v in params.items())
    req = urllib.request.Request(url, headers={"User-Agent": "prism-data-lab/1.0 (research)"})
    with urllib.request.urlopen(req, timeout=60) as r:
        if r.headers.get("Content-Type") != "application/csv":
            raise ValueError(f"{series}: got {r.headers.get('Content-Type')}, not a CSV")
        text = r.read().decode("utf-8")
    want = "observation_date," + series.upper() + SUFFIX.get(params.get("transformation"), "")
    if text.splitlines()[0] != want:
        raise ValueError(f"{series}: header {text.splitlines()[0]!r}, expected {want!r}")
    return text

It cannot catch an ignored fq value, because the column name does not change. Count the rows instead: a monthly request for one year should return 12.

Why the retrieval date matters

FRED revises. Monthly payrolls are revised twice after the first print and benchmarked annually; GDP has three estimates and then annual and comprehensive revisions; even the H.15 yields are occasionally corrected. The CSV endpoint serves the current vintage only. If a figure in an article needs to be reproducible, the article must ship the file it used, dated, because the same URL will serve different numbers later. Every dataset on this site carries its retrieval date in the article's Sources list for that reason, and the --since trimming keeps the shipped file to the window the analysis uses.

FRED also has a vintage archive (ALFRED) for those who need the number as it was known on a given day. It is a different tool for a different question, covered in our ALFRED vintages article; for "what does the series say now", the plain CSV is enough.

What this does not cover

The script does not authenticate, so it cannot use the search, categories, or release-calendar features of the keyed API, and it cannot ask for a specific vintage, because fredgraph.csv ignores vintage_date (tested above). It does not retry: a network failure raises and stops, which is the right behaviour for a download step that another script depends on. It does not resample, fill, or convert frequency, on purpose. And it does not verify that the series you asked for is the series you meant: CPIAUCSL and CPIAUCNS are the same index seasonally adjusted and not, and the endpoint will hand you either without comment. Read the series page once; then automate.

This article is analysis and education, not investment, tax, or legal advice. Figures are cited to their source and dated; check them before relying on them.