Skip to main content

Yamlator is a CLI tool that allows a YAML file to be validated using a lightweight schema language

Project description

Yamlator

Test codecov License PyPi Version

Yamlator is a CLI tool that allows a YAML file to be validated using a lightweight schema that defines the expected structure. When executed, the YAML is compared against the rules to validate that the relevant keys and data types are present. Once validated, a list of violations will be displayed to help amend the YAML file.

Installing the package

The Yamlator package can be installed from PyPi with:

pip install yamlator

A basic example

Schemas in Yamlator are comprised of rules, rulesets and enums, which are defined in a Yamlator schema file with the .ys extension.

In the Yamlator schema file, the entry point is defined in a schema block. As a minimum, a schema block must be defined for Yamlator to validate a file. Complex structures can be defined as rulesets to validate nested structures. For example, the following schema can be defined to manage a list of employees:

ruleset Employee {
    firstName str
    lastName str
    roles list(str) optional
}

schema {
    employees list(Employee)
}

This schema can then be used to validate the following YAML data:

employees:
    - firstName: employee
      lastName: one
      roles:
        - manager
    - firstName: employee
      lastName: two
      roles:
        - engineer
        - manager
    - firstName: employee
      lastName: three

More information on the different components that can be used in a schema can be found in the schema components documentation.

Additional examples of Yamlator schemas can be found in the examples directory

How to run the CLI

Assuming you have a YAML and Yamlator schema file, the CLI can be executed with:

yamlator <path-to-yaml-file> -s <path-to-yamlator-schema>

Where <path-to-yaml-file> is replaced with the path to your YAML file and <path-to-yamlator-schema> is the path to the schema file which must have the .ys extension.

The first argument for the CLI is always the path to the YAML file.

Flag Alias Description Is Required
--schema -s The schema that will be used to validate the YAML file True
--output -o Defines the violations format that will be displayed. Supported values are table, yaml or json. Defaults to table if not specified. False

To see the help options for the CLI, run yamlator -h or yamlator --help

Setting up the development environment

For instructions on how to set up the development environment, read the setting up the environment documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yamlator-0.4.1.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

yamlator-0.4.1-py3-none-any.whl (40.1 kB view details)

Uploaded Python 3

File details

Details for the file yamlator-0.4.1.tar.gz.

File metadata

  • Download URL: yamlator-0.4.1.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for yamlator-0.4.1.tar.gz
Algorithm Hash digest
SHA256 d50072914d4e78ee88d0050a62832ed81dd39f35463da55400c9629e9b570b2b
MD5 c746d21331105471618149a2cce19529
BLAKE2b-256 a200720eb58ba029bb68738a22c9967a5a9ca17c09e6cf04cc3592af77aa0439

See more details on using hashes here.

File details

Details for the file yamlator-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: yamlator-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 40.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for yamlator-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7c10fdf8c381f57b4d603f53fb63a5250daa5ddbc53c9ef475411256a6e8e1c
MD5 9aa428a0f557073d60fbee44eebda77e
BLAKE2b-256 29f058742064cceccc2f884beddcd6f2ae4890736c38cf6bac8732787520848f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page