PyYAML

A full-featured YAML parser and emitter for Python, with C-accelerated bindings

Library
PyPI
v6.0.3
2,958 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
61 /100 Good
Development Activity 44
Maintenance 24
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
78 /100 Good
Architecture 82
Code Quality 78
Innovation 68
Learning Curve 85

PyYAML is the canonical YAML processing library for Python, providing a complete implementation of the YAML 1.1 specification for parsing YAML documents into native Python objects and serializing Python objects back into YAML text. It exposes a small, well-known API — yaml.safe_load, yaml.load, and yaml.dump — that has become the de facto standard for reading and writing configuration files, CI pipelines, Kubernetes manifests, and structured data across the Python ecosystem.

Under the hood, PyYAML is built as a layered pipeline of scanner, parser, composer, constructor, and resolver stages, each independently swappable, and it can optionally link against libyaml (via Cython bindings, CSafeLoader/CDumper) for significantly faster parsing and emitting on large documents. The library ships as pure Python by default so it works everywhere CPython runs, with the C extension as an opt-in performance upgrade.

What You Get

  • A complete YAML 1.1 parser and emitter accessible through yaml.safe_load(), yaml.load(), and yaml.dump()
  • Safe-by-default loading (SafeLoader/safe_load) that only constructs plain Python types, plus FullLoader and the legacy unsafe Loader for advanced tag resolution
  • Optional libyaml-backed CSafeLoader/CDumper classes for significantly faster parsing and emitting of large YAML documents
  • Support for custom YAML tags and Python-specific object serialization via representer/constructor registration
  • A layered, swappable pipeline (Reader, Scanner, Parser, Composer, Constructor, Resolver) that advanced users can extend or subclass

Common Use Cases

  • Loading and validating application configuration files written in YAML
  • Parsing CI/CD pipeline definitions (GitHub Actions, GitLab CI) and Kubernetes/Docker Compose manifests
  • Serializing Python data structures to human-readable YAML for storage or interchange
  • Round-tripping structured data between services or tools that standardize on YAML as their config format

Under The Hood

Architecture PyYAML is organized as a mixin-composed pipeline rather than a monolithic parser: Reader handles raw stream decoding, Scanner tokenizes the input, Parser turns tokens into a stream of parsing events, Composer assembles those events into a node graph, Constructor walks the node graph to build native Python objects, and Resolver decides implicit tag types (e.g. distinguishing a bare 42 as an int vs a string). Concrete loader classes such as SafeLoader, FullLoader, and Loader (in lib/yaml/loader.py) simply combine these mixins with different Constructor variants to control how much trust is placed in the input — SafeConstructor only ever builds plain dicts/lists/scalars, while Constructor/UnsafeConstructor can instantiate arbitrary Python objects from YAML tags, which is why yaml.load() requires an explicit Loader argument and safe_load() is the recommended default. The emitter side mirrors this with Emitter, Serializer, and Representer stages composed into Dumper/SafeDumper classes.

Tech Stack The library is pure Python at its core (lib/yaml/*.py, ~5,900 lines across scanner, parser, emitter, constructor, representer, and resolver modules) with an optional Cython extension (lib/_yaml/_yaml.pyx) that binds to the C libyaml library for the CSafeLoader/CDumper fast path. Packaging uses a custom PEP 517 build backend (packaging/) driven by setup.py and pyproject.toml, which probes for a system libyaml install and conditionally builds the Cython extension; when libyaml isn’t available, PyYAML falls back transparently to the pure-Python implementation.

Code Quality The tests/ directory includes both a modern pytest-based suite (test_dump_load.py, test_merge.py) and an extensive legacy suite (tests/legacy_tests/) covering structure, constructors, representers, resolvers, error handling, and round-trip canonical-YAML fixtures — a strong signal of correctness coverage for a spec-implementing library, though the codebase predates modern Python type hints and does not use static typing throughout. Security-sensitive code paths are explicit: BaseConstructor.check_state_key() blacklists dunder/state keys during deserialization to reduce (but not eliminate) the risk of yaml.load() on untrusted input, and the CHANGES file documents a long history of CVE-driven hardening (safe-by-default behavior was added specifically in response to arbitrary-code-execution reports).

API Design The public API is deliberately minimal and mirrors Python’s own pickle/json module conventions (load/dump, safe_load/safe_dump), which makes onboarding nearly instant for any Python developer. The main ergonomic sharp edge — needing to pick a Loader class and understanding the safe-vs-unsafe distinction — is well documented in the README and is the single most important thing new users must learn; beyond that, extension points (registering custom constructors/representers for new tags) are straightforward subclassing patterns.

Used by 90 apps in this directory

Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

37,802

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
62
Repo Health
82
Technical
66
Dependency
Built with
Python 51%
TypeScript 36%
Updated 2 months ago
Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,755

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 6 days ago
Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,755

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 6 days ago
TypeScript
84%
Apache 2.0

ktx

AI Development · Analytics · Data Engineering

1,623

ktx builds a self-improving context layer over your data warehouse so AI agents like Claude Code and Codex query it with approved metric definitions instead of reinventing SQL logic from scratch.

View details
52
Repo Health
85
Technical
71
Dependency
Built with
TypeScript 84%
Updated 1 weeks ago
TypeScript
39%
Apache 2.0

Label Studio

AI Development · Data Engineering

28,540

Label Studio is an open-source, multi-type data labeling platform that lets teams annotate images, text, audio, video, and time series data with a configurable XML-based UI and export annotations in formats ready for any ML framework.

View details
93
Repo Health
87
Technical
64
Dependency
Built with
TypeScript 39%
JavaScript 27%
Python 25%
Updated 1 weeks ago
Python
71%
MIT

Langflow

AI Agents · AI Development

155,973

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
64
Dependency
Built with
Python 71%
TypeScript 21%
Updated 6 days ago
Python
53%
AGPL 3.0

LearnHouse

CMS · Learning Management

2,413

Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.

View details
90
Repo Health
77
Technical
65
Dependency
Built with
Python 53%
TypeScript 45%
Updated 6 days ago
Python
84%
MIT

LiteLLM

AI Development · Developer Tools

61,933

Open source AI gateway and Python SDK that gives you one OpenAI-compatible interface to call 100+ LLM providers, with built-in routing, cost tracking, guardrails, and virtual keys.

View details
93
Repo Health
81
Technical
69
Dependency
Built with
Python 84%
TypeScript 11%
Updated 6 days ago
TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,055

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
68
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 2 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers