# Koda Validate
Koda Validate is a library and toolkit for building composable and typesafe validators. In many cases,
validators can be derived from typehints (e.g. TypedDicts, dataclasses, and NamedTuples). For everything else, you can
combine existing validation logic, or write your own. At its heart, Koda Validate is just a few kinds of
callables that fit together, so the possibilities are endless. It is async-friendly and comparable in performance to Pydantic 2.
Koda Validate can be used in normal control flow or as a runtime type checker.
Docs: [https://koda-validate.readthedocs.io/en/stable/](https://koda-validate.readthedocs.io/en/stable/)
## At a Glance
#### Explicit Validators
```python
from koda_validate import ListValidator, StringValidator, MaxLength, MinLength
my_string_validator = StringValidator(MinLength(1), MaxLength(20))
my_string_validator("a string!")
#> Valid("a string!")
my_string_validator(5)
#> Invalid(...)
# Composing validators
list_string_validator = ListValidator(my_string_validator)
list_string_validator(["a", "b", "c"])
#> Valid(["a", "b", "c"])
```
#### Derived Validators
```python
from typing import TypedDict
from koda_validate import (TypedDictValidator, Valid, Invalid)
from koda_validate.serialization import to_serializable_errs
class Person(TypedDict):
name: str
hobbies: list[str]
person_validator = TypedDictValidator(Person)
match person_validator({"name": "Guido"}):
case Valid(string_list):
print(f"woohoo, valid!")
case Invalid() as invalid:
# readable errors
print(to_serializable_errs(invalid))
#> {'hobbies': ['key missing']}
```
#### Runtime Type Checking
```python
from koda_validate.signature import validate_signature
@validate_signature
def add(a: int, b: int) -> int:
return a + b
add(1, 2) # returns 3
add(1, "2") # raises `InvalidArgsError`
# koda_validate.signature.InvalidArgsError:
# Invalid Argument Values
# -----------------------
# b='2'
# expected <class 'int'>
```
There's much, much more in the [Docs](https://koda-validate.readthedocs.io/en/stable/).
## Something's Missing or Wrong
Open an [issue on GitHub](https://github.com/keithasaurus/koda-validate/issues) please!
Raw data
{
"_id": null,
"home_page": "https://github.com/keithasaurus/koda-validate",
"name": "koda-validate",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0.0,>=3.8.1",
"maintainer_email": null,
"keywords": "validation, type hints, asyncio, serialization, typesafe, validate, validators, predicate, processor",
"author": "Keith Philpott",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/1c/26/c3c5fa3c49fa32f81485f60298af8cabe5dae3ef49ff29336a10f2286301/koda_validate-4.2.0.tar.gz",
"platform": null,
"description": "# Koda Validate\n\nKoda Validate is a library and toolkit for building composable and typesafe validators. In many cases,\nvalidators can be derived from typehints (e.g. TypedDicts, dataclasses, and NamedTuples). For everything else, you can \ncombine existing validation logic, or write your own. At its heart, Koda Validate is just a few kinds of\ncallables that fit together, so the possibilities are endless. It is async-friendly and comparable in performance to Pydantic 2.\n\nKoda Validate can be used in normal control flow or as a runtime type checker.\n\nDocs: [https://koda-validate.readthedocs.io/en/stable/](https://koda-validate.readthedocs.io/en/stable/)\n\n## At a Glance\n\n#### Explicit Validators\n\n```python\nfrom koda_validate import ListValidator, StringValidator, MaxLength, MinLength\n\nmy_string_validator = StringValidator(MinLength(1), MaxLength(20))\nmy_string_validator(\"a string!\")\n#> Valid(\"a string!\")\nmy_string_validator(5)\n#> Invalid(...)\n\n\n# Composing validators\nlist_string_validator = ListValidator(my_string_validator)\nlist_string_validator([\"a\", \"b\", \"c\"])\n#> Valid([\"a\", \"b\", \"c\"])\n```\n\n#### Derived Validators\n\n```python\nfrom typing import TypedDict\nfrom koda_validate import (TypedDictValidator, Valid, Invalid)\nfrom koda_validate.serialization import to_serializable_errs\n\nclass Person(TypedDict):\n name: str\n hobbies: list[str]\n\n\nperson_validator = TypedDictValidator(Person)\n\nmatch person_validator({\"name\": \"Guido\"}):\n case Valid(string_list):\n print(f\"woohoo, valid!\")\n case Invalid() as invalid:\n # readable errors\n print(to_serializable_errs(invalid))\n\n#> {'hobbies': ['key missing']}\n```\n\n#### Runtime Type Checking\n\n```python\nfrom koda_validate.signature import validate_signature\n\n@validate_signature\ndef add(a: int, b: int) -> int:\n return a + b\n\n\nadd(1, 2) # returns 3\n\nadd(1, \"2\") # raises `InvalidArgsError`\n# koda_validate.signature.InvalidArgsError:\n# Invalid Argument Values\n# -----------------------\n# b='2'\n# expected <class 'int'>\n```\n\nThere's much, much more in the [Docs](https://koda-validate.readthedocs.io/en/stable/).\n\n\n## Something's Missing or Wrong \nOpen an [issue on GitHub](https://github.com/keithasaurus/koda-validate/issues) please!\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Typesafe, composable validation",
"version": "4.2.0",
"project_urls": {
"Documentation": "https://koda-validate.readthedocs.io/en/stable/",
"Homepage": "https://github.com/keithasaurus/koda-validate"
},
"split_keywords": [
"validation",
" type hints",
" asyncio",
" serialization",
" typesafe",
" validate",
" validators",
" predicate",
" processor"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "421be04f77d9013159e8e9b2617d28f55ae9c918e3bb8af26088be652dbeb8ac",
"md5": "5da14a30122ae3610c044a55f3773778",
"sha256": "3bae7a416d6cf69d94be3094cb51fb5700482f6852cf6df063ad3d084eca6a81"
},
"downloads": -1,
"filename": "koda_validate-4.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5da14a30122ae3610c044a55f3773778",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.8.1",
"size": 53781,
"upload_time": "2024-09-05T06:32:52",
"upload_time_iso_8601": "2024-09-05T06:32:52.228623Z",
"url": "https://files.pythonhosted.org/packages/42/1b/e04f77d9013159e8e9b2617d28f55ae9c918e3bb8af26088be652dbeb8ac/koda_validate-4.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1c26c3c5fa3c49fa32f81485f60298af8cabe5dae3ef49ff29336a10f2286301",
"md5": "21fe13d904932cedf4770d3cf28c9fc3",
"sha256": "c7d17283e85c37783ff50537d6fd30c515510f27aa29a9e2f4f43d27d76068ea"
},
"downloads": -1,
"filename": "koda_validate-4.2.0.tar.gz",
"has_sig": false,
"md5_digest": "21fe13d904932cedf4770d3cf28c9fc3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.8.1",
"size": 42104,
"upload_time": "2024-09-05T06:32:54",
"upload_time_iso_8601": "2024-09-05T06:32:54.280573Z",
"url": "https://files.pythonhosted.org/packages/1c/26/c3c5fa3c49fa32f81485f60298af8cabe5dae3ef49ff29336a10f2286301/koda_validate-4.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-05 06:32:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "keithasaurus",
"github_project": "koda-validate",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "koda-validate"
}