{"id":2842,"library":"webargs","title":"webargs","description":"webargs is a Python library for declarative parsing and validation of HTTP request objects. It provides built-in support for popular web frameworks, including Flask, Django, Bottle, Tornado, Pyramid, Falcon, and aiohttp. Leveraging Marshmallow under the hood, it offers a consistent API for defining request arguments and handling validation errors across different frameworks. The library is actively maintained, with the current stable version being 8.7.1.","status":"active","version":"8.7.1","language":"en","source_language":"en","source_url":"https://github.com/marshmallow-code/webargs","tags":["http","flask","django","validation","api","marshmallow","request parsing","web frameworks"],"install":[{"cmd":"pip install -U webargs","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for schema definition and validation.","package":"marshmallow","optional":false}],"imports":[{"note":"While webargs re-exports marshmallow.fields, it's best practice to import directly from webargs for consistency within the library's context.","wrong":"from marshmallow import fields","symbol":"fields","correct":"from webargs import fields"},{"note":"Import path varies by framework (e.g., `webargs.djangoparser`, `webargs.aiohttpparser`).","symbol":"use_args","correct":"from webargs.flaskparser import use_args"},{"note":"The `Arg` class was used in older versions (<=2.x). As of webargs 3.x, `marshmallow.fields.Field` classes (re-exported by `webargs.fields`) are used.","wrong":"from webargs import Arg","symbol":"Arg","correct":"from webargs import fields"},{"note":"The `dict2schema` helper was removed in webargs 7.x. Use `marshmallow.Schema.from_dict` instead.","wrong":"from webargs import dict2schema","symbol":"dict2schema","correct":"from marshmallow import Schema"}],"quickstart":{"code":"from flask import Flask\nfrom webargs import fields\nfrom webargs.flaskparser import use_args\n\napp = Flask(__name__)\n\n@app.route(\"/\")\n@use_args({\"name\": fields.Str(required=True)}, location=\"query\")\ndef index(args):\n    return \"Hello \" + args[\"name\"]\n\nif __name__ == \"__main__\":\n    # To run: python your_app.py\n    # Then try: curl \"http://127.0.0.1:5000/?name=World\"\n    app.run(debug=True)","lang":"python","description":"This Flask example demonstrates how to use the `use_args` decorator to parse and validate a 'name' query parameter. It uses `fields.Str` from `webargs` (which re-exports `marshmallow.fields`) to define the expected argument."},"warnings":[{"fix":"Upgrade Marshmallow to version 3.x or higher: `pip install -U marshmallow>=3.0.0`.","message":"webargs 7.x dropped support for Marshmallow 2. Ensure your project is using Marshmallow 3.x or later.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Replace `webargs.dict2schema` with `marshmallow.Schema.from_dict`.","message":"The `dict2schema` helper function was removed in webargs 7.x.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Explicitly set `unknown=marshmallow.RAISE` in your schema or `use_args`/`use_kwargs` decorator if you require strict validation against unknown fields in these locations. Example: `@use_args(MySchema(unknown=RAISE))`.","message":"The default behavior of the `unknown` parameter changed in webargs 8.x for `json`, `form`, and `json_or_form` locations. It now defaults to `None` instead of `RAISE` if not explicitly set. This means unknown fields might be silently ignored rather than raising an error.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Upgrade your Python environment to 3.9 or higher. If using webapp2, migrate to a supported framework.","message":"webargs 7.x dropped support for Python 3.5 and webapp2.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Register a custom error handler using the parser's `@parser.error_handler` decorator to properly format validation errors as JSON. See `webargs` documentation on 'Error Handling' for details.","message":"When integrating with Flask-RESTful, webargs' default error handling may return HTTP 500 errors for validation failures instead of JSON-formatted errors.","severity":"gotcha","affected_versions":"All versions with Flask-RESTful"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}