How to download economic data (rates, inflation, GDP) from FRED with Python
Interest rates, inflation and GDP often matter as much as prices when you study a market. The St. Louis Fed publishes them through the FRED API. This guide shows how to request one series and turn it into a table you can save or chart.
What you need
- Python with the
requestsandpandaspackages. - A free FRED account and an API key. The FRED API page says every request needs a key, a 32-character string of lowercase letters and numbers.
Step by step
- Request your key. Log in to your FRED account, open the API keys page and request a key. Use one key per application, as the documentation asks.
- Pick a series. Each series has an ID shown on its page on the FRED website (the official example in the docs is
GNPCA). - Build the request. The endpoint is
https://api.stlouisfed.org/fred/series/observationswith the parametersseries_id,api_keyandfile_type=json. The default format is XML, so ask for JSON explicitly. - Limit the dates. Add
observation_startandobservation_endin YYYY-MM-DD format. Without them you get the whole history. - Load it into pandas. The JSON has an
observationslist; each item has adateand avalue. The example shows values as text, so convert them to numbers (for example withpandas.to_numeric) and check how gaps appear in your series before calculating. - Transform if you want. The
unitsparameter can return percent change (pch), change from a year ago (ch1), percent change from a year ago (pc1) and more. Thefrequencyparameter aggregates to a lower frequency such as monthly or quarterly (not to a higher one). - Save it. Write the table to a CSV with
to_csvso you do not call the API every time.
Ideas for what to do next
- Put a rates or inflation series next to price history from yfinance to see how a market behaved around releases.
- Prefer less code? pandas-datareader and OpenBB are other ways to reach economic data; check each page for what it supports.
- Use ALFRED vintages (described in the FRED API page) to test with data as it was known on a past date.
Other ways to do it
For price history, see our guide to downloading prices to a CSV with yfinance. Browse the use cases for more ideas.
Good to know
FRED is economic data, not a trading feed: there are no real-time prices or order execution. The pages we read do not state rate limits or full terms, so check the official terms before building on it. Any example is illustrative and not a promise of results.
See more ideas
Try the live demo. Custom bots are coming soon: tell me when it opens.
Before you start
What does FRED API cost and what licence does it use?
The API documentation does not state a price; check the official website for current terms. An API key is required. Licence: Public service (see the official terms of use). Prices change, so check the official website before you decide.
What should I know before using FRED API?
Every request needs an API key, and each application should use its own. Rate limits and terms of use are not stated in the pages we read; check the official terms before building on it. It is economic data, not a trading feed: no real-time prices or order execution.
What does pandas-datareader cost and what licence does it use?
Free to install with pip. Some underlying data sources may have their own terms or API keys, so check each source's official website. Licence: Not detected by GitHub; check the repository's licence file. Prices change, so check the official website before you decide.
What should I know before using pandas-datareader?
Depends on third-party websites and APIs, so a source can change or stop working without notice. GitHub does not detect a standard licence, so check the repository before using it commercially. The README says Python 3.12 and later may need setuptools installed for distutils. Last repository change was in July 2026, so updates are less frequent than on very active projects.
What does yfinance cost and what licence does it use?
Free (open source). Licence: Apache-2.0. Prices change, so check the official website before you decide.
What should I know before using yfinance?
Not affiliated with or endorsed by Yahoo. Its own documentation says the tool is intended for research and educational purposes and that the Yahoo Finance API is for personal use only: read their terms. Since it is not an official API, it can stop working whenever Yahoo changes something.
Tools in this guide
- FRED API: REST API from the St. Louis Fed to retrieve economic data series (FRED) and their historical vintages (ALFRED) as JSON or XML.
- pandas-datareader: Python library that pulls macroeconomic and factor-style data from public sources such as FRED, Fama/French, the World Bank, OECD and Eurostat straight into a pandas DataFrame.
- yfinance: Python library to download prices and history from Yahoo Finance; widely used for research and learning.
- OpenBB: Open-source data platform that connects many data sources and exposes them to Python, a command line, a local REST API and AI agents.
Compare your options
Want a bot like this when custom bots open? Get notified · more bot ideas
Coming soon: custom bots
We are preparing a service to code, backtest and automate trading and statistics bots to your own rules. It is not available yet: follow our Telegram channel to know when it opens.