Skip to main content

fredapi is a Python API for the FRED data provided by the Federal Reserve Bank of St. Louis. fredapi provides a wrapper in python to the FRED web service, and also provides several conveninent methods for parsing and analyzing point-in-time data (i.e. historic data revisions) from ALFRED

fredapi makes use of pandas and returns data to you in a pandas Series or DataFrame

Installation

pip install fredapi

Basic Usage

First you need an API key, you can apply for one for free on the FRED website. Once you have your API key, you can set it in one of three ways:

  • set it to the evironment variable FRED_API_KEY

  • save it to a file and use the ‘api_key_file’ parameter

  • pass it directly as the ‘api_key’ parameter

from fredapi import Fred
fred = Fred(api_key='insert api key here')
data = fred.get_series('SP500')

Working with data revisions

Many economic data series contain frequent revisions. fredapi provides several convenient methods for handling data revisions and answering the quesion of what-data-was-known-when.

In ALFRED there is the concept of a vintage date. Basically every observation can have three dates associated with it: date, realtime_start and realtime_end.

  • date: the date the value is for

  • realtime_start: the first date the value is valid

  • realitime_end: the last date the value is valid

For instance, there has been three observations (data points) for the GDP of 2014 Q1:

<observation realtime_start="2014-04-30" realtime_end="2014-05-28" date="2014-01-01" value="17149.6"/>
<observation realtime_start="2014-05-29" realtime_end="2014-06-24" date="2014-01-01" value="17101.3"/>
<observation realtime_start="2014-06-25" realtime_end="2014-07-29" date="2014-01-01" value="17016.0"/>

This means the GDP value for Q1 2014 has been released three times. First release was on 4/30/2014 for a value of 17149.6, and then there have been two revisions on 5/29/2014 and 6/25/2014 for revised values of 17101.3 and 17016.0, respectively.

Get first data release only (i.e. ignore revisions)

data = fred.get_series_first_release('GDP')

Get latest data

Note that this is the same as simply calling get_series()

data = fred.get_series_latest_release('GDP')

Get latest data known on a given date

fred.get_series_as_of_date('GDP', '6/1/2014')

Get all data release dates

This returns a DataFrame with all the data from ALFRED

df = fred.get_series_all_releases('GDP')
df.tail()

Get all vintage dates

vintage_dates = fred.get_series_vintage_dates('GDP')

Search for data series

You can always search for data series on the FRED website. But sometimes it can be more convenient to search programmatically. fredapi provides a search() method that does a fulltext search and returns a DataFrame of results.

fred.search('potential gdp')

You can also search by release id and category id with various options

df1 = fred.search_by_release(11)
df2 = fred.search_by_category(101, limit=10, order_by='popularity', sort_order='desc')

Dependencies

More Examples

Release files for fredapi 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fredapi 0.5.2
File Size Uploaded
fredapi-0.5.2.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fredapi 0.5.2
File Interpreter ABI Platform
fredapi-0.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 26.6 kB

Release files / fredapi-0.5.2.tar.gz

Download URL fredapi-0.5.2.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
405ca048abed4207d93dbc9b7ee8c46d6b473483650323e2f1c094af83d4b247
BLAKE2b-256 checksum
How to use checksums
6f3ce9281ecda4c6ee5c7d50a4bcf00dc5df1a7ff325e604c9b9510c5bdd8514
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.65.0 CPython/3.10.11

Release files / fredapi-0.5.2-py3-none-any.whl

Download URL fredapi-0.5.2-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
961817ec8d70e58886ff7302d3dda908614ad99f77831a59833c4fc3f6150155
BLAKE2b-256 checksum
How to use checksums
73641db43417cf7ed430f104a347126b5260a1724ee9a1b7d0b1622262c9c4df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.65.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

1 release file

0.4.0

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page