{"library":"pyyaml-env-tag","code":"import yaml\nimport os\nfrom yaml_env_tag import add_env_tag\n\n# Create a YAML string with environment variable tags\nyaml_content = \"\"\"\ndatabase:\n  host: !ENV DB_HOST\n  port: !ENV [DB_PORT, 5432] # Uses 5432 if DB_PORT is not set\n  user: !ENV [DB_USER, default_user] # Uses 'default_user' if DB_USER is not set\napi_key: !ENV [API_KEY_SECRET, FALLBACK_API_KEY, \"no_api_key_set\"]\n\"\"\"\n\n# Set some environment variables for testing\nos.environ['DB_HOST'] = 'localhost'\nos.environ['API_KEY_SECRET'] = 'my_super_secret_key'\n# DB_PORT, DB_USER, and FALLBACK_API_KEY are intentionally not set to demonstrate fallbacks\n\n# Get a PyYAML SafeLoader and add the environment tag constructor to it.\n# It's crucial to use SafeLoader for security with untrusted YAML.\nSafeEnvLoader = add_env_tag(yaml.SafeLoader)\n\n# Load the YAML content\nconfig = yaml.load(yaml_content, Loader=SafeEnvLoader)\n\nprint(\"Loaded Configuration:\")\nprint(config)\n\n# Clean up environment variables (good practice, especially in automated tests)\ndel os.environ['DB_HOST']\ndel os.environ['API_KEY_SECRET']\n\n# Expected output:\n# Loaded Configuration:\n# {\n#   'database': {'host': 'localhost', 'port': 5432, 'user': 'default_user'},\n#   'api_key': 'my_super_secret_key'\n# }","lang":"python","description":"This quickstart demonstrates how to load YAML content containing `!ENV` tags, which resolve to environment variable values or specified defaults. It highlights the use of `add_env_tag` with `yaml.SafeLoader` for secure parsing and showcases both single variable and fallback sequence syntaxes. Set environment variables using `os.environ` before loading the YAML.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}