Skip to main content

Pydantic validation for Sanic framework

Project description

sanicpydantic

Pydantic validation for Sanic framework

Install:

pip install sanicpydantic

Example:

from pydantic import BaseModel
from sanic_pydantic import RequestValidator

validator = RequestValidator()

...

class QueryModel(BaseModel):
    str_param: str
    int_param: int
    bool_param: bool


@app.get('/')
@validator(query_schema=QueryModel)
def get_endpoint(request, query_: QueryModel):
    ...


class JsonModel(BaseModel):
    str_field: str
    int_field: int
    bool_field: bool


@app.post('/')
@validator(json_schema=JsonModel)
def post_endpoint(request, json_: JsonModel):
    ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sanicpydantic-0.0.3.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

sanicpydantic-0.0.3-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page