Release v4.4.1. (Changelog)
webargs is a Python library for parsing and validating HTTP request objects, with built-in support for popular web frameworks, including Flask, Django, Bottle, Tornado, Pyramid, webapp2, Falcon, and aiohttp.
from flask import Flask
from webargs import fields
from webargs.flaskparser import use_args
app = Flask(__name__)
hello_args = {"name": fields.Str(required=True)}
@app.route("/")
@use_args(hello_args)
def index(args):
return "Hello " + args["name"]
if __name__ == "__main__":
app.run()
# curl http://localhost:5000/\?name\='World'
# Hello World
Webargs will automatically parse:
Query Parameters
$ curl http://localhost:5000/\?name\='Freddie'
Hello Freddie
Form Data
$ curl -d 'name=Brian' http://localhost:5000/
Hello Brian
JSON Data
$ curl -X POST -H "Content-Type: application/json" -d '{"name":"Roger"}' http://localhost:5000/
Hello Roger
and, optionally:
Schemas
to define your request arguments.pip install -U webargs
Ready to get started? Go on to the Quickstart tutorial or check out some examples.