A flexible validator that uses YAML rule files to validate user configuration files with type constraints and semantic checks.
Project description
jps-yaml-schema-validator
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jps_yaml_schema_validator-1.0.2.tar.gz.
File metadata
- Download URL: jps_yaml_schema_validator-1.0.2.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40b083ab9fac4c6ef58ecd6369d572746534af2e6f539c2bdad3b10bbab2e5e7
|
|
| MD5 |
741794b5def6529bdcaaff6dff613484
|
|
| BLAKE2b-256 |
b3f521c17b5fac19d74edf759b7f3dce590a5ec5750432c39ce21c15f1e427c3
|
File details
Details for the file jps_yaml_schema_validator-1.0.2-py3-none-any.whl.
File metadata
- Download URL: jps_yaml_schema_validator-1.0.2-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c21d2a489d9923d505ac28b96512203ca308eaea81a4e00d76cdadc719d0289
|
|
| MD5 |
bc5dd38a8b80535ea01831fa0fe1e799
|
|
| BLAKE2b-256 |
0585da2ae32eb674f4121fec04e5d59f63d67c6d64285102a2d40cf69fa9ae89
|