Package maintenance

sanic-pydantic

Sanic Pyndatic Description A library for parsing and validating http requests for sanic web-framework using pydantic library Full documentation here Requirements python >= 3.7 How to install bash pip install sanic-pydantic Dependencies pydantic Example ```python from sanic_pydantic import webargs from sanic import Sanic from sanic.response import json from pydantic import BaseModel app = Sanic("new app") class PathModel(BaseModel): id: int class QueryModel(BaseModel): name: str class BodyModel(BaseModel): age: int class HeadersModel(BaseModel): api_key: str = Field(alias="x-api-key") @app.route("/get/", methods=["GET"]) @webargs(path=PathModel, headers=HeadersModel) def example_get_endpoint_params(request, id, **kwargs): response = json({"id":id}) return response @app.route("/get-request", methods=["GET"]) @webargs(query=QueryModel) def example_get_endpoint(request, **kwargs): print(kwargs) response = json(kwargs) return response @app.route("/post-request", methods=["POST"]) @webargs(query=QueryModel, body=BodyModel) def example_post_endpoint(request, **kwargs): print(kwargs) response = json(kwargs) return response @app.route("/async-get-request", methods=["GET"]) @webargs(query=QueryModel) async def async_example_get_endpoint(request, **kwargs): print(kwargs) response = json(kwargs) return response @app.route("/async-post-request", methods=["POST"]) @webargs(query=QueryModel, body=BodyModel) async def async_example_post_endpoint(request, **kwargs): print(kwargs) response = json(kwargs) return response if name == "main": app.run(host="0.0.0.0", port=8000) ```

pypi package. Binary | Source

Latest version: 1.3.1 Released: 2022-05-12

Maintenance Metrics
Release recency: 36.0 months C
Commits recency: 0.0 months D
Commits frequency: 0.0 / month D
Issues lifetime: 0.0 days D
Issues open %: 0.0% D
PR lifetime: 0.0 days D
PR open %: 0.0% D