saneyaml
Read and write readable YAML safely preserving order and avoiding bad surprises with unwanted infered type conversions. This library is a PyYaml wrapper with sane behaviour to read and write readable YAML safely, typically when used for configuration.
What it is and what it does
saneyaml is a thin wrapper around PyYAML designed to make YAML parsing and generation more predictable for typical configuration-file use cases. It addresses two common pain points: unwanted type inference (converting strings like '3.0.0' into floats or booleans) and loss of key order. By default, saneyaml loads everything except booleans as strings, preserves insertion order in dictionaries, and can optionally detect duplicate map keys—all while producing clean, readable YAML output when dumping.
The library is intended for developers who need reliable, unsurprising YAML handling in configuration workflows. It trades some of PyYAML's automatic type conversion for predictability, making it especially useful when you want version strings, IDs, and other numeric-looking values to remain strings unless explicitly converted.
Use it for:
- Parse configuration files where numeric-looking strings (versions, IDs) must stay strings and not convert to numbers.
- Generate human-readable YAML output from Python dicts while maintaining consistent formatting and key order.
- Detect and report duplicate keys in YAML maps to catch configuration errors early.
- Load YAML safely in build or deployment tools where type surprises could cause silent failures.
- Preserve the order of configuration keys when round-tripping YAML through Python.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A lightweight PyYAML wrapper that reads and writes YAML safely with predictable behavior, loading everything except booleans as strings and preserving key order.
Yes, if you need predictable YAML handling for configuration files and want to avoid PyYAML's automatic type conversions. The single dependency, permissive license, and low install friction make it a lightweight addition. Maintenance is aging (last release 2024-08-14, no updates in over 730 days), but the repository is active and there are no known security vulnerabilities. Suitable for stable, non-evolving use cases; monitor the repo if you need ongoing feature development.
Install
saneyaml on PyPI
pip
pip install saneyamluv
uv add saneyamlpoetry
poetry add saneyamlInstalling saneyaml
Before you install
Low install friction with a single runtime dependency (PyYAML). Maintenance status is aging—last commit was 2025-03-30 and the latest release was 2024-08-14, over 730 days ago—but the repository remains active and unarchived.
License in practice
Licensed under Apache-2.0 (permissive), so you can use it freely in commercial and private projects without copyleft obligations.
Quickstart
pip install saneyaml
from saneyaml import load, dump
yaml_text = '''version: 3.0.0
description: Example config'''
data = load(yaml_text)
output = dump(data)
print(output)
Requires PyYAML 5.x or higher and Python 3.7+.
Verify before relying
- Whether duplicate key detection is enabled by default or requires explicit configuration.
- Performance characteristics when handling large YAML files compared to raw PyYAML.
- Scope of 'sane behavior' differences from PyYAML beyond type conversion and ordering.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — PyYAML |
| Maintenance | aging — 730 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 170,427/month — #10,395 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: saneyaml-0.6.1-py3-none-any.whl
Keywords: utilities, yaml, pyyaml, block, flow
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
oyamloyaml is a drop-in replacement for PyYAML that…
permissive · top 5,000 on PyPI
pyamlProduces human-readable, diff-friendly YAML…
permissive · top 5,000 on PyPI
yamlcoreAdds YAML 1.2 Core Schema support to PyYAML,…
permissive · top 15,000 on PyPI
yamlableConverts Python objects to YAML and back using…
permissive · top 15,000 on PyPI
yamlloaderProvides specialized loaders and dumpers for…
permissive · top 15,000 on PyPI
aspy.yamlProvides order-preserving YAML loading and…
permissive · top 15,000 on PyPI
yamlordereddictloaderProvides YAML loaders and dumpers for PyYAML…
permissive · top 15,000 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
HyperPyYAMLExtends YAML syntax with Python-friendly…
permissive · top 5,000 on PyPI
annotatedyamlParses and validates YAML files with support…
permissive · top 15,000 on PyPI