Skip to content

Getting Started

CircleCI CircleCI codecov GitHub Pipenv locked Python version GitHub top language PyPI Downloads license GitHub pull requests GitHub closed pull requests GitHub issues GitHub closed issues

A library for parsing and validating http requests for Flask web framework using pydantic library

Full code on github

Requirements

python >= 3.6

How to install

pip install pydantic-webargs

Dependencies

flask
pydantic

How to use

from flask import Flask
from pydantic import BaseModel
from pydantic_webargs import webargs

app = Flask(__name__)


class QueryModel(BaseModel):
    name: str


class BodyModel(BaseModel):
    age: int


@app.route("/post-request", methods=["POST"])
@webargs(query=QueryModel, body=BodyModel)
def example_post_endpoint(**kwargs):
    print(kwargs)
    response = kwargs
    return response


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)