Skip to main content

jps-yaml-schema-validator

Build Publish to PyPI codecov

A strict, rule-driven YAML validator that verifies configuration files against a YAML-defined schema — supporting rich type checking, required fields, filesystem validation, enumerations, regex constraints, numeric ranges, list validation, and complete aggregated error reporting.


🚀 Overview

jps-yaml-schema-validator enables configuration-driven applications to validate user-supplied YAML files using a declarative rules file (also YAML).

This library focuses on:

  • Strict validation (no silently ignored fields)
  • Rich semantic checks
  • Human-readable error messages
  • Aggregated error reporting (never fail fast)
  • CLI + Python API support

Ideal for pipelines, workflow engines (Nextflow/Snakemake), microservices, CLIs, or any software that consumes YAML config files.


✨ Features

Supported rule types

Rule Description
required: true Field must exist
type: string/int/float/bool Type enforcement
type: file File must exist, readable, and not empty
type: directory Must be an existing absolute directory
allowed: [...] Enumerations
regex: "pattern" Regex string validation
min_length, max_length String length constraints
min, max Numeric range checks
element_type, min_items List validation
allow_extra_keys Disable/enable acceptance of unknown keys

Additional capabilities

  • Aggregates all validation errors before failing
  • Validates the schema file itself
  • Robust error messages
  • Clear CLI interface
  • 100% deterministic behavior

📘 Example

rules.yaml

name:
  type: string
  required: true

threads:
  type: int
  required: true
  min: 1
  max: 64

input_file:
  type: file
  required: true

mode:
  type: string
  allowed:
    - fast
    - slow

config.yaml

name: "my job"
threads: 12
input_file: input.txt
mode: fast

Validate using CLI

jps-yaml-schema-validate validate \
    --schema rules.yaml \
    --config config.yaml

Output:

 Configuration is valid.

❌ Example validation failures

If the user config violates rules:

 Validation failed:
  - Missing required key: name
  - Field 'threads' must be >= 1
  - Field 'input_file' must be an existing file

🧨 CLI Usage

jps-yaml-schema-validate validate --schema rules.yaml --config config.yaml

Full help:

jps-yaml-schema-validate --help

🧵 Python API Usage

from jps_yaml_schema_validator import assert_valid_config

schema = {
    "name": {"type": "string", "required": True},
    "threads": {"type": "int", "min": 1, "max": 16},
}

config = {"name": "job1", "threads": 8}

assert_valid_config(schema=schema, config=config)

📦 Installation

From source

make install

From PyPI

pip install jps-yaml-schema-validator

🧪 Development

make fix && make format && make lint
make test

To run tests with coverage:

make test

📜 License

MIT License © Jaideep Sundaram

Download files

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

Source Distribution

jps_yaml_schema_validator-1.0.2.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jps_yaml_schema_validator-1.0.2-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file jps_yaml_schema_validator-1.0.2.tar.gz.

File metadata

File hashes

Hashes for jps_yaml_schema_validator-1.0.2.tar.gz
Algorithm Hash digest
SHA256 40b083ab9fac4c6ef58ecd6369d572746534af2e6f539c2bdad3b10bbab2e5e7
MD5 741794b5def6529bdcaaff6dff613484
BLAKE2b-256 b3f521c17b5fac19d74edf759b7f3dce590a5ec5750432c39ce21c15f1e427c3

See more details on using hashes here.

File details

Details for the file jps_yaml_schema_validator-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for jps_yaml_schema_validator-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c21d2a489d9923d505ac28b96512203ca308eaea81a4e00d76cdadc719d0289
MD5 bc5dd38a8b80535ea01831fa0fe1e799
BLAKE2b-256 0585da2ae32eb674f4121fec04e5d59f63d67c6d64285102a2d40cf69fa9ae89

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page