Treasury yield curve API and CPI data in Python
Get the daily US Treasury par yield curve since 1990, CPI, payrolls and other BLS and Treasury series as JSON, and compute spreads and inflation without handling flat files.
The Treasury publishes the par yield curve as a daily table and the Bureau of Labor Statistics publishes CPI, payrolls and wages as flat files, each with its own layout. SecFeed loads both into one shape: /v1/treasury/yield-curve for the full curve per date, and /v1/economic/series plus /v1/economic/observations for every other series.
Setup
import os
import requests
H = {"Authorization": "Bearer " + os.environ["SECFEED_KEY"]}
BASE = "https://secfeedapi.com/v1"
Today's curve and the 10 year minus 2 year spread
r = requests.get(BASE + "/treasury/yield-curve", headers=H, params={"size": 1}).json()
c = r["curves"][0]
print(c["date"], {k: c["yields"][k] for k in ("3mo", "2yr", "10yr", "30yr")})
print("10yr minus 2yr:", round(c["yields"]["10yr"] - c["yields"]["2yr"], 2))
Output from a real run:
2026-11-27 {'3mo': 4.35, '2yr': 4.69, '10yr': 4.94, '30yr': 5.33}
10yr minus 2yr: 0.25
Each curve holds every tenor the Treasury published that day, from 1 month to 30 years, in percent. Pass startDate and endDate for history back to 1990:
r = requests.get(BASE + "/treasury/yield-curve", headers=H, params={"startDate": "2023-07-01", "endDate": "2023-07-07"}).json()
for c in r["curves"]:
print(c["date"], c["yields"]["2yr"], c["yields"]["10yr"])
2023-07-07 4.94 4.06
2023-07-06 4.99 4.05
2023-07-05 4.94 3.95
2023-07-03 4.94 3.86
In July 2023 the 2 year yielded almost a full point more than the 10 year: an inverted curve.
Find a series
r = requests.get(BASE + "/economic/series", headers=H, params={"source": "treasury", "size": 200}).json()
for s in r["series"][:8]:
print(s["id"], "|", s["name"], "|", s["frequency"], s["firstDate"])
treasury.avgrate.bills | Average interest rate, Treasury Bills | monthly 2001-01-31
treasury.avgrate.bonds | Average interest rate, Treasury Bonds | monthly 2001-01-31
treasury.avgrate.notes | Average interest rate, Treasury Notes | monthly 2001-01-31
treasury.debt.total | Total public debt outstanding | daily 1993-04-01
treasury.par.10yr | Treasury par yield, 10 Yr | daily 1990-01-02
treasury.par.15month | Treasury par yield, 1.5 Month | daily 2025-02-18
treasury.par.1mo | Treasury par yield, 1 Mo | daily 2001-07-31
treasury.par.1yr | Treasury par yield, 1 Yr | daily 1990-01-02
source=bls lists the 44 BLS series (CPI and its components, PPI, unemployment, payrolls, hours, earnings and job openings). q searches the names, for example q=cpi core.
CPI year over year, matched by date
Match months by date rather than by position. BLS did not publish October 2025 CPI, so counting back 12 rows would compare against the wrong month:
r = requests.get(BASE + "/economic/observations", headers=H,
params={"series": "bls.cusr0000sa0", "startDate": "2024-09-01"}).json()
by_date = {o["date"]: o["value"] for o in r["observations"]}
for month in ("2026-10-01", "2026-09-01"):
prev = str(int(month[:4]) - 1) + month[4:]
if prev in by_date:
print(month, "CPI year over year:", round(by_date[month] / by_date[prev] - 1, 4))
else:
print(month, "no value for", prev)
2026-10-01 no value for 2025-10-01
2026-09-01 CPI year over year: 0.0372
What to keep in mind
- Values are as the agencies publish them. Revisions replace older values when the source file changes; there is no vintage history.
sizegoes up to 5000 observations and 1000 curves per call. Useorder=descfor the newest first.- Sources: U.S. Department of the Treasury and Bureau of Labor Statistics, public domain.