Apathetic Python Schema π§©
Lightweight validation for dict-based configs.
Types can be schema too.
Apathetic Python Schema validates dict-based data structures (configs, usually from JSONC/JSON/TOML) using Python TypedDicts used for mypy/pyright. No need for separate schema definitions β your type annotations are your schema.
Features
- π§© TypedDict validation β Validate dict-based configs using Python TypedDicts
- π Recursive validation β Supports nested TypedDicts and list types
- β οΈ Error aggregation β Collect and report validation errors and warnings
- π― Strict mode β Optional strict validation that treats warnings as errors
- π§ Type-aware β Works with mypy/pyright type annotations
- πͺΆ Minimal dependencies β Only requires
apathetic-utils - π Helpful errors β Provides context and suggestions for validation failures
Quick Example
from apathetic_schema import apathetic_schema, ApatheticSchema_ValidationSummary
from apathetic_utils import schema_from_typeddict, load_jsonc
from typing import TypedDict
from pathlib import Path
# Define your config schema using TypedDict
class AppConfig(TypedDict):
name: str
version: str
port: int
debug: bool
# Load config from JSONC
config = load_jsonc(Path("config.jsonc"))
# Validate against TypedDict schema
summary = ApatheticSchema_ValidationSummary(valid=True, errors=[], strict_warnings=[], warnings=[], strict=False)
schema = schema_from_typeddict(AppConfig)
is_valid = apathetic_schema.check_schema_conformance(
config,
schema,
"in configuration file",
strict_config=False,
summary=summary,
)
if not summary.valid:
print("Validation errors:", summary.errors)
print("Warnings:", summary.warnings)
Requirements
- Python 3.10+
- apathetic-utils (>=0.2.1,<2.0.0) - for
schema_from_typeddict,safe_isinstance, and other utilities - apathetic-logging (>=0.3.2,<2.0.0) - for logging functionality
Installation
Install via poetry or pip:
# Using poetry
poetry add apathetic-schema
# Using pip
pip install apathetic-schema
For alternative installation methods, see the Installation Guide.
Documentation
- Installation Guide β How to install and set up
- Quick Start β Get up and running in minutes
- API Reference β Complete API documentation
- Examples β Advanced usage examples
- Contributing β How to contribute
License
Youβre free to use, copy, and modify the library under the standard MIT terms.
The additional rider simply requests that this project not be used to train or fine-tune AI/ML systems until the author deems fair compensation frameworks exist.
Normal use, packaging, and redistribution for human developers are unaffected.
Resources
- π Roadmap
- π Release Notes
- π Issue Tracker
- π¬ Discord