or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdcore-functions.mdexceptions.mdindex.mdschema-management.mdvalidators.md
tile.json

tessl/pypi-yamale

A schema and validator for YAML with comprehensive data type validation and constraint support.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/yamale@6.0.x

To install, run

npx @tessl/cli install tessl/pypi-yamale@6.0.0

index.mddocs/

Yamale

A comprehensive Python library for validating YAML documents against schemas. Yamale provides a powerful validation syntax supporting various data types (strings, integers, booleans, lists, maps), advanced constraints (min/max values, regex patterns, custom validators), recursive schema definitions through includes, and both strict and non-strict validation modes.

Package Information

  • Package Name: yamale
  • Language: Python
  • Installation: pip install yamale or pip install yamale[ruamel] for YAML 1.2 support
  • Python Requirements: 3.8+
  • Dependencies: PyYAML (required), ruamel.yaml (optional)

Core Imports

import yamale

Common usage imports:

from yamale import make_schema, make_data, validate, YamaleError, YamaleTestCase, __version__
from yamale.validators import DefaultValidators

Basic Usage

import yamale

# Check version
print(f"Yamale version: {yamale.__version__}")

# Create a schema from file
schema = yamale.make_schema('./schema.yaml')

# Load data to validate
data = yamale.make_data('./data.yaml')

# Validate data against schema
try:
    yamale.validate(schema, data)
    print('Validation success!')
except yamale.YamaleError as e:
    print('Validation failed!')
    for result in e.results:
        print(f"Error validating data '{result.data}' with '{result.schema}'")
        for error in result.errors:
            print(f"  {error}")

Example schema (schema.yaml):

name: str()
age: int(max=200)
height: num()
awesome: bool()

Example valid data (data.yaml):

name: Bill
age: 26
height: 6.2
awesome: True

Architecture

Yamale follows a schema-driven validation architecture:

  • Schema: Defines validation rules using YAML syntax with validator expressions
  • Validators: Built-in validation classes for different data types and constraints
  • Data Parsing: YAML file and content parsing with support for multiple parsers
  • Validation Engine: Processes data against schema rules and generates detailed error reports
  • Includes System: Enables schema composition and recursive validation structures

The library supports both programmatic API usage and command-line validation workflows, making it suitable for configuration validation, data processing pipelines, API input validation, and automated testing scenarios.

Capabilities

Core Validation Functions

Primary functions for schema creation, data loading, and validation that form the foundation of Yamale's functionality.

def make_schema(path=None, parser="PyYAML", validators=None, content=None): ...
def make_data(path=None, parser="PyYAML", content=None): ...  
def validate(schema, data, strict=True, _raise_error=True): ...

Core Functions

Schema Management

Schema creation, include management, and validation result handling for building complex validation structures.

class Schema:
    def __init__(self, schema_dict, name="", validators=None, includes=None): ...
    def add_include(self, type_dict): ...
    def validate(self, data, path, strict): ...

class ValidationResult:
    def isValid(self): ...
    errors: list
    data: str
    schema: str

Schema Management

Built-in Validators

Comprehensive set of validators for all common data types with constraint support for building robust validation schemas.

# Core type validators
class String(Validator): ...    # str()
class Integer(Validator): ...   # int()  
class Number(Validator): ...    # num()
class Boolean(Validator): ...   # bool()
class Null(Validator): ...      # null()

# Collection validators  
class List(Validator): ...      # list()
class Map(Validator): ...       # map()

# Advanced validators
class Enum(Validator): ...      # enum()
class Any(Validator): ...       # any()
class Subset(Validator): ...    # subset()
class Include(Validator): ...   # include()
class Regex(Validator): ...     # regex()

# Specialized validators
class Day(Validator): ...       # day() - YYYY-MM-DD
class Timestamp(Validator): ... # timestamp() - YYYY-MM-DD HH:MM:SS  
class Ip(Validator): ...        # ip() - IPv4/IPv6
class Mac(Validator): ...       # mac() - MAC addresses
class SemVer(Validator): ...    # semver() - semantic versioning

# Version information
__version__: str                # Package version string

# Validator registry
DefaultValidators: dict         # Dictionary of all available validators

Built-in Validators

Exception Handling

Error handling and testing utilities for comprehensive validation workflows and error reporting.

class YamaleError(ValueError):
    def __init__(self, results): ...
    message: str
    results: list

class YamaleTestCase(TestCase):
    def validate(self, validators=None): ...
    schema: str
    yaml: str | list  
    base_dir: str

Exception Handling

Command Line Interface

Command-line tools for validating YAML files in scripts and automated workflows.

yamale [options] [PATH ...]

Command Line Interface