Getting Started
A library for parsing and validating http requests for sanic web-framework using pydantic library
Full code on github here
Requirements
python >= 3.8
How to install
pip install sanic-pydantic
Dependencies
pydantic
Example
from sanic_pydantic import webargs
from sanic import Sanic
from sanic.response import json
from pydantic import BaseModel
app = Sanic("new app")
class BodyModel(BaseModel):
age: int
class QueryModel(BaseModel):
name: str
@app.route("/post-request", methods=["POST"])
@webargs(query=QueryModel, body=BodyModel)
def example_post_endpoint(request, **kwargs):
print(kwargs)
response = json(kwargs)
return response
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)