{"id":1641,"library":"pyaml","title":"pyaml - Pretty YAML Dumper","description":"pyaml is a PyYAML-based module designed to produce more human-readable and aesthetically pleasing YAML-serialized data. It provides enhanced defaults for indentation, key sorting, and block-style formatting. The current version is 26.2.1, and it maintains a moderate release cadence, with updates typically several times a year to reflect PyYAML changes or minor enhancements.","status":"active","version":"26.2.1","language":"en","source_language":"en","source_url":"https://github.com/mk-fg/pretty-yaml","tags":["yaml","serialization","pretty-print","developer-tool"],"install":[{"cmd":"pip install pyaml","lang":"bash","label":"Install pyaml"}],"dependencies":[{"reason":"pyaml is a wrapper around PyYAML, providing enhanced dumping capabilities. PyYAML is a core dependency for all YAML parsing and dumping operations.","package":"PyYAML","optional":false}],"imports":[{"note":"pyaml provides dump and dumps functions directly under its module namespace.","symbol":"dump","correct":"import pyaml\n# then use pyaml.dump(...)"},{"note":"pyaml provides dump and dumps functions directly under its module namespace.","symbol":"dumps","correct":"import pyaml\n# then use pyaml.dumps(...)"}],"quickstart":{"code":"import pyaml\nimport sys\n\ndata = {\n    'name': 'Alice',\n    'age': 30,\n    'isStudent': False,\n    'courses': [\n        {'title': 'Math', 'credits': 3},\n        {'title': 'History', 'credits': 4}\n    ],\n    'address': {\n        'street': '123 Main St',\n        'city': 'Anytown',\n        'zip': '12345'\n    }\n}\n\n# Dump to stdout with pretty formatting\nprint('--- Pretty YAML Output (to stdout) ---')\npyaml.dump(data, sys.stdout)\n\n# Or get as a string\nyaml_string = pyaml.dumps(data)\nprint('\\n--- Pretty YAML Output (as string) ---')\nprint(yaml_string)","lang":"python","description":"This quickstart demonstrates how to use `pyaml.dump` to write YAML data to a file-like object (like `sys.stdout`) and `pyaml.dumps` to get the formatted YAML as a string. pyaml automatically applies its 'pretty' formatting defaults, including sorted keys and sensible indentation."},"warnings":[{"fix":"Use `import yaml` from the underlying PyYAML library for loading operations, e.g., `yaml.safe_load(yaml_string)`.","message":"pyaml focuses exclusively on *dumping* (serialization) YAML data. It does not provide `load` or `loads` functionality for deserializing YAML. For deserialization, you must use `PyYAML` directly (e.g., `yaml.safe_load`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always test `pyaml` output if migrating from raw `PyYAML` dumping. Most `pyaml.dump` options can be manually configured (e.g., `sort_keys=False`) to revert specific behaviors if desired.","message":"While `pyaml` is built on `PyYAML`, its default output behavior (e.g., `sort_keys=True`, specific indentation, preference for block style) differs significantly from `PyYAML`'s raw `dump` defaults. This is its core purpose, but users expecting a drop-in replacement that only visually enhances existing `PyYAML` output might be surprised by structural changes.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `PyYAML` is correctly installed and compatible. If encountering issues, try updating `PyYAML` or checking its documentation for platform-specific notes.","message":"pyaml requires `PyYAML` to be installed. Although `pip install pyaml` typically installs `PyYAML` as a dependency, it's essential to understand that `pyaml` is a wrapper, not a standalone YAML library. Issues with `PyYAML` (e.g., version conflicts, specific platform issues) can affect `pyaml`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}