A flask extension to provide schema validation with pydantic.
Project description
flask-dantic-schema
Generate from quart-schema
Install
pip install schema-validator
How to use
from dataclasses import dataclass
from datetime import datetime
from typing import Optional
from pydantic import BaseModel
from flask import Flask
from schema_validator import FlaskSchema, validate
app = Flask(__name__)
FlaskSchema(app)
OR
schema = FlaskSchema()
schema.init_app(app)
@dataclass
class Todo:
task: str
due: Optional[datetime]
class TodoResponse(BaseModel):
id: int
name: str
@app.post("/")
@validate(body=Todo, responses=TodoResponse)
def create_todo():
... # Do something with data, e.g. save to the DB
return dict(id=1, name="2")
@app.put("/")
@validate(
body=Todo,
responses={200: TodoResponse, 400: TodoResponse}
)
def update_todo():
... # Do something with data, e.g. save to the DB
return TodoResponse(id=1, name="123")
app.cli.add_command(generate_schema_command)
virtualenv: flask schema swagger.json -> generate json swagger
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
schema_validator-0.1.6.tar.gz
(7.8 kB
view hashes)
Built Distribution
Close
Hashes for schema_validator-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab32557bbdcaa24d627414a39084557a60edc6c0428dd3586c404fd5546ba4f1 |
|
MD5 | 0c6e58150b475734be349f5f485fde03 |
|
BLAKE2b-256 | 7576860588a11cb837f4331b5c3d4de84dc9115ba17ccefefeaa422a8c7c2121 |