Software & Apps

Strictly – hitchdeb

Stars in Github Repo
Pypi - Downloads

The streakoaml is a Type-Safe Yaml parser partics and verifies a Topped Subset on Yaml
detail.

Presidents:

  • Great API
  • PARSE RECALL the evil, hard to read and unsure parts of yaml like Norway problem.
  • Strictly validating the mark and straightforward type type.
  • Clearly, readable exceptions Code snippets and Numbers in line.
  • Act as a near-drop replacement for pyyaml, ramelel.yaml or poyo.
  • The ability to read Yamitl, make changes and write them again with comments to be preserved.
  • Nonperanttoday.

Simple Example:

# All about the character
name: Ford Prefect
age: 42
possessions:
- Towel
from strictyaml import load, Map, Str, Int, Seq, YAMLError

Default parse result:

>>> load(yaml_snippet)
YAML({'name': 'Ford Prefect', 'age': '42', 'possessions': ('Towel')})

All data is string, list or order:

>>> load(yaml_snippet).data
{'name': 'Ford Prefect', 'age': '42', 'possessions': ('Towel')}

CONTACT SCHMA TEST:

from strictyaml import load, Map, Str, Int, Seq, YAMLError

schema = Map({"name": Str(), "age": Int(), "possessions": Seq(Str())})

42 is now parked as an integer:

>>> person = load(yaml_snippet, schema)
>>> person.data
{'name': 'Ford Prefect', 'age': 42, 'possessions': ('Towel')}

A yamerror will be exalted if there are syntactic problems, breaking your schema or using unexpected yaml parts:

# All about the character
name: Ford Prefect
age: 42

For example, a violation of the schema:

try:
    person = load(yaml_snippet, schema)
except YAMLError as error:
    print(error)
while parsing a mapping
  in "", line 1, column 1:
    # All about the character
     ^ (line: 1)
required key(s) 'possessions' not found
  in "", line 3, column 1:
    age: '42'
    ^ (line: 3)

If connected correctly:

from strictyaml import load, Map, Str, Int, Seq, YAMLError, as_document

schema = Map({"name": Str(), "age": Int(), "possessions": Seq(Str())})

You can change values ​​and write YAML to keep comments:

person = load(yaml_snippet, schema)
person('age') = 43
print(person.as_yaml())
# All about the character
name: Ford Prefect
age: 43
possessions:
- Towel

As well as viewing numbers in line:

>>> person = load(yaml_snippet, schema)
>>> person('possessions')(0).start_line
5

And build YAML documents from dictates or lists:

print(as_document({"x": 1}).as_yaml())

Apply

Why is strictyaml?

There are a number of formats and procedures to achieve more or less equal intent as structure. I tried to make it the best. Below is a series of documented justifications:

Using tight woman

How:

COMPOUND TALES:

Scalar tales:

Restrictions:

Design Muscles

There are some decisions in the design of the tight woman controversial and / or unclear. It was written here:

Star contributions

  • @wwoods
  • @ChrisBurr
  • @ jnichols0

Other givers

  • @euliores
  • @Waltwoods
  • @Christophergs
  • @gvx
  • @Alexandrecan
  • @ lots0logs
  • @Tobbez
  • @jaredampson
  • @Boobotig

Stringtoaml also includes code from ramel.yamlCopyright Anthon van der Neut.

causes

  • Before writing any code, please read the tutorial to Contributing to Hitchdeb libraries.
  • Before writing any code, if you suggest a new feature, please lift it to GitHub. If it has one side / bug, please mention and describe briefly how you can implement it.
  • All code should come accompanied by a story that used it or a change to a stories. It used both to try the code and build the documentation.

2025-03-07 12:45:00

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button