1. License
“to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software”
MIT allows use in paid and closed-source products.
github.com/yaml/pyyaml/blob/main/LICENSE3. Used by agents' projects
Dependency in 371 public GitHub projects set up for AI coding agents that we scanned (5.9%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily; card checked Nov 10, 2026. Tap a verdict to see its source.How we checkedReport an error
What PyYAML does
PyYAML is a free Python library that reads and writes YAML, the plain-text format many settings files use. Your app turns such a file into ordinary Python data and can save data back the same way. It does not keep comments when it rewrites a file, and it reads a few words like "no" and "off" as false.
What people build with it
Read your app's settings file
Shop name, languages and limits live in one readable file; your app loads them at start instead of hard-coding them.
Save data as a readable file
Your app writes its settings or an export so a person can open and edit it in any text editor.
Open files people upload
Users upload a settings or data file; your app reads only plain data from it and never runs code hidden inside.
Read multi-part deployment files
One file holds several blocks split by --- lines, as server setup files often do; your script reads each block in turn.
Edit blog post headers Idea
Markdown posts start with a short settings block (title, date, draft); a script flips draft to false before publishing.
PyYAML popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How PyYAML is used
- PyYAML is a dependency in 371 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (22.9% of the 1,623 Python ones), #3 of 408 in utilities.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 2,578; those are left out of every share on this page.
- Projects that use it most often also use Pydantic (49.3%), python-dotenv (44.7%), Requests (41.2%).
- It is more common in projects set up for OpenClaw (12.9%) than for OpenAI Codex (4.7%).
By coding agent
Often used with
PyYAML in practice
Strengths
With the LibYAML bindings installed, you switch backends per call: <code>Loader=yaml.CLoader</code> for loading, <code>Dumper=yaml.CDumper</code> for dumping. The README calls these the "fast LibYAML-based parser and emitter".
Pass no flag and <code>setup.py</code> builds the bindings only if it finds LibYAML. <code>--with-libyaml</code> skips the check and forces the build. <code>--without-libyaml</code> skips the check and the build.
<code>make test</code> runs the pure Python tests, builds a local LibYAML, then runs the extension tests. The local LibYAML build is pinned by <code>LIBYAML-REF</code>, which defaults to <code>0.2.5</code>. <code>make test-python</code> and <code>make test-libyaml</code> run one mode each.
The website's news list covers PyYAML, LibYAML and PySyck. Its PyYAML entries start with 3.01 on 2006-05-07. It records Python 3 support arriving in 3.08, released on 2008-12-31.
Watch out for
The bindings have to be built at install time. Even then, the README's examples request the C classes explicitly on each <code>load</code> and <code>dump</code> call.
Release 6.0.3 adds support for Python 3.14. Its free-threading support is marked experimental.
pyyaml.org lists development chat on <code>irc.freenode.net</code>. The README sends you to Matrix or <code>irc.libera.chat</code>. The website's news list ends at 2020-06-01.
C loader and dumper, and loading untrusted input
>>> yaml.load(stream, Loader=yaml.CLoader)
>>> yaml.dump(data, Dumper=yaml.CDumper)
>>> yaml.safe_load(stream)More about PyYAML
Packages around it
- pydantic: Data validation
- python-dotenv: .env file loading
- requests: HTTP client
- numpy: Numeric arrays
- uvicorn: ASGI server
- fastapi: Web API framework
Alternatives
PyYAML This page
Pick ruamel.yaml when you edit files people maintain by hand; it keeps comments, key order and formatting on a round trip.
Pick js-yaml when the code that reads the file is JavaScript or Node.js rather than Python.
Pick the yaml package for JavaScript when you need full spec compliance and to keep comments in JavaScript code.
Get started
Tell your AI assistant
“Use the Python library PyYAML (pin pyyaml==6.0.3, import yaml) to read config.yaml with yaml.safe_load, quote values like NO, off and 1.10 that must stay text, and write changes with yaml.safe_dump(sort_keys=False, allow_unicode=True).”
Install PyYAML into your project's Python environment. Note: the package is named PyYAML, but you import yaml.
pip install pyyamlRead files you did not write yourself with safe_load, never plain load.
yaml.safe_load(stream)Write data back with safe_dump; pass sort_keys=False to keep your key order.
Rules for your agent
## PyYAML
- For any YAML stream you don't trust, use `yaml.safe_load(stream)`, as the README instructs.
- Only pass `Loader=yaml.CLoader` / `Dumper=yaml.CDumper` when the LibYAML bindings are installed.
- To control the C build from source, use `python setup.py --with-libyaml install` (force) or `python setup.py --without-libyaml install` (skip).
- When changing PyYAML itself, run `make test` to cover both backends. Use `make test-python` or `make test-libyaml` for one mode.
- To test against a specific interpreter, set it explicitly, e.g. `make test PYTHON-VERSION=3.13.5`.
- Treat free-threading support on Python 3.14 as experimental (added in 6.0.3).
Mistakes to avoid
Since 6.0 load() without Loader= raises TypeError (our run), and load with the full loader is unsafe for untrusted input.
Our run read NO and off as False and 1.10 as the number 1.1.
In our run the defaults sorted keys alphabetically and wrote Cyrillic text as \u escape codes.
In our run the comment lines of config.yaml were gone after safe_dump.
The package on PyPI is PyYAML; the import name is yaml.
Questions
Can I use it in a paid, closed-source app?
Yes. It is MIT-licensed; keep the copyright and license notice with its files.
Why does yaml.load(text) fail with "missing 1 required positional argument: 'Loader'"?
Since version 6.0 load needs a Loader. Use yaml.safe_load(text) instead (our run showed this TypeError).
Is FullLoader or full_load safe for untrusted files?
The project's own page says to avoid it for untrusted data; use safe_load.
Why did my value "NO" become False?
PyYAML reads on, off, yes, no and similar words as true or false. Put such values in quotes in the file.
Is there a faster mode?
Yes. When the LibYAML C parser is present, CLoader and CDumper are much faster; the PyPI wheels in our run had it built in.