Parsing strings (Str)

StrictYAML parses to a YAML object, not the value directly to give you more flexibility and control over what you can do with the YAML.

This is what that can object can do - in most cases if parsed as a string, it will behave in the same way.

Example yaml_snippet:

a: 1
b: yes
c: â string
d: |
  multiline string
from strictyaml import Str, Map, load
from ensure import Ensure

schema = Map({"a": Str(), "b": Str(), "c": Str(), "d": Str()})

parsed = load(yaml_snippet, schema)

Parses correctly:

    {"a": "1", "b": "yes", "c": u"â string", "d": "multiline string\n"}

Dict lookup cast to string:


Dict lookup cast to int:


Dict lookup cast to bool impossible:

Cannot cast 'YAML(1)' to bool.
Use bool( or bool(yamlobj.text) instead.

Executable specification

Documentation automatically generated from scalar-string.story storytests.