Registry / serialization / pyaml
library26.7.0pypypi✓ verified 27d ago

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 pyaml
INSTALL
IMPORT
SIG · PYAML
P
pyaml
serializationpythonv26.7.0
Install
1.7s avg
Import
157ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v26.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.158s · 20.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.156s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dump
import pyaml # then use pyaml.dump(...)
pyaml provides dump and dumps functions directly under its module namespace.
dumps
import pyaml # then use pyaml.dumps(...)
pyaml provides dump and dumps functions directly under its module namespace.

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.

import pyaml import sys data = { 'name': 'Alice', 'age': 30, 'isStudent': False, 'courses': [ {'title': 'Math', 'credits': 3}, {'title': 'History', 'credits': 4} ], 'address': { 'street': '123 Main St', 'city': 'Anytown', 'zip': '12345' } } # Dump to stdout with pretty formatting print('--- Pretty YAML Output (to stdout) ---') pyaml.dump(data, sys.stdout) # Or get as a string yaml_string = pyaml.dumps(data) print('\n--- Pretty YAML Output (as string) ---') print(yaml_string)
Debug
Known issues
gotchapyaml 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`).
fix
Use `import yaml` from the underlying PyYAML library for loading operations, e.g., `yaml.safe_load(yaml_string)`.
affects: All versions
gotchaWhile `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.
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.
affects: All versions
gotchapyaml 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`.
fix
Ensure `PyYAML` is correctly installed and compatible. If encountering issues, try updating `PyYAML` or checking its documentation for platform-specific notes.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'yaml'
The PyYAML package, which provides the 'yaml' module, is not installed in the Python environment, or the environment where it's installed is not active. pyaml depends on PyYAML to function.
fix
Install the PyYAML package using pip: `pip install pyyaml`
yaml.YAMLLoadWarning: The default loader for yaml.load is unsafe. Please read https://pyyaml.org/wiki/PyYAMLDocumentation for more information.
PyYAML's `yaml.load()` function has been deprecated without explicitly specifying a `Loader` due to security vulnerabilities, starting from PyYAML 5.1.
fix
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.
yaml.scanner.ScannerError: mapping values are not allowed here
The YAML content being parsed contains a syntax error, such as incorrect indentation, a missing colon (`:`), or an unexpected character in a context where a mapping value is expected. Other common `ScannerError` messages include 'could not find expected ':' or 'invalid indentation level'.
fix
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.
AttributeError: module 'yaml' has no attribute 'load'
This error typically occurs when a local Python file or directory in your project is named `yaml.py` or `yaml`, which shadows the installed `PyYAML` library, causing Python to import your local (empty or unrelated) module instead of the actual `PyYAML` package.
fix
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.
Upgrade
Version history
26.7.0latest on PyPI · released Jul 4, 2026
Audit
Dependencies
PyYAMLrequiredpyaml is a wrapper around PyYAML, providing enhanced dumping capabilities. PyYAML is a core dependency for all YAML parsing and dumping operations.
Agent activity
23 hits · last 30 days
node
20
Resources
pyaml — pip install pyaml · libregistry