Annotated YAML

1.0.2 · active · verified Thu Apr 16

Annotated YAML is a Python library that provides advanced YAML parsing and dumping capabilities, supporting secrets management and deep integration with Python's type hinting system. It builds upon `ruamel.yaml` and targets modern Python environments. The current version is 1.0.2, with a frequent release cadence, primarily for bug fixes and platform support within the 1.x series.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic loading and dumping of YAML data. For secrets support, install `annotatedyaml[secrets]` and set the `ENCRYPTED_SECRETS_KEY` environment variable.

import io
from annotated_yaml import load, dump

yaml_config_str = io.StringIO("""
app_name: MyConfigApp
version: 1.0.0
database:
  host: localhost
  port: 5432
features:
  - user_profiles
  - notifications
""")

# Load configuration from a string (or file-like object)
config = load(yaml_config_str)

print(f"Application Name: {config['app_name']}")
print(f"Database Host: {config['database']['host']}")
print(f"Enabled Features: {', '.join(config['features'])}")

# You can also dump the configuration back to YAML
print("\n--- Dumped YAML ---")
dump(config, io.StringIO().write) # Dumps to a string, or sys.stdout to print directly

view raw JSON →