### Install fredapi using pip Source: https://github.com/mortada/fredapi/blob/master/DESCRIPTION.rst This command installs the fredapi library using pip. Ensure you have pip installed and accessible in your environment. ```sh pip install fredapi ``` -------------------------------- ### GET /series/first_release Source: https://context7.com/mortada/fredapi/llms.txt Retrieves the initial release data values for a series, excluding subsequent revisions. ```APIDOC ## GET /series/first_release ### Description Retrieves only the first-release data values for a series, ignoring all subsequent revisions. This is useful for backtesting and understanding what data was initially reported. ### Method GET ### Parameters #### Query Parameters - **series_id** (string) - Required - The FRED series ID (e.g., 'GDP') ### Response #### Success Response (200) - **data** (Series) - A pandas Series containing the first-release values indexed by date. ``` -------------------------------- ### GET /series/all_releases Source: https://context7.com/mortada/fredapi/llms.txt Retrieves the complete revision history for a specific economic series. ```APIDOC ## GET /series/all_releases ### Description Retrieves the complete revision history for a series, including all first releases and subsequent revisions. ### Method GET ### Parameters #### Query Parameters - **series_id** (string) - Required - The FRED series ID - **realtime_start** (string) - Optional - Start date for the revision history - **realtime_end** (string) - Optional - End date for the revision history ### Response #### Success Response (200) - **data** (DataFrame) - A DataFrame with columns: realtime_start, date, and value. ``` -------------------------------- ### GET /search Source: https://context7.com/mortada/fredapi/llms.txt Performs a fulltext search across all FRED series. ```APIDOC ## GET /search ### Description Performs a fulltext search across all FRED series. Returns a DataFrame with information about matching series. ### Method GET ### Parameters #### Query Parameters - **search_text** (string) - Required - The search query - **limit** (int) - Optional - Number of results to return - **order_by** (string) - Optional - Field to sort by (e.g., 'popularity') - **sort_order** (string) - Optional - 'asc' or 'desc' ### Response #### Success Response (200) - **data** (DataFrame) - A DataFrame containing series metadata like title, frequency, and popularity. ``` -------------------------------- ### Get first release of a series Source: https://github.com/mortada/fredapi/blob/master/DESCRIPTION.rst Retrieves only the first release of a specified economic data series, ignoring any subsequent revisions. This is useful for historical analysis of initial data points. ```python data = fred.get_series_first_release('GDP') ``` -------------------------------- ### Get Series Data As of Date (Python) Source: https://context7.com/mortada/fredapi/llms.txt Returns the data for a series as it was known on a specific historical date, including revisions up to that point but ignoring later ones. Essential for point-in-time analysis. Requires 'fredapi' and an API key. ```python from fredapi import Fred import pandas as pd fred = Fred(api_key='your_api_key') # Get GDP data as it was known on June 1, 2014 gdp_as_of = fred.get_series_as_of_date('GDP', '6/1/2014') print(gdp_as_of.tail()) # Output DataFrame with columns: date, realtime_start, value # date realtime_start value # 2237 2013-10-01 2014-01-30 17102.5 # 2238 2013-10-01 2014-02-28 17080.7 # 2239 2013-10-01 2014-03-27 17089.6 # 2241 2014-01-01 2014-04-30 17149.6 # 2242 2014-01-01 2014-05-29 17101.3 # Get latest value known for each date as of a specific point in time gdp_known = fred.get_series_as_of_date('GDP', '2020-03-15') latest_known = gdp_known.groupby('date')['value'].last() print(latest_known.tail()) ``` -------------------------------- ### Get Series First Release (Ignore Revisions) - Python Source: https://github.com/mortada/fredapi/blob/master/README.md Retrieves a specific economic data series from FRED, ignoring any revisions. This function returns the initial data as it was first released. The output is a pandas Series. ```python data = fred.get_series_first_release('GDP') data.tail() ``` -------------------------------- ### Get Series First Release Data (Python) Source: https://context7.com/mortada/fredapi/llms.txt Retrieves only the first-release data values for a series, ignoring all subsequent revisions. This is useful for backtesting and understanding initial data reports. It requires the 'fredapi' library and an API key. ```python from fredapi import Fred import pandas as pd fred = Fred(api_key='your_api_key') # Get first-release GDP data (ignores all revisions) gdp_first = fred.get_series_first_release('GDP') print(gdp_first.tail()) # Output shows original values before any revisions: # date # 2023-01-01 26149.6 # 2023-04-01 26467.8 # 2023-07-01 27063.0 # 2023-10-01 27543.5 # Name: value, dtype: object # Compare first release vs latest release gdp_latest = fred.get_series_latest_release('GDP') comparison = pd.DataFrame({ 'first_release': gdp_first, 'latest': gdp_latest }).tail() print(comparison) ``` -------------------------------- ### Get Series Vintage Dates (Python) Source: https://context7.com/mortada/fredapi/llms.txt Returns a list of all vintage dates for a series, which are the dates when data values were revised or new observations were released. Useful for point-in-time analysis. Requires 'fredapi' and an API key. ```python from fredapi import Fred import pandas as pd fred = Fred(api_key='your_api_key') # Get all vintage dates for GDP series vintage_dates = fred.get_series_vintage_dates('GDP') print(f"Total vintage dates: {len(vintage_dates)}") print("Most recent vintage dates:") for dt in vintage_dates[-5:]: print(dt.strftime('%Y-%m-%d')) # Output: # Total vintage dates: 245 # Most recent vintage dates: # 2024-03-28 # 2024-04-25 # 2024-05-30 # 2024-06-27 # 2024-07-25 # Create a point-in-time dataset using vintage dates pit_data = {} for vd in vintage_dates[-12:]: # Last 12 vintages data = fred.get_series_as_of_date('GDP', vd.strftime('%Y-%m-%d')) pit_data[vd] = data.groupby('date')['value'].last() pit_df = pd.DataFrame(pit_data) ``` -------------------------------- ### GET /series/as_of_date Source: https://context7.com/mortada/fredapi/llms.txt Returns data as it was known on a specific historical date, useful for point-in-time analysis. ```APIDOC ## GET /series/as_of_date ### Description Returns the data as it was known on a specific historical date, including all revisions up to that date but ignoring any revisions made after. ### Method GET ### Parameters #### Query Parameters - **series_id** (string) - Required - The FRED series ID - **vintage_date** (string) - Required - The date (YYYY-MM-DD) to retrieve data as of ### Response #### Success Response (200) - **data** (DataFrame) - A DataFrame containing columns: date, realtime_start, and value. ``` -------------------------------- ### Get all vintage dates for a series Source: https://github.com/mortada/fredapi/blob/master/DESCRIPTION.rst Retrieves a list of all vintage dates associated with a specific economic data series. Vintage dates indicate when a particular data point was recorded or revised. ```python vintage_dates = fred.get_series_vintage_dates('GDP') ``` -------------------------------- ### Get latest release of a series Source: https://github.com/mortada/fredapi/blob/master/DESCRIPTION.rst Fetches the latest available release of a specified economic data series. This is equivalent to calling the standard get_series() method. ```python data = fred.get_series_latest_release('GDP') ``` -------------------------------- ### GET /series/vintage_dates Source: https://context7.com/mortada/fredapi/llms.txt Returns a list of all vintage dates when data values were revised or released. ```APIDOC ## GET /series/vintage_dates ### Description Returns a list of all vintage dates for a series, which are the dates when data values were revised or new observations were released. ### Method GET ### Parameters #### Query Parameters - **series_id** (string) - Required - The FRED series ID ### Response #### Success Response (200) - **dates** (list) - A list of datetime objects representing vintage dates. ``` -------------------------------- ### Get Series All Releases History (Python) Source: https://context7.com/mortada/fredapi/llms.txt Retrieves the complete revision history for a series, including all first releases and subsequent revisions. Returns a DataFrame with observation date, reporting date, and value. Requires 'fredapi' and an API key. ```python from fredapi import Fred fred = Fred(api_key='your_api_key') # Get all releases and revisions for GDP gdp_all = fred.get_series_all_releases('GDP') print(gdp_all.tail(10)) # Output: # realtime_start date value # 2236 2014-07-30 2013-07-01 16872.3 # 2237 2014-01-30 2013-10-01 17102.5 # 2238 2014-02-28 2013-10-01 17080.7 # 2239 2014-03-27 2013-10-01 17089.6 # 2240 2014-07-30 2013-10-01 17078.3 # 2241 2014-04-30 2014-01-01 17149.6 # 2242 2014-05-29 2014-01-01 17101.3 # 2243 2014-06-25 2014-01-01 17016.0 # 2244 2014-07-30 2014-01-01 17044.0 # 2245 2014-07-30 2014-04-01 17294.7 # Analyze revision patterns for a specific quarter q1_2014 = gdp_all[gdp_all['date'] == '2014-01-01'] print("Revisions for Q1 2014 GDP:") print(q1_2014) # With custom realtime date range gdp_recent = fred.get_series_all_releases('GDP', realtime_start='2023-01-01', realtime_end='2023-12-31') ``` -------------------------------- ### Get series data as of a specific date Source: https://github.com/mortada/fredapi/blob/master/DESCRIPTION.rst Retrieves the data for a specified series as it was known on a particular date. This method is crucial for understanding historical data states and revisions. ```python fred.get_series_as_of_date('GDP', '6/1/2014') ``` -------------------------------- ### Get Series Metadata with fredapi Source: https://context7.com/mortada/fredapi/llms.txt Retrieves metadata for a FRED series using get_series_info. Returns a pandas Series containing details like title, frequency, observation dates, units, and notes. Requires 'fredapi' and 'pandas'. ```Python from fredapi import Fred fred = Fred(api_key='your_api_key') # Get information about the PAYEMS (payroll employment) series info = fred.get_series_info('PAYEMS') print(info) # Access specific fields print(f"Title: {info['title']}") print(f"Frequency: {info['frequency']}") print(f"Last Updated: {info['last_updated']}") ``` -------------------------------- ### Get Series Latest Release - Python Source: https://github.com/mortada/fredapi/blob/master/README.md Retrieves the latest available data for a specific economic series from FRED. This is equivalent to calling the standard get_series() method. The output is a pandas Series. ```python data = fred.get_series_latest_release('GDP') data.tail() ``` -------------------------------- ### Get all release dates for a series Source: https://github.com/mortada/fredapi/blob/master/DESCRIPTION.rst Returns a pandas DataFrame containing all historical data releases for a specified economic series from ALFRED. This provides a comprehensive view of data revisions over time. ```python df = fred.get_series_all_releases('GDP') df.tail() ``` -------------------------------- ### Initialize Fred API client Source: https://github.com/mortada/fredapi/blob/master/DESCRIPTION.rst Demonstrates how to initialize the Fred API client with your API key. The API key can be provided directly, via an environment variable, or from a file. ```python from fredapi import Fred fred = Fred(api_key='insert api key here') data = fred.get_series('SP500') ``` -------------------------------- ### Initialize Fred Class in Python Source: https://context7.com/mortada/fredapi/llms.txt Demonstrates various ways to initialize the Fred class, including passing the API key directly, loading from a file, using an environment variable, and configuring proxy support. Requires the 'fredapi' library. ```Python from fredapi import Fred # Method 1: Pass API key directly fred = Fred(api_key='your_api_key_here') # Method 2: Load API key from a file fred = Fred(api_key_file='/path/to/api_key.txt') # Method 3: Use environment variable FRED_API_KEY import os os.environ['FRED_API_KEY'] = 'your_api_key_here' fred = Fred() # Method 4: With proxy support fred = Fred( api_key='your_api_key_here', proxies={'http': 'http://proxy.example.com:8080', 'https': 'https://proxy.example.com:8080'} ) ``` -------------------------------- ### Search for Economic Data Series by Keyword Source: https://context7.com/mortada/fredapi/llms.txt Demonstrates how to search for all series related to a specific keyword using the search method. Setting the limit to 0 retrieves all available results. ```python from fredapi import Fred fred = Fred(api_key='your_api_key') unemployment = fred.search('unemployment rate', limit=0) print(f"Found {len(unemployment)} unemployment-related series") ``` -------------------------------- ### Retrieve Time Series Data with fredapi Source: https://context7.com/mortada/fredapi/llms.txt Shows how to fetch time series data for a given FRED series ID using the get_series method. Supports filtering by date range and passing additional FRED API parameters. Returns a pandas Series. Requires 'fredapi' and 'pandas'. ```Python from fredapi import Fred fred = Fred(api_key='your_api_key') # Get S&P 500 data sp500 = fred.get_series('SP500') print(sp500.tail()) # Get GDP data with date range gdp = fred.get_series('GDP', observation_start='2020-01-01', observation_end='2023-12-31') print(gdp) # Using additional FRED API parameters (e.g., units transformation) cpi = fred.get_series('CPIAUCSL', units='pc1') # percent change from year ago print(cpi.tail()) ``` -------------------------------- ### Search by Release Source: https://context7.com/mortada/fredapi/llms.txt Searches for all series belonging to a specific FRED release ID. Useful for finding related data series published together. ```APIDOC ## POST /fred/release/series ### Description Searches for all series belonging to a specific FRED release ID. ### Method POST ### Endpoint /fred/release/series ### Parameters #### Path Parameters - **release_id** (integer) - Required - The ID of the FRED release. #### Query Parameters - **limit** (integer) - Optional - The number of observations to return. - **order_by** (string) - Optional - The field to order the results by (e.g., 'popularity', 'series_id'). - **sort_order** (string) - Optional - The order to sort the results ('asc' or 'desc'). ### Request Example ```python from fredapi import Fred fred = Fred(api_key='your_api_key') # Search for series in the Employment Situation release (release_id=50) employment_series = fred.search_by_release(50, limit=10, order_by='popularity', sort_order='desc') print(employment_series[['title', 'frequency', 'popularity']].head()) # Get all series from Personal Income release (release_id=175) pi_series = fred.search_by_release( 175, limit=100, order_by='series_id', sort_order='asc' ) print(f"Found {len(pi_series)} series in release 175") print(pi_series[['title', 'observation_start']].head()) ``` ### Response #### Success Response (200) - **Series Data** (DataFrame) - A pandas DataFrame containing the series found. #### Response Example ``` title frequency popularity series id UNRATE Unemployment Rate Monthly 95 PAYEMS All Employees: Total Nonfarm Payrolls Monthly 86 ... Found 100 series in release 175 title observation_start series id 175A050A024AA 1959-01-01 175A050A024SA 1959-01-01 ... ``` ``` -------------------------------- ### Fetch Latest Release Data with fredapi Source: https://context7.com/mortada/fredapi/llms.txt Uses get_series_latest_release to fetch the most recent data values for a given FRED series. Functionally equivalent to get_series() but specifically targets the latest release. Returns a pandas Series. Requires 'fredapi' and 'pandas'. ```Python from fredapi import Fred fred = Fred(api_key='your_api_key') # Get latest GDP values gdp_latest = fred.get_series_latest_release('GDP') print(gdp_latest.tail()) ``` -------------------------------- ### Search by Category Source: https://context7.com/mortada/fredapi/llms.txt Searches for all series within a specific FRED category. Categories organize series by topic. ```APIDOC ## POST /fred/category/series ### Description Searches for all series within a specific FRED category. ### Method POST ### Endpoint /fred/category/series ### Parameters #### Path Parameters - **category_id** (integer) - Required - The ID of the FRED category. #### Query Parameters - **limit** (integer) - Optional - The number of observations to return. - **order_by** (string) - Optional - The field to order the results by (e.g., 'popularity', 'series_id'). - **sort_order** (string) - Optional - The order to sort the results ('asc' or 'desc'). - **filter** (tuple) - Optional - A tuple to filter results (e.g., ('seasonal_adjustment', 'Seasonally Adjusted')). ### Request Example ```python from fredapi import Fred fred = Fred(api_key='your_api_key') # Search for series in category 32991 (H.15 Selected Interest Rates) interest_rates = fred.search_by_category( 32991, limit=20, order_by='popularity', sort_order='desc' ) print(interest_rates[['title', 'frequency', 'popularity']].head()) # Get series from Money Supply category (category_id=32242) money_supply = fred.search_by_category( 32242, filter=('seasonal_adjustment', 'Seasonally Adjusted') ) print(money_supply[['title', 'units']].head(10)) ``` ### Response #### Success Response (200) - **Series Data** (DataFrame) - A pandas DataFrame containing the series found. #### Response Example ``` title frequency popularity series id DFF Federal Funds Effective Rate Daily 88 FEDFUNDS Federal Funds Effective Rate Monthly 85 ... title units series id BOGMBASE Billions of Persons, Seasonally Adjusted M1 Billions of Dollars, Seasonally Adjusted ... ``` ``` -------------------------------- ### Search for series by release or category ID Source: https://github.com/mortada/fredapi/blob/master/DESCRIPTION.rst Allows programmatic searching of FRED data series using release IDs or category IDs. Supports options for limiting results, ordering, and sorting. ```python df1 = fred.search_by_release(11) df2 = fred.search_by_category(101, limit=10, order_by='popularity', sort_order='desc') ``` -------------------------------- ### Retrieve vintage dates for a series Source: https://github.com/mortada/fredapi/blob/master/README.md Retrieves a list of all vintage dates available for a specific series. The output is a list of datetime objects, which can be formatted as strings for display. ```python from __future__ import print_function vintage_dates = fred.get_series_vintage_dates('GDP') for dt in vintage_dates[-5:]: print(dt.strftime('%Y-%m-%d')) ``` -------------------------------- ### Search for economic data series by keyword Source: https://github.com/mortada/fredapi/blob/master/DESCRIPTION.rst Performs a full-text search for economic data series based on a keyword query. Returns a pandas DataFrame with matching series information. ```python fred.search('potential gdp') ``` -------------------------------- ### Search for Series by Release ID Source: https://context7.com/mortada/fredapi/llms.txt Retrieves economic series associated with a specific FRED release ID. This is useful for grouping data published in the same report, such as employment or personal income data. ```python from fredapi import Fred fred = Fred(api_key='your_api_key') # Search for series in the Employment Situation release employment_series = fred.search_by_release(50, limit=10, order_by='popularity', sort_order='desc') print(employment_series[['title', 'frequency', 'popularity']].head()) # Get all series from Personal Income release pi_series = fred.search_by_release(175, limit=100, order_by='series_id', sort_order='asc') print(f"Found {len(pi_series)} series in release 175") ``` -------------------------------- ### Search for Series Source: https://context7.com/mortada/fredapi/llms.txt Searches for series based on a keyword. The `limit=0` parameter retrieves all matching series without any restriction. ```APIDOC ## POST /fred/series/search ### Description Searches for all unemployment-related series (no limit). ### Method POST ### Endpoint /fred/series/search ### Parameters #### Query Parameters - **search_text** (string) - Required - The text to search for. - **limit** (integer) - Optional - The number of observations to return. ### Request Example ```python from fredapi import Fred fred = Fred(api_key='your_api_key') unemployment = fred.search('unemployment rate', limit=0) print(f"Found {len(unemployment)} unemployment-related series") ``` ### Response #### Success Response (200) - **Series Data** (DataFrame) - A pandas DataFrame containing the series found. #### Response Example ``` Found 150 unemployment-related series ``` ``` -------------------------------- ### Search FRED Series (Python) Source: https://context7.com/mortada/fredapi/llms.txt Performs a full-text search across all FRED series, returning a DataFrame with information like title, frequency, units, and popularity. Supports sorting, filtering, and limiting results. Requires 'fredapi' and an API key. ```python from fredapi import Fred fred = Fred(api_key='your_api_key') # Basic search for GDP-related series results = fred.search('potential gdp') print(results[['title', 'frequency', 'popularity']].head()) # Output: # title frequency popularity # series id # GDPPOT Real Potential Gross Domestic Product Quarterly 72 # NGDPPOT Nominal Potential Gross Domestic ... Quarterly 61 # Search with options inflation_series = fred.search( 'consumer price index', limit=10, order_by='popularity', sort_order='desc', filter=('frequency', 'Monthly') ) print(inflation_series[['title', 'popularity', 'seasonal_adjustment']].head()) ``` -------------------------------- ### Search for economic data series Source: https://github.com/mortada/fredapi/blob/master/README.md Performs a full-text search across the FRED database to find relevant series IDs. The results are returned as a pandas DataFrame, which can be transposed for easier readability. ```python fred.search('potential gdp').T ``` -------------------------------- ### Search for Series by Category ID Source: https://context7.com/mortada/fredapi/llms.txt Searches for economic series within a specific FRED category. Supports filtering by attributes such as seasonal adjustment. ```python from fredapi import Fred fred = Fred(api_key='your_api_key') # Search for series in category 32991 (H.15 Selected Interest Rates) interest_rates = fred.search_by_category(32991, limit=20, order_by='popularity', sort_order='desc') print(interest_rates[['title', 'frequency', 'popularity']].head()) # Get series from Money Supply category with filter money_supply = fred.search_by_category(32242, filter=('seasonal_adjustment', 'Seasonally Adjusted')) print(money_supply[['title', 'units']].head(10)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.