Skip to content

About

US economic data API examples in Python and curl: GDP, CPI and inflation by category, jobs, Treasury yields and the yield curve, Fed rate decisions, mortgage rates and trade.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

US economic data API: GDP, inflation, jobs, interest rates, the yield curve, Fed decisions and trade

Get official US economic data with one request each: GDP, consumer prices and inflation by category, jobs and unemployment, weekly jobless claims, Treasury yields and the yield curve, Federal Reserve rate decisions, mortgage and corporate bond rates, trade by country and product, and gas prices. Every example is one request to the DataPorium REST API, shown in Python and curl.

Quick start

pip install git+https://github.com/DataPorium/dataporium-python.git
export DATAPORIUM_API_KEY="YOUR_API_KEY"
from dataporium import DataPorium, to_frame

dp = DataPorium()   # reads DATAPORIUM_API_KEY
answer = dp.economic_metrics(economic_metrics="GDP")
print(to_frame(answer).head())

Or run any example below from this repository:

git clone https://github.com/DataPorium/us-economic-data-api.git
cd us-economic-data-api
pip install -r requirements.txt
python examples.py           # list the examples
python examples.py gdp     # run one
python examples.py gdp --csv out.csv

What you can get

Question Example Endpoint
US GDP gdp GET /economic-metrics
Unemployment rate unemployment-rate GET /economic-metrics
Nonfarm payrolls payrolls GET /economic-metrics
Consumer price index (CPI) cpi GET /economic-metrics
Recession probability recession-probability GET /economic-metrics
Which prices are rising fastest: 25 categories, newest month inflation-by-category GET /inflation-categories
Shelter and rent inflation since 2020 rent-inflation-history GET /inflation-categories
The next Federal Reserve meetings and the current target range fed-next-meeting GET /fed-decisions
Every Fed rate cut since 2019 fed-cuts GET /fed-decisions
The Treasury yield curve today, a month ago and a year ago yield-curve GET /treasury-yields/curve
2-year and 10-year Treasury yields, monthly since 2000 treasury-yields GET /treasury-yields
30-year fixed mortgage rate mortgage-rate GET /economic-metrics
High-grade corporate bond yields and their spread over Treasuries corporate-bonds GET /corporate-bond-yields
Weekly unemployment claims, US jobless-claims GET /layoffs/official/claims
States ranked by unemployment, newest month state-unemployment GET /local-jobs
Official layoffs and discharges (JOLTS) layoffs-rate GET /layoffs/official/jolts
Largest US trade deficits by country, last 12 months trade-deficits GET /us-trade/summary
Monthly trade with China since 2024 trade-china GET /us-trade
Release dates of consumer price index (CPI) reports economic-calendar GET /market-calendar
Gas prices in the states of the weekly survey, newest week gas-prices GET /gas-prices

Headline indicators

US GDP

dp.economic_metrics(economic_metrics="GDP")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/economic-metrics?economic_metrics=GDP"

Newest first, as {date, value}. The same request gives every series below by name.

Unemployment rate

dp.economic_metrics(economic_metrics="unemployment_Rate")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/economic-metrics?economic_metrics=unemployment_Rate"

Nonfarm payrolls

dp.economic_metrics(economic_metrics="total_Non_farm_Payroll")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/economic-metrics?economic_metrics=total_Non_farm_Payroll"

Consumer price index (CPI)

dp.economic_metrics(economic_metrics="CPI")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/economic-metrics?economic_metrics=CPI"

Recession probability

dp.economic_metrics(economic_metrics="smoothed_US_Recession_Probabilities")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/economic-metrics?economic_metrics=smoothed_US_Recession_Probabilities"

Inflation

Which prices are rising fastest: 25 categories, newest month

dp.inflation_categories(latest=True, sort="yoy_pct", order="desc")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/inflation-categories?latest=true&sort=yoy_pct&order=desc"

Gasoline, electricity, rent, shelter, groceries, restaurants, used cars, car insurance, airline fares, medical care and more, with 12-month and 1-month changes.

Shelter and rent inflation since 2020

dp.inflation_categories(category="shelter,rent", month_from="2020-01", sort="month", order="asc", limit=500)
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/inflation-categories?category=shelter,rent&month_from=2020-01&sort=month&order=asc&limit=500"

Interest rates

The next Federal Reserve meetings and the current target range

