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.2.0.tar.gz (10.2 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.2.0-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fred_stl-0.2.0.tar.gz
  • Upload date:
  • Size: 10.2 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.2.0.tar.gz
Algorithm Hash digest
SHA256 48903a105cd9703b16f2e983b03fd1a5c534b73bf6479c257192911d0d5cba5f
MD5 7849383ff10bcc5c104c3ca739cdab98
BLAKE2b-256 7a7f6236ab17ee5b6a912405c895acc662a059014bc9847ecd58db0c24482366

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fred_stl-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 38.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb3ce4f083125287730fc9aecc9de8f0e2a40a552c3aec0eacc866af07be39b0
MD5 d7c4f66f49b9c0b92ee645a633496cd0
BLAKE2b-256 d79f0fba621e284554fae8b720d6352ba2b03e5df33233aca22c68146ca55ea7

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