yayaml#
The yayaml package provides extensions to ruamel.yaml that allow creating
some often-needed Python objects directly via YAML tags and making it easier
to represent custom objects when writing YAML files.
Features:
40+ built-in YAML tags for common operations (math, strings, paths, etc.)
Easy creation of custom constructors and representers
Seamless integration with
ruamel.yamlSupport for environment variables, conditionals, and NumPy arrays
Quick Example#
Use YAML tags to create Python objects directly:
# config.yml
sum: !sum [1, 2, 3] # 6
formatted: !format ["{}+{}={}", 1, 2, 3] # "1+2=3"
linspace: !linspace [-1, 1, 5] # np.linspace(-1, 1, 5)
home_path: !expanduser ~/config # "/home/user/config"
username: !getenv [USER, "unknown_user"] # $USER or fallback
Load and use in Python:
import yayaml as yay
# Load YAML with built-in tags
config = yay.load_yml("config.yml")
print(config["sum"]) # 6
# Or load from string
data = yay.yaml.load("value: !sum [1, 2, 3]")
# Write YAML files
yay.write_yml({"key": "value"}, path="output.yml")