PyYaml (GitHub) is a complete YAML 1.1 parser and emitter, providing both a low-level event-based API (like SAX) and a high-level API for serializaing and deserializing native Python objects. It supports all types from the YAML types repository, has an extension API for additional types, and can construct arbitrary Python objects (which is not safe unless you trust what you're loading). It's written in pure Python, but can also use the LibYAML C library if installed.
Versions:
- The commonly used release is 3.12, the latest on PyPI.
- 3.13 (currently at 3.13b1) is required for Python 3.7. It has no functionality changes from 3.12.
- A 4.1 release was attempted in 2018-06 but then retracted; 4.2 will be released once the issues causing that have been fixed.
The only documentation seems to be the PyYAML Documentation page on the old Wiki, though it claims to be historical.
Functions in yaml
module:
load(stream)
, Parses first document in a stream, throwingComposerError
if there is more than one document.load_all(stream)
: Parses all documents in a stream.safe_load(stream)
,safe_load_all()
: As withload()
but parses only basic YAML.dump(data, stream=None)
,dump_all
,safe_dump
,safe_dump_all
: Returns anstr
or writes the dumped data to the given stream. Parameters include:explicit_start
width
indent
canonical
: defaultFalse
default_flow_style
: defaultTrue