Typesafe, composable validation
Project description
Koda Validate
Build typesafe validators automatically or explicitly -- or write your own. Combine them to build validators of arbitrary complexity. Koda Validate is async-friendly, pure Python, and 1.5x - 12x faster than Pydantic.
Docs: https://koda-validate.readthedocs.io/en/stable/
from typing import TypedDict
from koda_validate import (StringValidator, MaxLength, MinLength,
ListValidator, TypedDictValidator, Valid, Invalid)
from koda_validate.serialization import to_serializable_errs
from koda_validate.signature import validate_signature
# Automatic Validators
class Person(TypedDict):
name: str
hobbies: list[str]
person_validator = TypedDictValidator(Person)
# Produce readable errors
match person_validator({"name": "Guido"}):
case Valid(string_list):
print(f"woohoo, valid!")
case Invalid() as invalid:
print(to_serializable_errs(invalid))
# prints: {'hobbies': ['key missing']}
# Explicit Validators
string_validator = StringValidator(MinLength(8), MaxLength(20))
list_string_validator = ListValidator(string_validator)
# Runtime type checking
@validate_signature
def add(a: int, b: int) -> int:
return a + b
There's much, much more... Check out the Docs.
Something's Missing Or Wrong
Open an issue on GitHub please!
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
koda_validate-4.0.0.tar.gz
(41.4 kB
view hashes)
Built Distribution
Close
Hashes for koda_validate-4.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6e744f529a5d5e77e187e16dc3c7816c8e8598646e162e4dde4aef95cee67f3 |
|
MD5 | d0c29bde846192ffca8305102264e88d |
|
BLAKE2b-256 | fcfdeb115efc482e5df4a28bf271898120759f9a54e92d8eb5711886c9c8849b |