Skip to main content

StrictYAML is a type-safe YAML parser, eliminating surprise bugs caused by implicit typing.

For example:

- Don Corleone: Do you have faith in my judgment?
- Clemenza: Yes
- Don Corleone: Do I have your loyalty?

Parse output of pyyaml and ruamel.yaml:

>>> from ruamel.yaml import load
>>> load(the_godfather)
[{'Don Corleone': 'Do you have faith in my judgement?'},
 {'Clemenza': True},
 {'Don Corleone': 'Do I have your loyalty?'},]

Wait, Clemenza said what??

Parse output of StrictYAML:

>>> from strictyaml import load, List, MapPattern, Str
>>> load(the_godfather, List(MapPattern({Str(), Str()})))
[{'Don Corleone': 'Do you have faith in my judgement?'},
 {'Clemenza': 'Yes'},
 {'Don Corleone': 'Do I have your loyalty?'},]

Why use StrictYAML?

YAML is an excellent metalanguage to describe most kinds of configuration as well as for creating simple DSLs.

It is terse and devoid of noisy syntax (unlike JSON), able to clearly represent hierarchical data (unlike INI) and most important of all, it’s not the product of a crazed committee of monkeys hammering away on typewriters (XML).

YAML has weaknesses, however, which StrictYAML addresses:

  • Implicitly typed (StrictYAML fixes this with explicit typing).

  • Allows arbitrary binary data leading to, among other things, Ruby on Rails’ spectacular security fail (disallowed in StrictYAML because why on earth did anybody think this was a good idea?).

  • Tag tokens, allowing you to specify types in the YAML (disallowed in StrictYAML).

  • Confusing “flow” style (disallowed by default in StrictYAML).

  • Often confusing node anchors and references (disallowed by default in StrictYAML).

Using StrictYAML

Map pattern in YAML can be translated to dicts:

>>> from strictyaml import load, MapPattern, Str, Int
>>> load("a: 1\nb: 2", MapPattern(Str(), Int()))
{'a': 1, 'b': 2}

Restricted, specified maps can also be translated to dicts:

>>> from strictyaml import load, Map, Bool
>>> load("a: yes\nb: no", Map({"a": Bool(), "b": Bool()}))
{'a': True, 'b': False}

Validators can be nested and lists can be restricted to a single type:

>>> from strictyaml import load, Map, Seq, Float
>>> list_float_typed_yaml = """
... a:
...   - 1.5
...   - 2.5
... b:
...   - 2
...   - -3.14e5
... """
>>> load(list_float_typed_yaml, Map({"a": Seq(Float()), "b": Seq(Float())}))
{'b': [2.0, -314000.0], 'a': [1.5, 2.5]}

Types can be mixed and matched:

>>> from strictyaml import load, Map, Bool, Str, Decimal
>>> product_yaml = """
... Name: Tea
... Price: 3.55
... Available: Yes
... """
>>> load(product_yaml, Map({"Name": Str(), "Price": Decimal(), "Available": Bool()}))
{'Available': True, 'Name': 'Tea', 'Price': Decimal('3.55')}

You can also use enums:

>>> from strictyaml import load, Map, Str, Enum
>>> product_yaml = """
... Name: Tea
... Type: Green
... """
>>> load(product_yaml, Map({"Name": Str(), "Type": Enum(["Green", "Mint"])}))
{'Name': 'Tea', 'Type': 'Green'}

Metadata

Release files for strictyaml 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for strictyaml 0.1.2
File Size Uploaded
strictyaml-0.1.2.tar.gz 6.0 kB Details

Release files / strictyaml-0.1.2.tar.gz

Download URL strictyaml-0.1.2.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
080b7d95f81ce2555b5a99840374236a6bfb213c1393e6e8200e2882c4d8aa59
BLAKE2b-256 checksum
How to use checksums
5f0720fdf80de14f477d5588d9a086a63d6f721810e94aa141c0ddf7b87b5bdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.7.3

2 release files

1.7.0

1 release file

1.6.2

1 release file

1.6.1

1 release file

1.6.0

1 release file

1.5.0

1 release file

1.4.4

1 release file

1.4.2

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.15.4

1 release file

0.15.3

1 release file

0.15.2

1 release file

0.15.1

1 release file

0.15.0

1 release file

0.14.1

1 release file

0.13.0

1 release file

0.12.0

1 release file

0.11.9

1 release file

0.11.8

1 release file

0.11.7

1 release file

0.11.6

1 release file

0.11.5

1 release file

0.11.4

1 release file

0.11.3

1 release file

0.11.2

1 release file

0.11.1

1 release file

0.11.0

1 release file

0.10.0

1 release file

0.9.0

1 release file

0.8.0

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.9

1 release file

0.5.8

1 release file

0.5.7

1 release file

0.5.6

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

This release

0.1.2 This release

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page