Validate and document your YAML config files — so future-you doesn't have to guess.
Project description
ReadTheYaml
A lightweight YAML schema validator with just enough structure to stop future-you from asking: "Why the heck did I set this to 42?"
What is this?
ReadTheYaml is a Python library that helps you define, validate, and document your YAML configuration files. It was built by someone (me) who got tired of forgetting:
- Which config values were required vs optional
- Why a given field was there in the first place
- What values are valid
It enforces structure in your YAML and documents everything along the way.
There might be more mature alternatives out there (really!), but this one's small, readable, and purpose-built for when you're tired of guessing your own project settings.
📦 Installation
pip install ReadTheYaml
Alternatively, clone the repo and install locally:
git clone https://github.com/TheRealMarVin/ReadTheYaml.git
cd ReadTheYaml
pip install -e .
What can it do?
🔹 Validate YAML config files
It ensures all required fields are present, types are correct, and defaults are filled in where needed.
🔹 Support optional and required fields with descriptions
So future-you (or teammates) know what a setting is for.
🔹 Provide default values
Optional fields can define a default that will be added if missing.
🔹 Define valid numeric or length ranges
So you don’t accidentally open port 99999 or supply an empty list.
🔹 Support list validation
You can define list(int), list(str), or even list(nested(...)) to validate list content with precision.
🔹 Define enum fields
You can restrict values to a fixed set of strings using EnumField or type: enum.
🔹 Modular design with $ref
Schemas can include and reuse other schemas stored in separate files.
Supported Schema Types
ReadTheYAML provides a flexible and expressive way to define and validate data structures using YAML. Below is an overview of the supported types, their syntax, and usage examples. I tried to follow the standard of type hints in Python, but I relaxed some constraints.
🔹 Basic Types
None: Represents None.int: Represents integer values.float: Represents floating-point numbers.str: Represents string values.bool: Represents boolean values (trueorfalse).
Example:
type: int
🔹 Composite Types
List
Defines a list of elements of a specified type.
Syntax:
type: list[<element_type>]
Example:
type: list[int]
Tuple
Defines a fixed-size sequence of elements, each with a specified type.
Syntax:
type: tuple[<type1>, <type2>, ...]
Example:
type: tuple[int, str]
Union
Specifies that a value can be of one of several types.
Syntax:
type: union[<type1>, <type2>, ...]
Example:
type: union[int, str]
🔹 Optional Types
To indicate that a field is optional (i.e., it can be null), include None in a union.
Example:
type: union[int, None]
Alternatively, you can use the shorthand:
type: int | None
🔹 Syntax Variations
ReadTheYAML supports both square brackets [] and parentheses () for defining composite types. However, the opening and closing brackets must match.
Valid:
type: tuple[int, str]
type: tuple(int, str)
Invalid:
type: tuple[int, str)
type: tuple(int, str]
🔹 Nested Types
You can nest composite types to define complex structures.
Example:
type: list[tuple[int, str]]
This defines a list where each element is a tuple containing an integer and a string.
🔹 Field Options
Fields can have additional options to control validation and behavior:
description: Provides a human-readable description of the field. This one is mandatoryrequired: Indicates whether the field is mandatory. By default, the value is false (the field is not required).default: Specifies a default value if the field is omitted. This is mandatory when required is set to false.
Example:
name:
type: str
required: true
default: Unnamed
description: The name of the entity.
Example schema.yaml
name: app_config
status:
type: enum
enum: [pending, approved, rejected]
required: true
retries:
type: int
default: 3
min_value: 0
max_value: 10
servers:
type: list(nested(Server))
length_range: [1, 5]
tags:
type: list(str)
min_length: 1
Server:
host:
type: str
required: true
port:
type: int
default: 8080
min_value: 1
max_value: 65535
How to Use
1. Validate a file with CLI
python -m ReadTheYaml.cli --schema schema.yaml --config config.yaml
You’ll see:
✅ Config is valid!
Or, if something’s off:
❌ Validation failed: [status] must be one of: pending, approved, rejected
2. Programmatic usage
from readtheyaml.schema import Schema
try:
schema = Schema.from_yaml("schema.yaml")
validated_config = schema.validate_file("config.yaml")
print(validated_config)
except Exception as e:
print(f"⚠️ Failed to load or validate config: {e}")
Contributions
If you try this out and find something confusing or missing — feel free to open an issue or suggestion. This project is a work-in-progress, but built with love and frustration.
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.2.0.tar.gz.
File metadata
- Download URL: readtheyaml-2.2.0.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c7df3d5544fb57bcc159d963c16518152d426c265dabae489cf29e36287c292
|
|
| MD5 |
25d75ece82db9772b4501840e732b417
|
|
| BLAKE2b-256 |
97dba68c7c96f4743cb73dd8b61696d717dc0088c566a6c875a8c36f06e06328
|
Provenance
The following attestation bundles were made for readtheyaml-2.2.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.2.0.tar.gz -
Subject digest:
3c7df3d5544fb57bcc159d963c16518152d426c265dabae489cf29e36287c292 - Sigstore transparency entry: 928462725
- Sigstore integration time:
-
Permalink:
TheRealMarVin/ReadTheYaml@dc6fb14c02f76647e0ae489348e63772189adfd7 -
Branch / Tag:
refs/tags/2.2 - Owner: https://github.com/TheRealMarVin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@dc6fb14c02f76647e0ae489348e63772189adfd7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file readtheyaml-2.2.0-py3-none-any.whl.
File metadata
- Download URL: readtheyaml-2.2.0-py3-none-any.whl
- Upload date:
- Size: 45.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dd0b40f4f30b1845c96b11fea8d6cc8e89d74b5062fa93ae4331bdc107d94e8
|
|
| MD5 |
849fa7dd116f568afdb8ce6e91a77440
|
|
| BLAKE2b-256 |
f2e4515e8be63a3988beaa7937c58c95ed7d752305b9d940cb3046cbaa1a8d47
|
Provenance
The following attestation bundles were made for readtheyaml-2.2.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.2.0-py3-none-any.whl -
Subject digest:
3dd0b40f4f30b1845c96b11fea8d6cc8e89d74b5062fa93ae4331bdc107d94e8 - Sigstore transparency entry: 928462727
- Sigstore integration time:
-
Permalink:
TheRealMarVin/ReadTheYaml@dc6fb14c02f76647e0ae489348e63772189adfd7 -
Branch / Tag:
refs/tags/2.2 - Owner: https://github.com/TheRealMarVin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@dc6fb14c02f76647e0ae489348e63772189adfd7 -
Trigger Event:
release
-
Statement type: