yamlite is simple limited YAML parser, designed for
minimalistic human friendly YAML subsets. It is a single
file that you can copy into your own project without any
Human-friendly YAML subset
It is a text format that you can understand without raising (too much) questions, and which is valid YAML at the same time. For example:
package: yamlite decription: parser for human-friendly YAML subset version: 2.0
Parser evolves over time. Things that are already parsed can be seen in dataset directory.
To see how
yamlite parses your file, use:
python -m yamlite your.yaml
For command line usage just run it as a module:
python -m yamlite your.yaml
The easiest way is to use API is to copy
into your project path and import from there.
import yamlite config = None with open('config.yaml', 'rb') as yf: config = yamlite.parse(yf.read()) print(config)
Limitations <a name="limited"></a>
yamlite doesn't do any type autoconversion. All
returned values are strings. For example, the version
field in the following example:
package: yamlite version: 1.2
It will still be string '1.2' after parsing. If you load the same data with PyYAML, it will be float.
yamlite may include helper to convert
types of known fields, but still probably return
values as strings by default. For simplicity.
Data driven development
Development is data based. First a new example is
dataset/ directory with a name like
01.in.yaml, which contains data that should be
01.out.txt in the same dir contains output
yamlite. There can be other files,
04.out.pyyaml.txt that contain output from
other tools when it differs.
The goal for version 1.0 is to parse the following examples:
app.yaml from GAE https://developers.google.com/appengine/docs/python/config/appconfig
ansible configs http://www.ansibleworks.com/docs/YAMLSyntax.html
Data-driven develompent means that if your example of
YAML syntax is not added to dataset, there is no
yamlite supports it even if current
version parses it correctly.
Enhance and experiment
Get latest version:
hg clone https://bitbucket.org/techtonik/yamlite
Make sure current
Generate reports to compare output with PyYAML:
Add new sample to dataset/, rerun above commands to
test it and modify
yamlite if necessary.
Feel free to apply either public domain or MIT license to this code, which means "attribution is appreciated, but not required".
https://pypi.python.org/pypi/PyYAML - complete YAML 1.1 parser by Kirill Simonov
https://wiki.python.org/moin/YAML - Python wiki page about YAML
https://bitbucket.org/techtonik/yamlite - yamlite development
compatibility report in html format
- frames for parser state
- --trace argument dumps parser state to files
- top level list
- key-value with string starting on the next line
- key-value with list
- proof-of-concept parser for sequence of key-value pairs
- complete dataset/ + framework scaffolding for easy data driven development