Skip to main content

Sanic pydantic validation

Project description

Tools for help developers working with Sanic and Pydantic.

Features

  • validate_schema

  • async_validate_by_method

Installation

pip install santic-validation

Usage

from typing import Optional
from pydantic import BaseModel
from santic_validation import validate_schema, async_validate_by_method


class PlanetSchema(BaseModel):
   name: Optional[str]
   category: int


sanic_app = Sanic(name="TestingApp")


def query_category_(category_id):
    return Model.get(id=category_id)

@sanic_app.route("/post", methods=["POST"])
@validate_schema(body=BodySchema, query=QuerySchema)
async def post_handler(request, body, query):

    # validate to make sure category exists
    # if exists, change the body.category value
    async_validate_by_method(
        body,
        {
            "category": {
                "method": query_category,
                "params": {"category_id": body.category},
            }
        },
        exceptions=(DoesNotExists,),
    )

    return Text("hello world")

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

santic-validation-0.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

santic_validation-0.0.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file santic-validation-0.0.1.tar.gz.

File metadata

  • Download URL: santic-validation-0.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.10

File hashes

Hashes for santic-validation-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d903e6355d27b44475dc899ef2d97d6f798fb256527928fd9fab315e6380c5c6
MD5 c28ba37dcb7c1ce8206e6799a71cc979
BLAKE2b-256 c3698ec73a540af804acb00568b358f427c642b371248ba4140fd77008ba8585

See more details on using hashes here.

File details

Details for the file santic_validation-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for santic_validation-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 597233fda0da4394f6361431eee30385ca6652148f5abeffb5a4ddf61a75f2b7
MD5 6c94e20c089dad4cf00adad681c27c1a
BLAKE2b-256 ed0a471212324b1db726cb2c5e4edbabab0fbe155bf06a04dea388a3aeaeb7b3

See more details on using hashes here.

Supported by

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