koda-validate


Namekoda-validate JSON
Version 4.1.1 PyPI version JSON
download
home_pagehttps://github.com/keithasaurus/koda-validate
SummaryTypesafe, composable validation
upload_time2024-04-09 17:31:33
maintainerNone
docs_urlNone
authorKeith Philpott
requires_python<4.0.0,>=3.8.1
licenseMIT
keywords validation type hints asyncio serialization typesafe validate validators predicate processor
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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/77/f3/51a061a669e77bb62f83d5ad638e806c588786efadcde8990696661f6bf3/koda_validate-4.1.1.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.1.1",
    "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": "fd833f53dbc9d142518a80c41ee51564081d96b25845c951301f329ab683637a",
                "md5": "8ce97cf849bcfd4429a0965c5d11ab88",
                "sha256": "33ea4a73c2c1a67f61606f53227391cbcd21378039db4c55f471f16258082e97"
            },
            "downloads": -1,
            "filename": "koda_validate-4.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8ce97cf849bcfd4429a0965c5d11ab88",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.8.1",
            "size": 53814,
            "upload_time": "2024-04-09T17:31:31",
            "upload_time_iso_8601": "2024-04-09T17:31:31.095190Z",
            "url": "https://files.pythonhosted.org/packages/fd/83/3f53dbc9d142518a80c41ee51564081d96b25845c951301f329ab683637a/koda_validate-4.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "77f351a061a669e77bb62f83d5ad638e806c588786efadcde8990696661f6bf3",
                "md5": "b19e0c62eb092202f8a7f3f5b5483ebf",
                "sha256": "8a818a4c80bdb539aab0a70c48ff37f28f0f2cb07d1c6cf4fb10d664af42c11a"
            },
            "downloads": -1,
            "filename": "koda_validate-4.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b19e0c62eb092202f8a7f3f5b5483ebf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.8.1",
            "size": 41793,
            "upload_time": "2024-04-09T17:31:33",
            "upload_time_iso_8601": "2024-04-09T17:31:33.030556Z",
            "url": "https://files.pythonhosted.org/packages/77/f3/51a061a669e77bb62f83d5ad638e806c588786efadcde8990696661f6bf3/koda_validate-4.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-09 17:31:33",
    "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"
}
        
Elapsed time: 0.22623s