### Install pyfredapi via pip Source: https://github.com/gw-moore/pyfredapi/blob/main/README.md Commands to install the library, including optional dependency sets. ```bash pip install pyfredapi ``` ```bash pip install 'pyfredapi[all]' ``` ```bash pip install 'pyfredapi[polars]' ``` -------------------------------- ### Install pyfredapi Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/index.md Install the pyfredapi library using pip. Include plotting dependencies with '[plot]'. ```bash pip install pyfredapi ``` ```bash pip install 'pyfredapi[plot]' ``` -------------------------------- ### Get Releases from a Specific Source Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves all releases published by a given data source. Requires the `source_id`. The example shows how to get releases from the U.S. Bureau of Labor Statistics and prints the count and names of the first five releases. ```python import pyfredapi as pf # Get releases from Bureau of Labor Statistics bls_releases = pf.get_source_release(source_id=17) print(f"Number of releases: {len(bls_releases['releases'])}") for release in bls_releases['releases'][:5]: print(f"{release['id']}: {release['name']}") ``` -------------------------------- ### Get metadata for a single FRED release by ID Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/releases.ipynb Fetches metadata for a specific FRED release using its unique ID. This example retrieves information for the 'Employment Cost Index' release. ```python employment_cost_index = pf.get_release(release_id="11") ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/references/CONTRIBUTING.md Install the development dependencies for pyfredapi using pip. This includes packages needed for testing and development. ```bash pip install '.[dev]' ``` -------------------------------- ### Get Geographic Shape Files Source: https://context7.com/gw-moore/pyfredapi/llms.txt Downloads geographic shape files in Well-Known Text (WKT) format, suitable for mapping. Supports various shapes like 'state', 'county', and 'msa'. The example retrieves state boundaries and shows the keys available in the shape data. ```python import pyfredapi as pf # Get state boundaries state_shapes = pf.get_shape_files(shape="state") print(f"Number of shapes: {len(state_shapes['shapes'])}") print(state_shapes['shapes'][0].keys()) # Get county boundaries county_shapes = pf.get_shape_files(shape="county") # Available shapes: "bea", "msa", "frb", "necta", "state", # "country", "county", "censusregion", "censusdivision" ``` -------------------------------- ### List Start Date of Series in Collection Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/series_collection.ipynb List the start dates for series within the SeriesCollection, grouping series by their respective start dates. This is useful for understanding the historical coverage of the data. ```python cpi_sc.list_start_date() ``` -------------------------------- ### Get All FRED Tags or Search Tags Source: https://context7.com/gw-moore/pyfredapi/llms.txt Fetches all available tags in FRED or searches for tags matching a specific text. Use `search_text` for keyword searches and `tag_group_id` to filter by group. The example demonstrates getting all tags, searching for 'gdp' tags, and retrieving tags by group 'freq'. ```python import pyfredapi as pf # Get all tags all_tags = pf.get_tags() print(f"Total tags: {len(all_tags['tags'])}") # Search for tags containing "gdp" gdp_tags = pf.get_tags(search_text="gdp") for tag in gdp_tags['tags'][:5]: print(f"{tag['name']}: {tag['series_count']} series") # Get tags by group frequency_tags = pf.get_tags(tag_group_id="freq") for tag in frequency_tags['tags']: print(f"{tag['name']}: {tag['series_count']} series") ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/references/CONTRIBUTING.md Set up pre-commit hooks to automatically format code and run checks before commits. This helps maintain code quality. ```bash pre-commit install ``` -------------------------------- ### Get Specific Data Source Information Source: https://context7.com/gw-moore/pyfredapi/llms.txt Fetches detailed information about a particular data source using its ID. Requires the `source_id` parameter. The example retrieves information for the U.S. Bureau of Labor Statistics. ```python import pyfredapi as pf # Get Bureau of Labor Statistics info bls = pf.get_source(source_id=17) print(bls) ``` -------------------------------- ### GET /release/sources Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieve data sources for a specific release. ```APIDOC ## GET /release/sources ### Description Get the sources (data providers) for a specific release. ### Parameters #### Query Parameters - **release_id** (int) - Required - The ID of the release. ``` -------------------------------- ### Get Series Matching Specific Tags Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves economic series that match all specified tags. Tags should be provided as a semicolon-separated string to the `tag_names` parameter. The example finds monthly, seasonally adjusted unemployment series. ```python import pyfredapi as pf # Find monthly, seasonally adjusted unemployment series series = pf.get_series_matching_tags(tag_names="unemployment;monthly;sa") print(f"Number of matching series: {len(series['seriess'])}") for s in series['seriess'][:5]: print(f"{s['id']}: {s['title']}") ``` -------------------------------- ### GET /release Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieve information about a specific release by ID. ```APIDOC ## GET /release ### Description Get information about a specific release by ID. ### Parameters #### Query Parameters - **release_id** (int) - Required - The ID of the release. ``` -------------------------------- ### GET /releases Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieve information about all economic data releases. ```APIDOC ## GET /releases ### Description Get information about all releases of economic data available in FRED. ### Parameters #### Query Parameters - **limit** (int) - Optional - Number of results to return. - **offset** (int) - Optional - Number of results to skip. ``` -------------------------------- ### GET /sources Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves a list of all available economic data sources from FRED. ```APIDOC ## GET /sources ### Description Get all sources of economic data in FRED. ### Method GET ### Endpoint /sources ### Parameters None ### Request Example ```python import pyfredapi as pf sources = pf.get_sources() ``` ### Response #### Success Response (200) - **sources** (list) - A list of dictionaries, where each dictionary contains information about a data source (id, name, link). #### Response Example ```json { "sources": [ { "id": 1, "name": "Board of Governors of the Federal Reserve System (US)", "link": "http://www.federalreserve.gov/" }, ... ] } ``` ``` -------------------------------- ### GET /release/dates Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieve release dates for a specific release. ```APIDOC ## GET /release/dates ### Description Get the release dates for a specific release to see when data was published. ### Parameters #### Query Parameters - **release_id** (int) - Required - The ID of the release. ``` -------------------------------- ### Get Metadata for a Geographic Series Source: https://context7.com/gw-moore/pyfredapi/llms.txt Fetches metadata for a specific geographic series (GeoFRED). Requires a `series_id`. The example retrieves and prints details like title, region type, units, frequency, and date range for 'Per Capita Personal Income by State'. ```python import pyfredapi as pf # Get info for Per Capita Personal Income by State geo_info = pf.get_geoseries_info(series_id="WIPCPI") print(f"Title: {geo_info.title}") print(f"Region Type: {geo_info.region_type}") print(f"Units: {geo_info.units}") print(f"Frequency: {geo_info.frequency}") print(f"Date Range: {geo_info.min_date} to {geo_info.max_date}") ``` -------------------------------- ### GET /release/tags Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieve tags for series within a specific release. ```APIDOC ## GET /release/tags ### Description Get the tags for series within a release. ### Parameters #### Query Parameters - **release_id** (int) - Required - The ID of the release. ``` -------------------------------- ### Get metadata for all FRED releases Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/releases.ipynb Fetches metadata for all available FRED releases. The result includes a count of releases and a list of release objects. ```python all_releases = pf.get_releases() ``` -------------------------------- ### Get Geographic/Regional Data for a Series Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves geographic or regional data for a given series, returning cross-sectional data by region. Supports returning data as a pandas DataFrame or JSON. The example shows fetching data as a DataFrame and then as JSON. ```python import pyfredapi as pf # Get Per Capita Personal Income by State as pandas DataFrame geo_data = pf.get_geoseries( series_id="WIPCPI", start_date="2020-01-01", end_date="2022-01-01" ) print(f"Info: {geo_data.info.title}") print(geo_data.data.head(10)) ``` ```python import pyfredapi as pf # Get as JSON geo_json = pf.get_geoseries( series_id="WIPCPI", return_format="json" ) ``` -------------------------------- ### Get Related FRED Tags Source: https://context7.com/gw-moore/pyfredapi/llms.txt Finds tags that are related to a given set of tags. Requires tag names to be provided as a semicolon-separated string using the `tag_names` parameter. The example shows how to find tags related to 'gdp' and 'quarterly'. ```python import pyfredapi as pf # Get tags related to 'gdp' and 'quarterly' related = pf.get_related_tags(tag_names="gdp;quarterly") print(f"Number of related tags: {len(related['tags'])}") for tag in related['tags'][:10]: print(f"{tag['name']} ({tag['group_id']}): {tag['series_count']} series") ``` -------------------------------- ### Get Initial Release Values Source: https://context7.com/gw-moore/pyfredapi/llms.txt Fetches only the initial release values for a data series, excluding all subsequent revisions. This is particularly useful for analyzing real-time data availability. ```python import pyfredapi as pf # Get initial release values only (no revisions) initial_gdp = pf.get_series_initial_release(series_id="GDP") print(initial_gdp.head()) # Output: # date realtime_start realtime_end value # 0 1947-01-01 1947-02-01 9999-12-31 227.000 # 1 1947-04-01 1947-06-01 9999-12-31 228.200 # 2 1947-07-01 1947-09-01 9999-12-31 229.900 # Compare initial vs current release current_gdp = pf.get_series(series_id="GDP") print(f"Initial 2020-Q1 GDP: {initial_gdp[initial_gdp['date'] == '2020-01-01']['value'].values[0]}") print(f"Current 2020-Q1 GDP: {current_gdp[current_gdp['date'] == '2020-01-01']['value'].values[0]}") ``` -------------------------------- ### Retrieve FRED Series Data Source: https://github.com/gw-moore/pyfredapi/blob/main/README.md Examples of fetching series data using either an environment variable or a direct parameter. ```python import pyfredapi as pf # api key set as environment variable pf.get_series(series_id="GDP") # api key passed to the function pf.get_series(series_id="GDP", api_key="my_api_key") ``` -------------------------------- ### Initialize Plotting Figure and Axes Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/maps.ipynb Create a Matplotlib figure and axes object for plotting the spatial data. This is a standard setup for Matplotlib plots. ```python fig, ax = plt.subplots(figsize=(10, 10)) ``` ```python from mpl_toolkits.axes_grid1 import make_axes_locatable ``` ```python fig, ax = plt.subplots(1, 1) ``` -------------------------------- ### GET /series/tags Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves economic series that match all of the specified tags. ```APIDOC ## GET /series/tags ### Description Get series that match all specified tags. ### Method GET ### Endpoint /series/tags ### Parameters #### Query Parameters - **tag_names** (string) - Required - A semicolon-separated list of tag names (e.g., "unemployment;monthly;sa"). ### Request Example ```python import pyfredapi as pf series = pf.get_series_matching_tags(tag_names="unemployment;monthly;sa") ``` ### Response #### Success Response (200) - **seriess** (list) - A list of dictionaries, where each dictionary represents a series and includes its ID and title. #### Response Example ```json { "seriess": [ { "id": "UNRATE", "title": "Unemployment Rate" }, ... ] } ``` ``` -------------------------------- ### Retrieve Series Info using pyfredapi Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/index.md Example of retrieving series information using pyfredapi. The API key can be set as an environment variable or passed directly to the function. ```python import pyfreadpi as pf # api key set as environment variable pf.get_series_info(series_id="GDP") ``` ```python # api key passed to function pf.get_series_info(series_id="GDP", api_key="my_api_key") ``` -------------------------------- ### GET /release/series Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieve series available within a specific release. ```APIDOC ## GET /release/series ### Description Get the series available within a specific release. ### Parameters #### Query Parameters - **release_id** (int) - Required - The ID of the release. ``` -------------------------------- ### GET /sources/{source_id} Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves detailed information about a specific economic data source. ```APIDOC ## GET /sources/{source_id} ### Description Get information about a specific data source. ### Method GET ### Endpoint /sources/{source_id} ### Parameters #### Path Parameters - **source_id** (int) - Required - The ID of the data source. ### Request Example ```python import pyfredapi as pf bls = pf.get_source(source_id=17) ``` ### Response #### Success Response (200) - **sources** (list) - A list containing a single dictionary with information about the specified source (id, name, link). #### Response Example ```json { "sources": [ { "id": 17, "name": "U.S. Bureau of Labor Statistics", "link": "http://www.bls.gov/" }, ... ] } ``` ``` -------------------------------- ### GET /category Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieve information about a specific FRED category by its ID. ```APIDOC ## GET /category ### Description Get details for a specific category using its unique identifier. ### Parameters #### Query Parameters - **category_id** (int) - Required - The unique ID of the category. ### Response #### Success Response (200) - **categories** (list) - A list containing the category object with id, name, and parent_id. ``` -------------------------------- ### GET /category/series Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieve all series associated with a specific category. ```APIDOC ## GET /category/series ### Description Get all series within a category. Returns a dictionary of SeriesInfo objects keyed by series ID. ### Parameters #### Query Parameters - **category_id** (int) - Required - The ID of the category. ``` -------------------------------- ### GET /category/tags Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieve FRED tags for series within a specific category. ```APIDOC ## GET /category/tags ### Description Get the FRED tags for series within a category. ### Parameters #### Query Parameters - **category_id** (int) - Required - The ID of the category. - **return_format** (string) - Optional - Format of the returned data (e.g., 'pandas'). ``` -------------------------------- ### Get All Releases as JSON Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves all releases for a given series ID in JSON format. This is useful for a comprehensive overview of a series' release history. ```python all_releases_json = pf.get_series_all_releases( series_id="UNRATE", return_format="json" ) ``` -------------------------------- ### Get release series data Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/releases.ipynb Fetches the series associated with the specified release ID. ```python series = pf.get_release_series(release_id="11") ``` -------------------------------- ### GET /shapefiles Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves geographic shape files in Well-Known Text (WKT) format, suitable for mapping. ```APIDOC ## GET /shapefiles ### Description Get geographic shape files in Well-Known Text (WKT) format for mapping. ### Method GET ### Endpoint /shapefiles ### Parameters #### Query Parameters - **shape** (string) - Required - The type of shape file to retrieve. Available options include: "bea", "msa", "frb", "necta", "state", "country", "county", "censusregion", "censusdivision". ### Request Example ```python import pyfredapi as pf # Get state boundaries state_shapes = pf.get_shape_files(shape="state") # Get county boundaries county_shapes = pf.get_shape_files(shape="county") ``` ### Response #### Success Response (200) - **shapes** (list) - A list of dictionaries, where each dictionary contains the name, code, and WKT shape data for a geographic region. #### Response Example ```json { "shapes": [ { "name": "Alabama", "code": "AL", "shape": "POLYGON ((...))" }, ... ] } ``` ``` -------------------------------- ### GET /sources/{source_id}/releases Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves a list of all releases published by a specific data source. ```APIDOC ## GET /sources/{source_id}/releases ### Description Get the releases published by a specific source. ### Method GET ### Endpoint /sources/{source_id}/releases ### Parameters #### Path Parameters - **source_id** (int) - Required - The ID of the data source. ### Request Example ```python import pyfredapi as pf bls_releases = pf.get_source_release(source_id=17) ``` ### Response #### Success Response (200) - **releases** (list) - A list of dictionaries, where each dictionary contains information about a release (id, name, related_code, similar_units, etc.). #### Response Example ```json { "releases": [ { "id": 10, "name": "Consumer Price Index", "related_code": null, "similar_units": null }, ... ] } ``` ``` -------------------------------- ### Get Series Releases Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves the release information for a series, showing which FRED release the series belongs to. ```APIDOC ## get_series_releases ### Description Get the release information for a series, showing which FRED release the series belongs to. ### Method GET (Implicit) ### Endpoint /series/releases ### Parameters #### Query Parameters - **series_id** (string) - Required - The ID of the series. - **api_key** (string) - Optional - Your FRED API key. - **file_type** (string) - Optional - The format of the output (e.g., 'json', 'xml', 'csv'). Defaults to 'json'. ### Request Example ```python import pyfredapi as pf release_info = pf.get_series_releases(series_id="UNRATE") print(release_info) ``` ### Response #### Success Response (200) - **dict** - A dictionary containing release information for the series. Includes 'id', 'realtime_start', 'realtime_end', 'name', 'press_release', and 'link'. ``` -------------------------------- ### Get Shape Files Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/maps.ipynb Retrieve shape files for a specified region (e.g., 'state') in Well-known text (WKT) format. ```python state_shapes_files = pf.get_shape_files(shape="state") ``` ```python pf.get_shape_files(shape="state") ``` -------------------------------- ### Get Metadata for All Releases Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/releases.ipynb Retrieves metadata for all available FRED releases. The response includes a count of releases and a list of release objects. ```APIDOC ## Get metadata for all releases ### Description Retrieves metadata for all available FRED releases. The response includes a count of releases and a list of release objects. ### Method GET ### Endpoint /releases ### Parameters None ### Request Example ```python import pyfredapi as pf all_releases = pf.get_releases() print(all_releases['count']) ``` ### Response #### Success Response (200) - **count** (integer) - The total number of releases. - **releases** (array) - A list of release objects, each containing: - **id** (integer) - The unique identifier for the release. - **realtime_start** (string) - The start date of the release's real-time period. - **realtime_end** (string) - The end date of the release's real-time period. - **name** (string) - The name of the release. - **press_release** (boolean) - Indicates if a press release is associated with this release. - **link** (string) - A URL related to the release. - **notes** (string, optional) - Additional notes about the release. #### Response Example ```json { "count": 314, "releases": [ { "id": 9, "realtime_start": "2024-04-05", "realtime_end": "2024-04-05", "name": "Advance Monthly Sales for Retail and Food Services", "press_release": true, "link": "http://www.census.gov/retail/", "notes": "The U.S. Census Bureau conducts the Advance Monthly Retail Trade and Food Services Survey..." }, { "id": 10, "realtime_start": "2024-04-05", "realtime_end": "2024-04-05", "name": "Consumer Price Index", "press_release": true, "link": "http://www.bls.gov/cpi/" } ] } ``` ``` -------------------------------- ### Get Metadata for a Single Release Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/releases.ipynb Retrieves metadata for a specific FRED release identified by its ID. ```APIDOC ## Get metadata for single release ### Description Retrieves metadata for a specific FRED release identified by its ID. ### Method GET ### Endpoint /release/{release_id} ### Parameters #### Path Parameters - **release_id** (string) - Required - The unique identifier of the release. ### Request Example ```python import pyfredapi as pf employment_cost_index = pf.get_release(release_id="11") ``` ### Response #### Success Response (200) - **realtime_start** (string) - The start date of the release's real-time period. - **realtime_end** (string) - The end date of the release's real-time period. - **releases** (array) - A list containing a single release object with the following fields: - **id** (integer) - The unique identifier for the release. - **realtime_start** (string) - The start date of the release's real-time period. - **realtime_end** (string) - The end date of the release's real-time period. - **name** (string) - The name of the release. - **press_release** (boolean) - Indicates if a press release is associated with this release. - **link** (string) - A URL related to the release. #### Response Example ```json { "realtime_start": "2024-04-05", "realtime_end": "2024-04-05", "releases": [ { "id": 11, "realtime_start": "2024-04-05", "realtime_end": "2024-04-05", "name": "Employment Cost Index", "press_release": true, "link": "http://www.bls.gov/ncs/ect" } ] } ``` ``` -------------------------------- ### Get all tags Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/tags.ipynb Retrieve all available tags from the FRED API. This function fetches a list of tags, each with associated metadata. ```python tags = pf.get_tags() ``` -------------------------------- ### Get Series Tags Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves the FRED tags assigned to a specific series. Tags describe characteristics of the series. ```APIDOC ## get_series_tags ### Description Get the FRED tags assigned to a specific series. Tags describe characteristics of the series. ### Method GET (Implicit) ### Endpoint /series/tags ### Parameters #### Query Parameters - **series_id** (string) - Required - The ID of the series. - **api_key** (string) - Optional - Your FRED API key. - **file_type** (string) - Optional - The format of the output (e.g., 'json', 'xml', 'csv'). Defaults to 'json'. ### Request Example ```python import pyfredapi as pf tags = pf.get_series_tags(series_id="UNRATE") print(tags) ``` ### Response #### Success Response (200) - **dict** - A dictionary containing a list of tags associated with the series. Each tag includes 'name', 'group_id', and 'notes'. ``` -------------------------------- ### Get Initial Release of a Series Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/series.ipynb Fetches only the first estimate released for a given economic series. This is useful for understanding the earliest available data point for a series. ```python gdp_initial_release_df = pf.get_series_initial_release("GDP") gdp_initial_release_df.tail() ``` -------------------------------- ### Get Category Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves information about a FRED category by its ID. Categories organize series hierarchically. ```APIDOC ## get_category ### Description Retrieve information about a FRED category by its ID. Categories organize series hierarchically. ### Method GET (Implicit) ### Endpoint /category ### Parameters #### Query Parameters - **category_id** (integer) - Required - The ID of the category to retrieve. - **api_key** (string) - Optional - Your FRED API key. - **file_type** (string) - Optional - The format of the output (e.g., 'json', 'xml', 'csv'). Defaults to 'json'. ### Request Example ```python import pyfredapi as pf root = pf.get_category(category_id=0) print(root) ``` ### Response #### Success Response (200) - **dict** - A dictionary containing information about the specified category. Includes 'id', 'name', and 'parent_id'. ``` -------------------------------- ### Get All FRED Data Sources Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves a list of all available data sources in FRED. Useful for understanding the origin of different datasets. Displays the total count and the first 10 sources with their IDs and names. ```python import pyfredapi as pf # Get all data sources sources = pf.get_sources() print(f"Total sources: {len(sources['sources'])}") for source in sources['sources'][:10]: print(f"{source['id']}: {source['name']}") ``` -------------------------------- ### GET /tags Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves all FRED tags or allows searching for tags based on a text query and/or tag group. ```APIDOC ## GET /tags ### Description Get all FRED tags or search for specific tags. ### Method GET ### Endpoint /tags ### Parameters #### Query Parameters - **search_text** (string) - Optional - Text to search for within tag names. - **tag_group_id** (string) - Optional - The ID of the tag group to filter by (e.g., 'freq', 'gen'). ### Request Example ```python import pyfredapi as pf # Get all tags all_tags = pf.get_tags() # Search for tags containing "gdp" gdp_tags = pf.get_tags(search_text="gdp") # Get tags by group frequency_tags = pf.get_tags(tag_group_id="freq") ``` ### Response #### Success Response (200) - **tags** (list) - A list of dictionaries, where each dictionary represents a tag and includes its name and series count. #### Response Example ```json { "tags": [ { "name": "gdp", "series_count": 2500 }, ... ] } ``` ``` -------------------------------- ### Get Geoseries Info Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/maps.ipynb Retrieve metadata information for a given GeoSeries. This is useful for understanding the available data before fetching it. ```python info = pf.get_geoseries_info(series_id="WIPCPI") print(info) ``` -------------------------------- ### Build Documentation with Sphinx Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/references/CONTRIBUTING.md Build the project's HTML documentation using Sphinx. Navigate to the docs directory and run the make command. ```bash make html -C docs/ ``` -------------------------------- ### Get Series Initial Release Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves only the initial release values for a data series, excluding all subsequent revisions. This is useful for analyzing real-time data availability. ```APIDOC ## get_series_initial_release ### Description Get only the initial release values for a data series, excluding all subsequent revisions. Useful for analyzing real-time data availability. ### Method GET (Implicit) ### Endpoint /series/initial_release ### Parameters #### Query Parameters - **series_id** (string) - Required - The ID of the series to retrieve. - **api_key** (string) - Optional - Your FRED API key. - **file_type** (string) - Optional - The format of the output (e.g., 'json', 'xml', 'csv'). Defaults to 'json'. ### Request Example ```python import pyfredapi as pf initial_gdp = pf.get_series_initial_release(series_id="GDP") print(initial_gdp.head()) ``` ### Response #### Success Response (200) - **DataFrame** - A pandas DataFrame containing the initial release data for the series. ``` -------------------------------- ### Open Built Documentation Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/references/CONTRIBUTING.md Open the locally built HTML documentation in your web browser. This allows you to preview the documentation. ```bash open docs/_build/html/index.html ``` -------------------------------- ### Get Series Release Information Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves information about the FRED release to which a series belongs. This includes the release ID, relevant dates, name, and a link to the press release if available. ```python import pyfredapi as pf # Get release info for unemployment rate release_info = pf.get_series_releases(series_id="UNRATE") print(release_info) # Output: # { # 'releases': [ # { # 'id': 50, # 'realtime_start': '2024-01-15', # 'realtime_end': '2024-01-15', # 'name': 'Employment Situation', # 'press_release': True, # 'link': 'http://www.bls.gov/news.release/empsit.toc.htm' # } # ] # } ``` -------------------------------- ### Import pyfredapi Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/sources.ipynb Initializes the library for use in your script. ```python import pyfredapi as pf ``` -------------------------------- ### Fetch Series with Additional Parameters Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/series.ipynb Allows fetching a series while passing additional arguments to the FRED API, such as observation start and end dates. Consult the FRED API documentation for available parameters. ```python extra_parameters = { "observation_start": "2020-01-01", "observation_end": "2020-12-31", } gdp_df = pf.get_series(series_id="GDP", **extra_parameters) ``` ```python gdp_df ``` -------------------------------- ### Get Releases As Of a Specific Date Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/series.ipynb Retrieves all data releases for a series that were made on or before a specified date. This function helps limit analysis to data known within a particular timeframe. ```python gdp_090122_df = pf.get_series_asof_date("GDP", date="2022-09-01") gdp_090122_df.tail() ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/gw-moore/pyfredapi/blob/main/RELEASE.md Build the MkDocs documentation site locally. After building, the site/index.html file can be opened in a browser to review the documentation. ```bash mkdocs build ``` ```bash open site/index.html ``` -------------------------------- ### Get Series As Of Date Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves data values for a series as they were known on a specific historical date. This is useful for backtesting models or reproducing historical analysis. ```APIDOC ## get_series_asof_date ### Description Get data values as they were known on a specific historical date. Useful for backtesting models or reproducing historical analysis. ### Method GET (Implicit) ### Endpoint /series/asof ### Parameters #### Query Parameters - **series_id** (string) - Required - The ID of the series to retrieve. - **date** (string) - Required - The historical date (YYYY-MM-DD) to retrieve data as of. - **api_key** (string) - Optional - Your FRED API key. - **file_type** (string) - Optional - The format of the output (e.g., 'json', 'xml', 'csv'). Defaults to 'json'. ### Request Example ```python import pyfredapi as pf gdp_asof = pf.get_series_asof_date( series_id="GDP", date="2020-01-01" ) print(gdp_asof.tail()) ``` ### Response #### Success Response (200) - **DataFrame** - A pandas DataFrame containing the series data as of the specified date. ``` -------------------------------- ### Create and Activate Virtual Environment with Hatch Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/references/CONTRIBUTING.md Create a virtual environment for the project using hatch and then activate it. This isolates project dependencies. ```bash hatch env create hatch shell ``` -------------------------------- ### Get Series Data as of a Specific Date Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves data values for a series as they were known on a specific historical date. This is useful for backtesting models or reproducing historical analysis. ```python import pyfredapi as pf # Get GDP values as they were known on January 1, 2020 gdp_asof = pf.get_series_asof_date( series_id="GDP", date="2020-01-01" ) print(gdp_asof.tail()) # Output shows values as they were published before January 1, 2020: # date realtime_start realtime_end value # 285 2018-07-01 2019-12-20 2020-01-01 20658.2 # 286 2018-10-01 2019-12-20 2020-01-01 20813.3 # 287 2019-01-01 2019-12-20 2020-01-01 21001.6 # 288 2019-04-01 2019-12-20 2020-01-01 21289.3 # 289 2019-07-01 2019-12-20 2020-01-01 21542.5 # Get unemployment as known mid-pandemic unemployment_mid_2020 = pf.get_series_asof_date( series_id="UNRATE", date="2020-06-01" ) ``` -------------------------------- ### Pretty print the first three releases Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/releases.ipynb Displays the metadata for the first three FRED releases in a formatted way. ```python pprint(releases[0:3]) ``` -------------------------------- ### Get All Releases of a Series Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/series.ipynb Retrieves all historical observations for every release of a specified economic series. Useful for tracking how data estimates have evolved. The realtime columns indicate when the data was known. ```python gdp_all_releases_df = pf.get_series_all_releases("GDP") gdp_all_releases_df.tail() ``` -------------------------------- ### Initialize pyfredapi Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/series.ipynb Import the necessary libraries and the pyfredapi package to begin interacting with the FRED API. ```python from rich import print as rprint from rich.pretty import pprint import pyfredapi as pf ``` -------------------------------- ### Parse Series Titles with a Function Source: https://context7.com/gw-moore/pyfredapi/llms.txt Use a custom function to rename series when creating a SeriesCollection. This example demonstrates shortening titles by taking the part before the first colon. ```python def shorten_title(title: str) -> str: return title.split(":")[0].strip() collection2 = pf.SeriesCollection( series_id=["CPIAUCSL", "CPILFESL"], rename=shorten_title ) ``` -------------------------------- ### Pretty print metadata for a single release Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/releases.ipynb Displays the detailed metadata for the 'Employment Cost Index' release in a formatted way. ```python pprint(employment_cost_index) ``` -------------------------------- ### Get Series Tags Source: https://context7.com/gw-moore/pyfredapi/llms.txt Fetches the FRED tags assigned to a specific series. Tags describe the characteristics of a series, such as its geographic scope, seasonality, and frequency. The output includes tag names, group IDs, and notes. ```python import pyfredapi as pf # Get tags for unemployment rate tags = pf.get_series_tags(series_id="UNRATE") print(tags) # Output: # { # 'tags': [ # {'name': 'nation', 'group_id': 'geot', 'notes': '', ...}, # {'name': 'nsa', 'group_id': 'seas', 'notes': '', ...}, # {'name': 'monthly', 'group_id': 'freq', 'notes': '', ...}, # ... # ] # } for tag in tags['tags']: print(f"{tag['name']} ({tag['group_id']})") ``` -------------------------------- ### Import necessary libraries Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/releases.ipynb Imports the pprint function for pretty printing and the pyfredapi library. ```python from rich.pretty import pprint import pyfredapi as pf ``` -------------------------------- ### Compile Documentation Requirements Source: https://github.com/gw-moore/pyfredapi/blob/main/RELEASE.md Compile documentation-specific dependencies from pyproject.toml, including the 'docs' extra, into docs/requirements.txt. This is necessary for building the documentation locally. ```bash python -m piptools compile --upgrade --extra docs -o docs/requirements.txt pyproject.toml ``` -------------------------------- ### Retrieve release sources Source: https://context7.com/gw-moore/pyfredapi/llms.txt Fetches data provider information for a specific release. ```python import pyfredapi as pf # Get sources for Employment Situation sources = pf.get_release_sources(release_id=50) print(sources) # Output: # { # 'sources': [{ # 'id': 17, # 'name': 'U.S. Bureau of Labor Statistics', # 'link': 'http://www.bls.gov/' # }] # } ``` -------------------------------- ### Create and Manage SeriesCollection Source: https://context7.com/gw-moore/pyfredapi/llms.txt Initialize a SeriesCollection with multiple series IDs and manage its contents by listing, accessing, adding, and removing series. ```python collection = pf.SeriesCollection( series_id=["GDP", "UNRATE", "CPIAUCSL"], drop_realtime=True # Remove realtime columns for cleaner data ) # List series in collection collection.list_series() # Check frequencies collection.list_frequency() # Access individual series gdp_data = collection["GDP"] print(gdp_data.df.head()) # Or via attribute print(collection.GDP.info.title) # Add more series collection.add("FEDFUNDS") # Remove series collection.remove("FEDFUNDS") ``` -------------------------------- ### Run Tests with Tox Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/references/CONTRIBUTING.md Run the test and lint suites using tox. This command ensures that the project adheres to quality standards across different environments. ```bash tox ``` -------------------------------- ### Retrieve all releases Source: https://context7.com/gw-moore/pyfredapi/llms.txt Fetches information about all available economic data releases, with support for pagination. ```python import pyfredapi as pf # Get all releases all_releases = pf.get_releases() print(f"Total releases: {len(all_releases['releases'])}") for release in all_releases['releases'][:5]: print(f"{release['id']}: {release['name']}") # Output: # Total releases: 300+ # 9: Advance Monthly Sales for Retail and Food Services # 10: Consumer Price Index # 11: Employment Cost Index # ... # Get with pagination releases_page = pf.get_releases(limit=50, offset=100) ``` -------------------------------- ### Run Unit Tests with VCR Cassettes Source: https://github.com/gw-moore/pyfredapi/blob/main/RELEASE.md Execute the pytest suite and update VCR cassettes for integration tests. The --record-mode=all flag ensures all HTTP interactions are recorded. ```bash pytest tests/ --record-mode=all --runslow ``` -------------------------------- ### Run Tests with Pytest Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/references/CONTRIBUTING.md Execute the project tests using pytest. This is a good initial step to ensure your development environment is set up correctly. ```bash pytest tests/ ``` -------------------------------- ### Compile and Upgrade Requirements Source: https://github.com/gw-moore/pyfredapi/blob/main/RELEASE.md Use piptools to compile and upgrade dependencies from pyproject.toml to requirements.txt. This ensures all project dependencies are up-to-date. ```bash python -m piptools compile --upgrade -o requirements.txt pyproject.toml ``` -------------------------------- ### GET /tags/related Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves FRED tags that are related to a specified set of tags. ```APIDOC ## GET /tags/related ### Description Get FRED tags that are related to specified tags. ### Method GET ### Endpoint /tags/related ### Parameters #### Query Parameters - **tag_names** (string) - Required - A semicolon-separated list of tag names (e.g., "gdp;quarterly"). ### Request Example ```python import pyfredapi as pf related = pf.get_related_tags(tag_names="gdp;quarterly") ``` ### Response #### Success Response (200) - **tags** (list) - A list of dictionaries, where each dictionary represents a related tag and includes its name, group ID, and series count. #### Response Example ```json { "tags": [ { "name": "usa", "group_id": "geo", "series_count": 250 }, ... ] } ``` ``` -------------------------------- ### Build Pyfredapi Package Source: https://github.com/gw-moore/pyfredapi/blob/main/RELEASE.md Build the pyfredapi package locally using hatch. This command generates distribution archives (sdist and wheel) in the dist/ directory. ```bash hatch build ``` -------------------------------- ### GET /category/children Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieve child categories for a given parent category ID. ```APIDOC ## GET /category/children ### Description Get the child categories of a parent category to navigate the FRED category hierarchy. ### Parameters #### Query Parameters - **category_id** (int) - Required - The ID of the parent category. ``` -------------------------------- ### GET /geoseries/{series_id}/info Source: https://context7.com/gw-moore/pyfredapi/llms.txt Retrieves metadata for a specific geographic series (GeoFRED). ```APIDOC ## GET /geoseries/{series_id}/info ### Description Get metadata for a geographic series (GeoFRED). ### Method GET ### Endpoint /geoseries/{series_id}/info ### Parameters #### Path Parameters - **series_id** (string) - Required - The ID of the geographic series. ### Request Example ```python import pyfredapi as pf geo_info = pf.get_geoseries_info(series_id="WIPCPI") ``` ### Response #### Success Response (200) - **title** (string) - The title of the geographic series. - **region_type** (string) - The type of region (e.g., 'state', 'county'). - **units** (string) - The units of measurement for the series. - **frequency** (string) - The frequency of the data (e.g., 'Annual', 'Monthly'). - **min_date** (string) - The earliest date available for the series. - **max_date** (string) - The latest date available for the series. #### Response Example ```json { "title": "Per Capita Personal Income", "region_type": "state", "units": "Dollars", "frequency": "Annual", "min_date": "1929-01-01", "max_date": "2022-01-01" } ``` ``` -------------------------------- ### Create Axes for Colorbar Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/maps.ipynb Set up an axes object specifically for displaying the colorbar, which will represent the data values on the map. ```python divider = make_axes_locatable(ax) ``` ```python cax = divider.append_axes("bottom", size="5%", pad=0.1) ``` -------------------------------- ### API Key Configuration Source: https://context7.com/gw-moore/pyfredapi/llms.txt Configure your FRED API key either as an environment variable or pass it directly to functions. ```APIDOC ## API Key Configuration Set up your FRED API key either as an environment variable or pass it directly to functions. ```python import os # Option 1: Set as environment variable (recommended) os.environ["FRED_API_KEY"] = "your_32_character_api_key_here" # Option 2: Pass directly to functions import pyfredapi as pf data = pf.get_series(series_id="GDP", api_key="your_32_character_api_key_here") ``` ``` -------------------------------- ### Configure FRED API Key Source: https://context7.com/gw-moore/pyfredapi/llms.txt Set the API key via environment variable or pass it directly to function calls. ```python import os # Option 1: Set as environment variable (recommended) os.environ["FRED_API_KEY"] = "your_32_character_api_key_here" # Option 2: Pass directly to functions import pyfredapi as pf data = pf.get_series(series_id="GDP", api_key="your_32_character_api_key_here") ``` -------------------------------- ### Display first three tags Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/tags.ipynb Access and display the first three tags from the retrieved list. This is useful for inspecting the structure of the tag data. ```python tags["tags"][0:3] ``` -------------------------------- ### Import necessary libraries Source: https://github.com/gw-moore/pyfredapi/blob/main/docs/tutorials/category.ipynb Imports the required libraries for data analysis and visualization. ```python import operator import matplotlib.pyplot as plt import seaborn as sns from rich.pretty import pprint import pyfredapi as pf ```