Skip to main content

A Python library for the FRED API (Federal Reserve Bank of St. Louis)

Project description

fred

Work in progress — the library is being built incrementally. APIs will change as more endpoints are added.

A Python library for the FRED API (Federal Reserve Economic Data, St. Louis Fed).

Overview

fred provides a type-driven Python interface to the FRED API. It is built endpoint by endpoint, with a typed request params model and a typed response model for each endpoint.

Requirements

  • Nix with flakes enabled
  • direnv hooked into your shell
  • An AWS SSO profile with access to the FRED_API_KEY secret in AWS Secrets Manager

Getting started

  1. Clone the repo and cd into it
  2. Create .env.local and set your AWS SSO profile:
    export AWS_PROFILE=<your-aws-sso-profile>
    
  3. Log in to AWS: aws sso login
  4. Allow direnv: direnv allow

direnv will activate the nix dev shell, run uv sync, activate the Python venv, and export FRED_API_KEY automatically.

Usage

Fetch the root FRED category:

import json
import urllib.parse
import urllib.request

from fred import category, for_request

params = category.RequestParams(
    api_key="your-api-key",
    file_type=category.FileType.json,
    category_id=0,
)

url = f"{category.ENDPOINT}?{urllib.parse.urlencode(for_request(params))}"

with urllib.request.urlopen(url) as resp:
    data = json.loads(resp.read())

response = category.Response.model_validate(data)
print(response.categories[0].name)  # "Categories"

Development

Running tests

# Unit and contract tests (no API key required)
pytest -m "unit_test or contract_test"

# All tests (requires FRED_API_KEY)
pytest

Pre-commit hooks

prek manages hooks. After cloning, hooks are activated automatically via .git/hooks. They run:

  • Pre-commit: whitespace/file checks, nix checks (nixfmt, statix, deadnix), Python checks (ruff, ty)
  • Pre-push: uv sync

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fred_stl-0.1.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fred_stl-0.1.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file fred_stl-0.1.0.tar.gz.

File metadata

  • Download URL: fred_stl-0.1.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fred_stl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0d284329cd2f9865682094d5a8a1e03be2befead6641a82a16c6fc5ebeb6e362
MD5 16b153610ef24b15aec6ae7c495550fb
BLAKE2b-256 a628ffff9f17b77381034b85017ac09e5084b480d0cf74142594c14df2dac7bf

See more details on using hashes here.

File details

Details for the file fred_stl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fred_stl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fred_stl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59d3b8d49e4709f3cf238a4acd67961dffa513931ceda55e9de2a87190bacbb4
MD5 c7ce156912a4199a98f44367124be136
BLAKE2b-256 f900c3d38ccee89b2e6be439d29f7be6cc2dcd9f6d68d70c0473210c4fefe747

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page