
US Treasury API: Track the National Debt in Real-Time with Python (No API Key)
The US national debt just crossed $36 trillion. I wanted to see exactly when it happened, so I built a tracker using the Treasury's free API. Turns out, the US government has a surprisingly good API. The API FiscalData.Treasury.gov — free, no API key, no signup. Track National Debt import requests def get_national_debt ( days = 10 ): url = " https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/debt_to_penny " params = { " sort " : " -record_date " , " page[size] " : days , " fields " : " record_date,tot_pub_debt_out_amt " } data = requests . get ( url , params = params ). json () for record in data [ " data " ]: debt = float ( record [ " tot_pub_debt_out_amt " ]) print ( f " { record [ " record_date " ] } : $ { debt / 1e12 : . 4 f } trillion " ) get_national_debt () # 2025-03-20: $36.2184 trillion # 2025-03-19: $36.2157 trillion Treasury Auction Results Want to know what interest rate the government is paying on new debt? def get_auctions ( security_type = "
Continue reading on Dev.to Tutorial
Opens in a new tab



