# PyYAML — card for AI agents

YAML parser and emitter for reading and writing YAML configuration files.

Category: Utilities · PyPI package `pyyaml` · latest version 6.0.3 (checked 2026-11-01)
Install: `pip install pyyaml`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## 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).

## What it is
- The website calls PyYAML "a full-featured YAML framework for the Python programming language." The canonical repository, github.com/yaml/pyyaml, was created on 2011-11-03 and is MIT licensed. The README says Kirill Simonov wrote the module. It is now maintained "by the YAML and Python communities."
- PyYAML can be installed with or without LibYAML bindings. By default, `python setup.py install` checks whether LibYAML is installed and builds the bindings only if it is. `--with-libyaml` forces the build and `--without-libyaml` skips it. Once the bindings are in place, you request the C backend explicitly: pass `Loader=yaml.CLoader` to `yaml.load` or `Dumper=yaml.CDumper` to `yaml.dump`. For input you don't trust, the README points to `yaml.safe_load(stream)`.
- The test suite runs in two modes: pure Python and LibYAML extension. The latest release, 6.0.3, adds support for Python 3.14 and experimental free-threading support.

## Caveats
- The fast path is opt-in twice: The bindings have to be built at install time. Even then, the README's examples request the C classes explicitly on each `load` and `dump` call.
- Free-threading support is experimental: Release 6.0.3 adds support for Python 3.14. Its free-threading support is marked experimental.
- Website and README list different chat channels: pyyaml.org lists development chat on `irc.freenode.net`. The README sends you to Matrix or `irc.libera.chat`. The website's news list ends at 2020-06-01.

## Numbers (AgentGid data)
- Gid Score: 75.9 (#180 of all tools, 12 of 408 in its category)
- Used in 371 public projects set up for AI coding agents (5.9%)
- Downloads last week: 321,621,561 (as of 2026-11-24), +20.0% over 4 weeks
- GitHub stars: 2,985 (as of 2026-11-24)
- Last push: 2026-11-20

## Often used with
Pydantic 49.3%, python-dotenv 44.7%, Requests 41.2%, Uvicorn 39.1%, FastAPI 36.1%, NumPy 34.8%

## Links
- AgentGid page: https://agentgid.com/tools/pyyaml/
- Homepage: https://pyyaml.org/
- Repository: https://github.com/yaml/pyyaml
- Source: https://github.com/yaml/pyyaml#readme
- Source: https://github.com/yaml/pyyaml
- Source: https://github.com/yaml/pyyaml/releases
- Source: https://pyyaml.org/


## PyYAML: read and write settings files in Python

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.

### Where to use 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: Markdown posts start with a short settings block (title, date, draft); a script flips draft to false before publishing. (idea, not from the official pages)

### How to start
- Install PyYAML into your project's Python environment. Note: the package is named PyYAML, but you import yaml.

```
pip install pyyaml
```

- Read 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.

### License
Free to use in any project, including paid and closed-source apps, under the MIT license. Keep its copyright and license notice if you ship its files.

### Good to know
- Plain yaml.load can run code hidden in a file. Use safe_load for anything from users, uploads or the internet.
- It follows an older version of the format, so on, off, yes, no and similar words turn into true or false.
- safe_load reads only the first part of a file split by --- lines. Use safe_load_all to get every part.
- The official tutorial is old: it still talks about version 5.1 and older Python. Current releases are the 6.0 line.
- Releases are rare. The latest, 6.0.3 from September 2025, mainly added support for Python 3.14.

Checked 2026-11-10 against: https://pyyaml.org/, https://pyyaml.org/wiki/PyYAMLDocumentation, https://github.com/yaml/pyyaml/blob/main/README.md, https://github.com/yaml/pyyaml/blob/main/LICENSE, https://github.com/yaml/pyyaml/blob/main/CHANGES, https://github.com/yaml/pyyaml/releases/tag/6.0.3, https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation, https://pypi.org/pypi/PyYAML/json

### Mistakes to avoid
- Don't: yaml.load(text) → Do: yaml.safe_load(text) (Since 6.0 load() without Loader= raises TypeError (our run), and load with the full loader is unsafe for untrusted input.)
- Don't: country: NO / debug: off / version: 1.10 left unquoted → Do: country: 'NO' / version: '1.10' in the file, or set the values as strings before safe_dump (Our run read NO and off as False and 1.10 as the number 1.1.)
- Don't: yaml.safe_dump(data) and expecting the original key order and non-English text as written → Do: yaml.safe_dump(data, sort_keys=False, allow_unicode=True) (In our run the defaults sorted keys alphabetically and wrote Cyrillic text as \u escape codes.)
- Don't: Load, change and save a hand-edited config with PyYAML → Do: Use ruamel.yaml for round trips where comments must survive (In our run the comment lines of config.yaml were gone after safe_dump.)
- Don't: pip install yaml → Do: pip install pyyaml (then import yaml) (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.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
