Overview

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 packaging cruft.

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

Usage

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 yamlite.py 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.

In future, 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 added into dataset/ directory with a name like 01.in.yaml, which contains data that should be parsed. 01.out.txt in the same dir contains output expected from yamlite. There can be other files, such as 04.out.pyyaml.txt that contain output from other tools when it differs.

Status

The goal for version 1.0 is to parse the following examples:

Guarantess

Data-driven develompent means that if your example of YAML syntax is not added to dataset, there is no guarantee that 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 yamlite works:

yamlite --test

Generate reports to compare output with PyYAML:

dataset/update.py

Add new sample to dataset/, rerun above commands to test it and modify yamlite if necessary.

License

Feel free to apply either public domain or MIT license to this code, which means "attribution is appreciated, but not required".

Links

Changes

0.3 (TBD)

  • single string

  • compatibility report in html format

  • frames for parser state
  • --trace argument dumps parser state to files

0.2 (2013-12-10)

  • top level list
  • key-value with string starting on the next line
  • key-value with list

0.1 (2013-11-25)

  • proof-of-concept parser for sequence of key-value pairs
  • complete dataset/ + framework scaffolding for easy data driven development