pydantic_yaml
YAML reading/writing for Pydantic models
Decision gist · record as of 2026-08-14
Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and fills a clear gap: it lets you use Pydantic's validation and typing with YAML files. If your project needs to read or write YAML with schema validation, this is the standard solution. The MIT license poses no restrictions.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later (package specifies >=3.10,<3.15).
- Low install friction: pure Python wheel with only three runtime dependencies (pydantic, ruamel-yaml, typing-extensions).
- Actively maintained with a release 54 days ago and no known vulnerabilities.
License · maintenance · safety
permissive license (permissive) — MIT License permits commercial and private use, modification, and redistribution with minimal restrictions—standard permissive terms suitable for most projects.
last release 2026-06-21 (54 days) · last repo commit 2026-06-21 · 193 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 2,493,981 downloads/mo, #3,038 on PyPI
Alternatives
Verify before relying
pip install pydantic-yaml
from pydantic import BaseModel
from pydantic_yaml import parse_yaml_raw_as, to_yaml_str
class MyModel(BaseModel):
x: int = 1
name: str = "test"
m = MyModel(x=2, name="example")
yaml_str = to_yaml_str(m)
m2 = parse_yaml_raw_as(MyModel, yaml_str)- Whether comment generation from docstrings (add_comments=True) works reliably with all field types and nested models.
- Performance characteristics when handling large YAML documents or deeply nested structures.
- Compatibility with Pydantic v2 dataclass dumping in production scenarios beyond the documented example.
What it is and what it does
Pydantic-YAML bridges Pydantic's data validation framework with YAML serialization. It provides two main functions: to_yaml_str() converts a validated Pydantic model instance into YAML text, and parse_yaml_raw_as() parses YAML text back into a typed model with full validation. The package leverages Pydantic's existing JSON serialization machinery and wraps ruamel-yaml for YAML handling, so it inherits Pydantic's validator support, nested model composition, and type safety.
Typical usage involves defining a Pydantic BaseModel, instantiating it with data, calling to_yaml_str() to export it as human-readable YAML, and later calling parse_yaml_raw_as() to load and re-validate YAML files. The package also supports optional comment generation from model docstrings and field descriptions, custom YAML writer configuration via ruamel.yaml instances, and works with both Pydantic v1 and v2 (including dataclass support in v2).
Use it for
- Load configuration files in YAML format into typed Pydantic models with automatic validation and type coercion.
- Export application state or settings as human-readable YAML while maintaining schema validation on round-trip.
- Generate YAML documentation or examples from Pydantic models using comment generation from docstrings.
- Migrate data between YAML and JSON formats while preserving type safety through a single Pydantic model definition.
- Validate YAML input in CLI tools or configuration management systems using Pydantic's full validator ecosystem.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
The package is actively maintained, has no known vulnerabilities, low install friction, and fills a clear gap: it lets you use Pydantic's validation and typing with YAML files. If your project needs to read or write YAML with schema validation, this is the standard solution. The MIT license poses no restrictions.
Install
pydantic-yaml on PyPI
Before you install
Low install friction: pure Python wheel with only three runtime dependencies (pydantic, ruamel-yaml, typing-extensions). Actively maintained with a release 54 days ago and no known vulnerabilities.
Requires Python 3.10 or later (package specifies >=3.10,<3.15).
License in practice
MIT License permits commercial and private use, modification, and redistribution with minimal restrictions—standard permissive terms suitable for most projects.
Quickstart
pip install pydantic-yaml
from pydantic import BaseModel
from pydantic_yaml import parse_yaml_raw_as, to_yaml_str
class MyModel(BaseModel):
x: int = 1
name: str = "test"
m = MyModel(x=2, name="example")
yaml_str = to_yaml_str(m)
m2 = parse_yaml_raw_as(MyModel, yaml_str)
Verify before relying
- Whether comment generation from docstrings (add_comments=True) works reliably with all field types and nested models.
- Performance characteristics when handling large YAML documents or deeply nested structures.
- Compatibility with Pydantic v2 dataclass dumping in production scenarios beyond the documented example.
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release <3.15,>=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 3 packagespydanticruamel-yamltyping-extensions |
| Maintenance | Actively maintained 54 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,493,981 / month, #3,038 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3 :: OnlyTopic :: Software DevelopmentTyping :: Typed |
Evidence: pydantic_yaml-1.7.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “pydantic yaml serialization”
- pydantic_yamlPydantic-YAML adds YAML serialization and deserialization to Pydantic…
- open-data-contract-standardReads and writes YAML files conforming to the Open Data Contract…
- datacontract-specificationReads and writes YAML files conforming to the Data Contract…
Give your agent the search over MCP, or paste the wish link into any chat.
More Software Development packages
Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.
See also pydantic-numpy · drf-pydantic · dyntastic · pydantic-collections · datacontract-specification · open-data-contract-standard · django-pydantic-field · flask-pydantic-spec · numpydantic · pydantic-to-pyarrow