Skip to main content

StrictYAML

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.3

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.3
File Size Uploaded Provenance Actions
strictyaml-0.1.3.tar.gz 6.0 kB Without provenance Details for strictyaml-0.1.3.tar.gz

Release files / strictyaml-0.1.3.tar.gz

Download URL strictyaml-0.1.3.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9a205f4611e8c44715d5c7395473211d36d2e9af16023162ca700a6eefa3fcf9
BLAKE2b-256 checksum
How to use checksums
7e9d102d744532d26583043dd84b819e88af69e1580aadaac4ca526a25cbfd90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for strictyaml 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.3 This release

1 release file No provenance

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