{"id":3804,"library":"shyaml","title":"shyaml: YAML for the Command Line (Python version)","description":"The original `shyaml` Python library (v0.6.2) is a command-line tool designed for reading and querying YAML files. It enables shell scripts to easily access YAML data using simple dot-notation paths. While it remains available on PyPI, this Python version is in a low-maintenance state with no new features planned. Active development has transitioned to `shyaml-rs`, a Rust rewrite that offers significant performance improvements and additional features like write capabilities, while maintaining command-line interface compatibility.","status":"maintenance","version":"0.6.2","language":"en","source_language":"en","source_url":"https://github.com/0k/shyaml","tags":["yaml","cli","parser","configuration","shell","automation"],"install":[{"cmd":"pip install shyaml","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Used for YAML parsing in the Python version.","package":"PyYAML","optional":false}],"imports":[{"note":"The Python `shyaml` library is primarily intended as a command-line tool. While a Python API exists via `shyaml.do()`, its typical usage involves piping YAML data from standard input to the `shyaml` executable rather than direct Python imports for general-purpose YAML manipulation.","symbol":"shyaml.do","correct":"import shyaml\n# ... then call shyaml.do(stdin_stream, args)"}],"quickstart":{"code":"cat <<EOF > config.yaml\ndatabase:\n  host: localhost\n  port: 5432\n  credentials:\n    username: admin\n    password: ${DB_PASSWORD:-fallback_pass}\nEOF\n\nDB_PASSWORD=\"secure_pass\" \\\n  cat config.yaml | shyaml get-value database.credentials.password","lang":"bash","description":"The primary use of `shyaml` is via the command line to extract values from YAML. It reads YAML from standard input and outputs the requested value to standard output. Paths are specified using dot notation."},"warnings":[{"fix":"Consider migrating to `shyaml-rs` for performance and new features. If you rely solely on CLI parsing, `shyaml-rs` should work seamlessly: `cargo install shyaml-rs` (if Rust is installed) or download a pre-built binary.","message":"The Python `shyaml` library is in maintenance mode. `shyaml-rs`, a Rust rewrite, is the actively developed and recommended replacement. `shyaml-rs` is designed as a drop-in CLI replacement, offering 14-42x faster performance and new write capabilities (e.g., `set-value`, `del`, `apply`) not present in the Python version.","severity":"gotcha","affected_versions":"All versions of Python shyaml"},{"fix":"Always provide a default value as the third argument to `shyaml get-value` if the key might be missing and you don't want an error: `cat file.yaml | shyaml get-value some.path 'my_default_value'`","message":"Handling of missing paths changed significantly in version 0.3. Prior to 0.3, if a specified key was not found, `shyaml` would return an empty string by default. From version 0.3 onwards (inclusive), if a key is not found and no default value is explicitly provided as the third argument, `shyaml` will print an error message and exit.","severity":"breaking","affected_versions":"< 0.3 vs. >= 0.3"},{"fix":"Ensure your scripts do not rely on a specific (or alphabetically sorted) order of keys if using older versions, or upgrade to 0.4.0+ if order preservation is critical. The current version (0.6.2) preserves order.","message":"Ordered mappings behavior changed in version 0.4.0. Before 0.4.0, `shyaml` would alphabetically re-order keys in mappings. While YAML specification considers mappings unordered, this behavior could be unexpected for users. From version 0.4.0 onwards, `shyaml` preserves the order of keys in mappings.","severity":"breaking","affected_versions":"< 0.4.0 vs. >= 0.4.0"},{"fix":"Use `shyaml --yaml get-value ...` or `shyaml -y get-value ...` to ensure strict YAML output for all values.","message":"By default, `shyaml` outputs simple string or number values directly without YAML quotes for convenience. This means the output is not strictly valid YAML in all cases. If you need strict YAML output (e.g., for piping to another YAML processor), you must use the `--yaml` or `-y` option.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}