Sanic pydantic validation
Project description
Package |
|---|
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file santic-validation-0.0.2.tar.gz.
File metadata
- Download URL: santic-validation-0.0.2.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3baa1a2d79606ced2e67f238ad636a5d3cf23da0b827d1b1516886af36677d0a
|
|
| MD5 |
bf7202d49b59f4f6517fc7a133c0a7ae
|
|
| BLAKE2b-256 |
ad506eab358e6be592b773921944eea623a7f3b61de4002ddc90141b4ec4e7ad
|
File details
Details for the file santic_validation-0.0.2-py3-none-any.whl.
File metadata
- Download URL: santic_validation-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94faab241b9ac08dcf112ad5dd11510f5b6adcd6dad73942baa46b1a8baed43d
|
|
| MD5 |
b806d7340700830601fe14f9b4e9ada8
|
|
| BLAKE2b-256 |
575f47031050b0155531aeddee8c7def1b22bcc670180caa0a43d75adf1af004
|