All Projects → crdoconnor → Strictyaml

crdoconnor / Strictyaml

Licence: mit
Type-safe YAML parser and validator.

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Strictyaml

Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+121.89%)
Mutual labels:  config, configuration-management, schema, validation, configuration
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (-89.71%)
Mutual labels:  config, yaml, configuration, configuration-management
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (-9.21%)
Mutual labels:  config, yaml, parser, configuration
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-97.61%)
Mutual labels:  config, yaml, configuration, configuration-management
Dynaconf
Configuration Management for Python ⚙
Stars: ✭ 2,082 (+149.04%)
Mutual labels:  config, configuration-management, configuration, yaml
Simple-YAML
A Java API that provides an easy-to-use way to store data using the YAML format.
Stars: ✭ 68 (-91.87%)
Mutual labels:  yaml, serialization, configuration, yml
Zaml
The Final Form of configuration files
Stars: ✭ 45 (-94.62%)
Mutual labels:  yaml, schema, validation, configuration
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (-80.26%)
Mutual labels:  config, configuration-management, yaml, configuration
Koanf
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
Stars: ✭ 450 (-46.17%)
Mutual labels:  config, configuration-management, yaml, configuration
exenv
Exenv makes loading environment variables from external sources easy.
Stars: ✭ 35 (-95.81%)
Mutual labels:  config, yaml, yml
libconfini
Yet another INI parser
Stars: ✭ 106 (-87.32%)
Mutual labels:  config, configuration, configuration-management
dotfiles
My personal app/env configs and dotfiles.
Stars: ✭ 27 (-96.77%)
Mutual labels:  config, configuration, configuration-management
cfg-rs
A Configuration Library for Rust Applications
Stars: ✭ 18 (-97.85%)
Mutual labels:  config, yaml, configuration
superconfig
Access environment variables. Also includes presence validation, type coercion and default values.
Stars: ✭ 33 (-96.05%)
Mutual labels:  config, configuration, configuration-management
Marshmallow
A lightweight library for converting complex objects to and from simple Python datatypes.
Stars: ✭ 5,857 (+600.6%)
Mutual labels:  schema, validation, serialization
yaask
Make your yaml configurable with interactive configurations!
Stars: ✭ 15 (-98.21%)
Mutual labels:  config, yaml, configuration
sitri
Sitri - powerful settings & configs for python
Stars: ✭ 20 (-97.61%)
Mutual labels:  config, configuration, configuration-management
goodconf
Transparently load variables from environment or JSON/YAML file.
Stars: ✭ 80 (-90.43%)
Mutual labels:  config, yaml, configuration
Carvel Ytt
YAML templating tool that works on YAML structure instead of text
Stars: ✭ 816 (-2.39%)
Mutual labels:  yaml, yml, configuration
Hoplite
A boilerplate-free library for loading configuration files as data classes in Kotlin
Stars: ✭ 322 (-61.48%)
Mutual labels:  config, yaml, configuration

StrictYAML

StrictYAML is a type-safe YAML parser that parses and validates a restricted subset of the YAML specification.

Priorities:

  • Beautiful API
  • Refusing to parse the ugly, hard to read and insecure features of YAML like the Norway problem.
  • Strict validation of markup and straightforward type casting.
  • Clear, readable exceptions with code snippets and line numbers.
  • Acting as a near-drop in replacement for pyyaml, ruamel.yaml or poyo.
  • Ability to read in YAML, make changes and write it out again with comments preserved.
  • Not speed, currently.

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 OrderedDict:

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

Quickstart with schema:

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

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

42 is now parsed as an integer:

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

A YAMLError will be raised if there are syntactic problems, violations of your schema or use of disallowed YAML features:

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

For example, a schema violation:

try:
    person = load(yaml_snippet, schema)
except YAMLError as error:
    print(error)

while parsing a mapping
  in "<unicode string>", line 1, column 1:
    # All about the character
     ^ (line: 1)
required key(s) 'possessions' not found
  in "<unicode string>", line 3, column 1:
    age: '42'
    ^ (line: 3)

If parsed correctly:

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

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

You can modify values and write out the YAML with comments preserved:

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 look up line numbers:

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

And construct YAML documents from dicts or lists:

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

x: 1

Install

$ pip install strictyaml

Why StrictYAML?

There are a number of formats and approaches that can achieve more or less the same purpose as StrictYAML. I've tried to make it the best one. Below is a series of documented justifications:

Using StrictYAML

How to:

Compound validators:

Scalar validators:

Restrictions:

Design justifications

There are some design decisions in StrictYAML which are controversial and/or not obvious. Those are documented here:

Star Contributors

Contributors

Contributing

  • Before writing any code, please read the tutorial on contributing to hitchdev libraries.
  • Before writing any code, if you're proposing a new feature, please raise it on github. If it's an existing feature / bug, please comment and briefly describe how you're going to implement it.
  • All code needs to come accompanied with a story that exercises it or a modification to an existing story. This is used both to test the code and build the documentation.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].