This is a code kata that implements a subset of the yaml spec. It is NOT intended to be used by anyone. It's just a way for me to deliberately practice my software engineering skills (design in particular)
You can demo the code here
To use myaml, clone this repo, then do.
cd src/
pip install .
create a yaml file called blah.yaml
that has some yaml in it.
Then do this
import myaml
with open('blah.yaml') as file:
blah = myaml.load(file.read())
Myaml support three types.
- Mappings
- Sequences
- Scalars
Scalars represent strings (they could also represent other primitive types but only strings are supported at the moment)
Mappings and Sequences are the collection types. They are recursive structures i.e they can contain other mappings and sequences.
Mappings correspond to dictionaries and can be nested. The key has to be a scalar and the value can be a scalar like in the example below
key: value
or the value can be a mapping that is indented one level more than the key
key:
key2: value
key3: value
or the value can be a sequence that is indented one level more than the key
key:
- value
- valu3
or look like this example, that has keys with values of different types
key:
key: value
key2:
- value
key3: value
Sequences corresponds to arrays.
An item in a sequence is denoted by a -
where the length of this should be equal to the indentSize(number of spaces that make up an indent).
Here are some examples
- value
- value3
or
- key: value
- key:
key3: value
- value