dp.fed_decisions(status="upcoming", order="asc")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/fed-decisions?status=upcoming&order=asc"

The answer also has current_target, next_meeting and last_decision.

Every Fed rate cut since 2019

dp.fed_decisions(decision="cut", date_from="2019-01-01", order="asc")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/fed-decisions?decision=cut&date_from=2019-01-01&order=asc"

The Treasury yield curve today, a month ago and a year ago

dp.treasury_yields_curve(compare="1m,1y")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/treasury-yields/curve?compare=1m,1y"

With the 10-year minus 2-year and 10-year minus 3-month spreads and whether the curve is inverted.

2-year and 10-year Treasury yields, monthly since 2000

dp.treasury_yields(maturity="2y,10y", date_from="2000-01-01", frequency="monthly", order="asc", limit=1000)
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/treasury-yields?maturity=2y,10y&date_from=2000-01-01&frequency=monthly&order=asc&limit=1000"

12 maturities from 1 month to 30 years, daily from 1990.

30-year fixed mortgage rate

dp.economic_metrics(economic_metrics="30Year_Fixed_Rate_Mortgage_Average")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/economic-metrics?economic_metrics=30Year_Fixed_Rate_Mortgage_Average"

High-grade corporate bond yields and their spread over Treasuries

dp.corporate_bond_yields(month_from="2020-01", order="asc")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/corporate-bond-yields?month_from=2020-01&order=asc"

Jobs

Weekly unemployment claims, US

dp.layoffs_official_claims(state="US", date_from="2026-01-01")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/layoffs/official/claims?state=US&date_from=2026-01-01"

Every state too: state=CA,TX.

States ranked by unemployment, newest month

dp.local_jobs(area_type="state", latest=True, sort="unemployment_rate", order="desc", limit=60)
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/local-jobs?area_type=state&latest=true&sort=unemployment_rate&order=desc&limit=60"

Also metro areas, counties and cities of 25,000 people or more.

Official layoffs and discharges (JOLTS)

dp.layoffs_official_jolts(area="US", latest=True)
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/layoffs/official/jolts?area=US&latest=true"

Trade and prices

Largest US trade deficits by country, last 12 months

dp.us_trade_summary(dimension="country", period="last_12_months", sort="balance", order="asc", limit=10)
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/us-trade/summary?dimension=country&period=last_12_months&sort=balance&order=asc&limit=10"

Monthly trade with China since 2024

dp.us_trade(dimension="country", code="5700", month_from="2024-01", order="asc")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/us-trade?dimension=country&code=5700&month_from=2024-01&order=asc"

Country codes: 5700 China, 1220 Canada, 2010 Mexico. dimension=product gives product groups.

Release dates of consumer price index (CPI) reports

dp.market_calendar(event_name="CPI YY")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/market-calendar?event_name=CPI%20YY"

Event names are written as in the calendar, for example CPI YY (CPI, change from a year earlier). Each row has the date, time, previous value and country.

Gas prices in the states of the weekly survey, newest week

dp.gas_prices(area_type="state", product="regular", latest=True, sort="price_usd", order="desc")
curl -H "apikey: $DATAPORIUM_API_KEY" "https://api.dataporium.io/gas-prices?area_type=state&product=regular&latest=true&sort=price_usd&order=desc"

Answers

Every answer is JSON. Many are a list of rows; paged answers hold their rows under rows with total, limit and offset. to_frame(answer) in the Python library finds the rows and returns a pandas DataFrame. Each endpoint and all of its parameters are described in the API documentation, and print(dp.describe("<method>")) shows them in Python.

Use it in Claude, ChatGPT or Cursor

The same data is in the DataPorium MCP server, so Claude, ChatGPT or Cursor can answer questions like "How have mortgage rates and the 10-year yield moved this year?" from the official numbers.

Ready-made scripts

Get an API key

Sign up at dataporium.tech and subscribe to the Premium plan; the key is in your account settings. It works for the REST API (600 requests per minute) and the MCP server. Send it in the apikey header, as above; a ?apikey= query parameter also works, but a key in a URL can end up in logs. Keep the key out of code you commit or share.

More

License

The code in this repository is released under the MIT License. Use of the API and its data is governed by the DataPorium Terms of Use. Data is for information only and is not investment advice.

About

US economic data API examples in Python and curl: GDP, CPI and inflation by category, jobs, Treasury yields and the yield curve, Fed rate decisions, mortgage rates and trade.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages