talira

YAML parser and emitter for Python

open sourceMITfree

PyYAML is a Python library for reading and writing YAML. It loads YAML documents into Python objects and dumps Python objects back to YAML, in pure Python or, when LibYAML is installed, through its faster C parser and emitter (CLoader, CDumper). yaml.safe_load loads only plain types such as strings, numbers, lists and dictionaries, and is the call to use for input you don't trust: yaml.load with the full loader can construct arbitrary Python objects.

Problems it solves

  • read a YAML config file in Python
  • write a Python dictionary out as YAML
  • parse YAML from users without letting it run code

Features

  • read and write YAML files in Python
  • safe loading of untrusted YAML with safe_load
  • optional fast C parser and emitter through LibYAML
  • custom tags mapped to Python classes

Limitations

  • yaml.load with the full or unsafe loader can run arbitrary Python code from a crafted document; only yaml.safe_load is safe for untrusted input.1

Alternatives

The same job

These do what PyYAML does.

  1. ruamel.yaml A YAML 1.2 loader and dumper for Python that round-trips comments and formatting

Compare PyYAML with the top 3