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
# Generate HTML documentation from a schema
python main.py --schema schema.yaml --generate-doc --output schema-doc.html
The repository also includes a Tkinter-based config editor:
python main_editor.py --schema schema.yaml --config config.yaml --strict true
For editor behavior and UI details, see docs/editor.md.
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 the full reference, including type behavior and the editor guide.
Examples In This Repo
Use matching schema/config pairs from examples/:
schema.yaml+config.yamlschema_composed.yaml+config_composed.yamlschema_all_types.yaml+config_all_types.yaml
Running tests
pytest
Status
Release files for ReadTheYAML 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| readtheyaml-3.0.0.tar.gz | 80.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| readtheyaml-3.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 197.0 kB
Release files / readtheyaml-3.0.0.tar.gz
| Download URL | readtheyaml-3.0.0.tar.gz |
|---|---|
| Size | 80.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b095dd91d40856a62682b8bb9f2ca607841c97fa8e2685b433969c3ef6d516da
|
|
BLAKE2b-256 checksum How to use checksums |
b5c884294676ec8a80146d0f4e80b17cd7b92d1d2a90899b3a87e082304df0a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 9, 2026.
Transparency logRelease files / readtheyaml-3.0.0-py3-none-any.whl
| Download URL | readtheyaml-3.0.0-py3-none-any.whl |
|---|---|
| Size | 116.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
013e13331a608825b4fd4f7b5230a8b0e6f55395da70e28ac84e231001d6cb87
|
|
BLAKE2b-256 checksum How to use checksums |
5d30dc310c731a57e177b019e8a23ef62a087c3b1fe08df7f69af0c28a1ad4b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 9, 2026.
Transparency log