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.
pip install pyamlVerified import paths — ran on the pinned version, not inferred.
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.
Use `import yaml` from the underlying PyYAML library for loading operations, e.g., `yaml.safe_load(yaml_string)`.
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.
Ensure `PyYAML` is correctly installed and compatible. If encountering issues, try updating `PyYAML` or checking its documentation for platform-specific notes.
Install the PyYAML package using pip: `pip install pyyaml`
For trusted YAML sources, use `yaml.load(stream, Loader=yaml.FullLoader)`. For untrusted sources, which is highly recommended, use `yaml.safe_load(stream)` to load only a safe subset of YAML.
Carefully inspect the YAML file or string for syntax issues, paying close attention to correct indentation, the placement of colons, and valid YAML structure. Tools like online YAML validators can help identify the exact line and column of the error.
Rename your local Python file or directory from `yaml.py` (or `yaml`) to something unique, like `my_yaml_utils.py`, to avoid the name collision.