Overview

Date: 2026-05-11

Time: 15:47

Overview

This is a Phase 3 example script demonstrating FTL2's secrets management system. It shows how to securely load, access, inspect, and handle sensitive values (API keys, database URLs, tokens) within automation scripts using the ftl.secrets interface. Secrets are declared upfront when creating an automation context and sourced from environment variables.

Usage Patterns

Secrets are declared as a list of environment variable names when entering the automation context:


async with automation(secrets=["API_KEY", "DB_PASSWORD"]) as ftl:
    value = ftl.secrets["API_KEY"]           # Direct access (raises KeyError if missing)
    value = ftl.secrets.get("OPTIONAL", "default")  # Access with fallback
    if "API_KEY" in ftl.secrets:             # Existence check
        # use it

Secrets can also be passed when constructing AutomationContext directly (without async with):


context = AutomationContext(secrets=["DIRECT_SECRET", "OTHER"])
context.secrets["DIRECT_SECRET"]

Typical use is passing secrets into module calls — e.g., as HTTP headers or connection strings — rather than writing them to files.

API and Configuration

Environment variables must be set before running:


export API_KEY="your-api-key"
export DATABASE_URL="postgres://..."
uv run python example_phase3_secrets.py

Key Behaviors

Relationships