Validate and document your YAML config files — so future-you doesn't have to guess.
Project description
ReadTheYAML
ReadTheYAML validates YAML config files against a schema, injects defaults, and returns a validated config object.
Installation
pip install ReadTheYAML
Local development install:
git clone https://github.com/TheRealMarVin/ReadTheYAML.git
cd ReadTheYAML
pip install -e .
What it supports
- Required and optional fields
- Default values for optional fields
- Primitive and composite types
- Nested sections
- Conditional fields/sections with
when - Strict mode (reject unknown keys) and non-strict mode (pass through unknown keys)
- Schema composition with
$ref(local files and HTTP URLs)
Quick start
Schema (schema.yaml):
service_name:
type: str
description: service display name
port:
type: int
description: service port
required: false
default: 8080
min_value: 1
max_value: 65535
logging:
$ref: ./shared/logging.yaml
required: false
Config (config.yaml):
service_name: api-gateway
Python usage:
from readtheyaml.schema import Schema
schema = Schema.from_yaml("schema.yaml")
built, data_with_default = schema.validate_file("config.yaml", strict=True)
print(built) # validated/built config
print(data_with_default) # config with injected defaults
CLI usage
This repository currently exposes a CLI through main.py:
python main.py --schema schema.yaml --config config.yaml
Type syntax overview
Primitive types:
anyNoneboolintfloatstrenum(requiresvalues)
Composite types:
list[T]tuple[T1, T2, ...]union[A, B]orA | Bobject[package.module.ClassName](orobjectwith_type_in data)
Common field options:
descriptionrequireddefaultmin_value/max_value/value_rangemin_length/max_length/length_range
Conditions (when)
when exists so one schema can express conditional fields/sections without splitting into multiple schemas.
It gates validation and output inclusion based on other config values known at schema-validation time.
Practical example (compile_enabled toggles a compile section):
compile_enabled:
type: bool
required: false
default: false
compile:
required: false
when:
field: compile_enabled
op: eq
value: true
command:
type: str
description: Compile command
required: true
If compile_enabled is false, compile is skipped.
If compile_enabled is true, compile.command is validated and required.
Syntax reference:
- Atomic condition:
when: { field: some.path, op: eq, value: 123 }
- Logical combinators:
all: [...](AND)any: [...](OR)not: {...}(NOT)
Semantics:
- Active node (
whenis true):- validated normally
- included in
built - included in
data_with_default(with defaults applied as needed)
- Inactive node (
whenis false):- not validated
- omitted from
built - removed/omitted from
data_with_default
- If an optional subsection is missing and has no explicit section
default, it is omitted (not auto-materialized from child defaults). - If a subsection is inactive due to
when, payload under that subsection is ignored when evaluating otherwhenconditions.
Limitations / non-goals for this phase:
whendoes not inspect runtime Python objects or object internals.whendoes not evaluate arbitrary Python expressions from YAML.
Full reference (operators, aliases, combinators): docs/conditions.md
Notes
- Field names cannot use reserved constructor keywords.
- Optional fields usually require a valid
default. - HTTP
$refresolution importsrequestsat runtime.
Documentation
See docs/index.md for a full type reference and behavior notes.
Running tests
pytest
Status
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 readtheyaml-2.4.0.tar.gz.
File metadata
- Download URL: readtheyaml-2.4.0.tar.gz
- Upload date:
- Size: 47.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67e77667ba3f789a618676469c8df59c63677202820ff26563b15146b4bb3e9c
|
|
| MD5 |
6bdded4b1c03907f47e4ab7b91ac4609
|
|
| BLAKE2b-256 |
224fa81eac5bf8510610e460170a92f3779c1fcec71e7f99942cb9c743b5ed89
|
Provenance
The following attestation bundles were made for readtheyaml-2.4.0.tar.gz:
Publisher:
python-publish.yml on TheRealMarVin/ReadTheYaml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
readtheyaml-2.4.0.tar.gz -
Subject digest:
67e77667ba3f789a618676469c8df59c63677202820ff26563b15146b4bb3e9c - Sigstore transparency entry: 1415072243
- Sigstore integration time:
-
Permalink:
TheRealMarVin/ReadTheYaml@017fbdf7efaef60e291c90c089eb0d6d079de69c -
Branch / Tag:
refs/tags/2.4.0 - Owner: https://github.com/TheRealMarVin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@017fbdf7efaef60e291c90c089eb0d6d079de69c -
Trigger Event:
release
-
Statement type:
File details
Details for the file readtheyaml-2.4.0-py3-none-any.whl.
File metadata
- Download URL: readtheyaml-2.4.0-py3-none-any.whl
- Upload date:
- Size: 72.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d159c682e61cbd251c7d8ecbaded4114be06c44b522d7690cb5b349114166e9
|
|
| MD5 |
7529a17009ece5d2e3f260818dfc5b1a
|
|
| BLAKE2b-256 |
89a211686243a955bba0770fbc40080385233ea9143ed599e9fae4981604fdc0
|
Provenance
The following attestation bundles were made for readtheyaml-2.4.0-py3-none-any.whl:
Publisher:
python-publish.yml on TheRealMarVin/ReadTheYaml
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
readtheyaml-2.4.0-py3-none-any.whl -
Subject digest:
9d159c682e61cbd251c7d8ecbaded4114be06c44b522d7690cb5b349114166e9 - Sigstore transparency entry: 1415072392
- Sigstore integration time:
-
Permalink:
TheRealMarVin/ReadTheYaml@017fbdf7efaef60e291c90c089eb0d6d079de69c -
Branch / Tag:
refs/tags/2.4.0 - Owner: https://github.com/TheRealMarVin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@017fbdf7efaef60e291c90c089eb0d6d079de69c -
Trigger Event:
release
-
Statement type: