webargs — webargs 5.5.3 documentation
Description: Declarative parsing and validation of HTTP request objects.

# webargs

Release v5.5.3. (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__)

    @app.route("/")
    @use_args({"name": fields.Str(required=True)})
    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:

- Headers

- Cookies

- Files

- Paths

## Why Use It

- Simple, declarative syntax. Define your arguments as a mapping rather than imperatively pulling values off of request objects.

- Code reusability. If you have multiple views that have the same request parameters, you only need to define your parameters once. You can also reuse validation and pre-processing routines.

- Self-documentation. Webargs makes it easy to understand the expected arguments and their types for your view functions.

- Automatic documentation. The metadata that webargs provides can serve as an aid for automatically generating API documentation.

- Cross-framework compatibility. Webargs provides a consistent request-parsing interface that will work across many Python web frameworks.

- marshmallow integration. Webargs uses marshmallow under the hood. When you need more flexibility than dictionaries, you can use marshmallow `Schemas` to define your request arguments.

## Get It Now

    pip install -U webargs

Ready to get started? Go on to the Quickstart tutorial or check out some examples.

## User Guide

- Install
  - From the PyPI
  - Get the Bleeding Edge Version
- Quickstart
  - Basic Usage
  - Decorator API
  - Request “Locations”
  - Validation
  - Error Handling
  - Parsing Lists in Query Strings
  - Nesting Fields
  - Next Steps
- Advanced Usage
  - Custom Location Handlers
  - marshmallow Integration
  - Schema Factories
  - Custom Fields
  - Custom Parsers
  - Returning HTTP 400 Responses
  - Bulk-type Arguments
  - Mixing Locations
  - Next Steps
- Framework Support
  - Flask
  - Django
  - Tornado
  - Pyramid
  - Falcon
  - aiohttp
  - Bottle
- Ecosystem

## API Reference

- API
  - webargs.core
  - webargs.fields
  - webargs.asyncparser
  - webargs.flaskparser
  - webargs.djangoparser
  - webargs.bottleparser
  - webargs.tornadoparser
  - webargs.pyramidparser
  - webargs.webapp2parser
  - webargs.falconparser
  - webargs.aiohttpparser

## Project Info

- License
- Changelog
- Authors
- Contributing Guidelines

Install →