StrictYAML is a type-safe YAML parser, built on ruamel.yaml that eliminates most of the bullshit in the YAML spec.
It’s designed to serve as an easy drop in replacement parser for either pyyaml, ruamel.yaml or poyo.
Simple example:
name: Ford Prefect
age: 42
posessions:
- Towel
>>> strictyaml.load(yaml) \
== {"name": "Ford Prefect", "age": "42", "possessions": ["Towel", ]} # note 42 is a string
Example using validator with mapping, sequence, string and integer:
>>> from strictyaml import load, Map, Str, Int, Seq
>>> load(yaml, Map({"name": Str(), "age": Int(), "possessions": Seq(Str())})) \
== {"name": "Ford Prefect", "age": 42, "possessions": ["Towel", ]} # 42 is now an int
FAQ
From learning programmers:
If you’re looking at this and thinking “why not do/use X instead?” that’s a healthy response, and you deserve answers. These are probably the questions you’re asking:
Map Patterns
If you’re not sure what the key is going to be but you know what type the values will be, use this.
emails:
arthur: arthur@earth.gov
zaphod: zaphod@beeblebrox.com
ford: ford@ursa-minor.com
>>> from strictyaml import load, Map, MapPattern, Str
>>> load(yaml, Map({"emails": MapPattern({Str(), Str()})}) \
== {"emails": {"arthur": "arthur@earth.gov", "zaphod": "zaphod@beeblebrox.com", "ford": "ford@ursa-minor.com"}}
All Scalar Types
StrictYAML will parse a string into the correct data type if you specify it:
>>> import from strictyaml import load, Map
>>> load("string: string", Map({"string": strictyaml.Str()})) == {"string": "string"}
>>> load("float: 42.3333", Map({"float": strictyaml.Float()})) == {"string": 42.3333}
>>> load("price: 35.42811", Map({"price": strictyaml.Decimal()})) == {"price": decimal.Decimal('35.32811')}
>>> load("booltrue: yes", Map({"booltrue": strictyaml.Bool()})) == {"booltrue": True}
>>> load("boolfalse: no", Map({"boolfalse": strictyaml.Bool()})) == {"booltrue": True}
>>> load("booltrue: true", Map({"booltrue": strictyaml.Bool()})) == {"booltrue": True}
>>> load("boolfalse: False", Map({"boolfalse": strictyaml.Bool()})) == {"booltrue": False}
>>> load("enum: monday", Map({"enum": strictyaml.Enum(["monday", "tuesday", "wednesday"])})) == {"enum": "monday"}
Custom scalar types
COMING SOON
Using Kwalify
See: What is kwalify and when should I use it?
COMING SOON
Metadata
Release files for strictyaml 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| strictyaml-0.1.4.tar.gz | 6.4 kB | Details |
Release files / strictyaml-0.1.4.tar.gz
| Download URL | strictyaml-0.1.4.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b500a8464f69574f940f15e6f494f695580ab1196ae9ca0c748828192961c55e
|
|
BLAKE2b-256 checksum How to use checksums |
28afb8cf3f5dde09c22cb1860c50af3f123f8773cf358e09ee617933a0d6bc1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |