Bug fixes:
- aiohttpparser: Fix bug that raised a
JSONDecodeErrorraised when parsing non-JSON requests using defaultlocations(:issue:`80`). Thanks :user:`leonidumanskiy` for reporting. - Fix parsing JSON requests that have a vendor media type, e.g.
application/vnd.api+json.
Features:
Parser.parse,Parser.use_argsandParser.use_kwargscan take a Schema factory as the first argument (:issue:`73`). Thanks :user:`DamianHeard` for the suggestion and the PR.
Support:
- Docs: Add "Custom Parsers" section with example of parsing nested querystring arguments (:issue:`74`). Thanks :user:`dwieeb`.
- Docs: Add "Advanced Usage" page.
Features:
- Add
AIOHTTPParser(:issue:`71`). - Add
webargs.asyncmodule withAsyncParser.
Bug fixes:
- If an empty list is passed to a List argument, it will be parsed as an empty list rather than being excluded from the parsed arguments dict (:issue:`70`). Thanks :user:`mTatcher` for catching this.
Other changes:
- Backwards-incompatible: When decorating resource methods with
FalconParser.use_args, the parsed arguments dictionary will be positioned after the request and response arguments. - Backwards-incompatible: When decorating views with
DjangoParser.use_args, the parsed arguments dictionary will be positioned after the request argument. - Backwards-incompatible:
Parser.get_request_from_view_argsgets passed a view function as its first argument. - Backwards-incompatible: Remove logging from default error handlers.
Features:
- Add
FalconParser(:issue:`63`). - Add
fields.DelimitedList(:issue:`66`). Thanks :user:`jmcarp`. TornadoParserwill parse json withsimplejsonif it is installed.BottleParsercaches parsed json per-request for improved performance.
No breaking changes. Yay!
Features:
TornadoParserreturns unicode strings rather than bytestrings (:issue:`41`). Thanks :user:`thomasboyt` for the suggestion.- Add
Parser.get_default_requestandParser.get_request_from_view_argshooks to simplifyParserimplementations. - Backwards-compatible:
webargs.core.get_valuetakes aFieldas its last argument. Note: this is technically a breaking change, but this won't affect most users sinceget_valueis only used internally byParserclasses.
Support:
- Add
examples/annotations_example.py(demonstrates using Python 3 function annotations to define request arguments). - Fix examples. Thanks :user:`hyunchel` for catching an error in the Flask error handling docs.
Bug fixes:
- Correctly pass
validateandforce_allparams toPyramidParser.use_args.
The major change in this release is that webargs now depends on marshmallow for defining arguments and validation.
Your code will need to be updated to use Fields rather than Args.
# Old API
from webargs import Arg
args = {
'name': Arg(str, required=True)
'password': Arg(str, validate=lambda p: len(p) >= 6),
'display_per_page': Arg(int, default=10),
'nickname': Arg(multiple=True),
'Content-Type': Arg(dest='content_type', location='headers'),
'location': Arg({
'city': Arg(str),
'state': Arg(str)
})
'meta': Arg(dict),
}
# New API
from webargs import fields
args = {
'name': fields.Str(required=True)
'password': fields.Str(validate=lambda p: len(p) >= 6),
'display_per_page': fields.Int(missing=10),
'nickname': fields.List(fields.Str()),
'content_type': fields.Str(load_from='Content-Type'),
'location': fields.Nested({
'city': fields.Str(),
'state': fields.Str()
}),
'meta': fields.Dict(),
}Features:
- Error messages for all arguments are "bundled" (:issue:`58`).
Changes:
- Backwards-incompatible: Replace
Argswith marshmallow fields (:issue:`61`). - Backwards-incompatible: When using
use_kwargs, missing arguments will have the special valuemissingrather thanNone. TornadoParserraises a customHTTPErrorwith amessagesattribute when validation fails.
Bug fixes:
- Fix required validation of nested arguments (:issue:`39`, :issue:`51`). These are fixed by virtue of using marshmallow's
Nestedfield. Thanks :user:`ewang` and :user:`chavz` for reporting.
Support:
- Updated docs.
- Add
examples/schema_example.py. - Tested against Python 3.5.
Changes:
- If a parsed argument is
None, the type conversion function is not called :issue:`54`. Thanks :user:`marcellarius`.
Bug fixes:
- Fix parsing nested
Argswhen the argument is missing from the input (:issue:`52`). Thanks :user:`stas`.
Features:
- Add parsing of
matchdicttoPyramidParser. Thanks :user:`hartror`.
Bug fixes:
- Fix
PyramidParser'suse_kwargsmethod (:issue:`42`). Thanks :user:`hartror` for the catch and patch. - Correctly use locations passed to Parser's constructor when using
use_args(:issue:`44`). Thanks :user:`jacebrowning` for the catch and patch. - Fix behavior of
defaultanddestargument on nestedArgs(:issue:`40` and :issue:`46`). Thanks :user:`stas`.
Changes:
- A 422 response is returned to the client when a
ValidationErroris raised by a parser (:issue:`38`).
Features:
- Support for webapp2 via the webargs.webapp2parser module. Thanks :user:`Trii`.
- Store argument name on
RequiredArgMissingError. Thanks :user:`stas`. - Allow error messages for required validation to be overriden. Thanks again :user:`stas`.
Removals:
- Remove
sourceparameter fromArg.
Features:
- Store argument name on
ValidationError(:issue:`32`). Thanks :user:`alexmic` for the suggestion. Thanks :user:`stas` for the patch. - Allow nesting of dict subtypes.
Changes:
- Add
destparameter toArgconstructor which determines the key to be added to the parsed arguments dictionary (:issue:`32`). - Backwards-incompatible: Rename
targetsparameter tolocationsinParserconstructor,Parser#parse_arg,Parser#parse,Parser#use_args, andParser#use_kwargs. - Backwards-incompatible: Rename
Parser#target_handlertoParser#location_handler.
Deprecation:
- The
sourceparameter is deprecated in favor of thedestparameter.
Bug fixes:
- Fix
validateparameter ofDjangoParser#use_args.
- When parsing a nested
Arg, filter out extra arguments that are not part of theArg'snesteddict(:issue:`28`). Thanks Derrick Gilland for the suggestion. - Fix bug in parsing
Argswith both type coercion andmultiple=True(:issue:`30`). Thanks Steven Manuatu for reporting. - Raise
RequiredArgMissingErrorwhen a required argument is missing on a request.
- Fix behavior of
multiple=Truewhen nesting Args (:issue:`29`). Thanks Derrick Gilland for reporting.
- Pyramid support thanks to @philtay.
- User-friendly error messages when
Argtype conversion/validation fails. Thanks Andriy Yurchuk. - Allow
useargument to be a list of functions. - Allow
Argsto be nested within each other, e.g. for nested dict validation. Thanks @saritasa for the suggestion. - Backwards-incompatible: Parser will only pass
ValidationErrorsto its error handler function, rather than catching all generic Exceptions. - Backwards-incompatible: Rename
Parser.TARGET_MAPtoParser.__target_map__. - Add a short-lived cache to the
Parserclass that can be used to store processed request data for reuse. - Docs: Add example usage with Flask-RESTful.
- Fix bug in
TornadoParserthat raised an error when request body is not a string (e.g when it is aFuture). Thanks Josh Carp.
- Fix
Parser.use_kwargsbehavior when anArgis allowed missing. Theallow_missingattribute is ignored whenuse_kwargsis called. defaultmay be a callable.- Allow
ValidationErrorto specify a HTTP status code for the error response. - Improved error logging.
- Add
'query'as a valid target name. - Allow a list of validators to be passed to an
ArgorParser.parse. - A more useful
__repr__forArg. - Add examples and updated docs.
- Add
sourceparameter toArgconstructor. Allows renaming of keys in the parsed arguments dictionary. Thanks Josh Carp. FlaskParser'shandle_errormethod attaches the string representation of validation errors onerr.data['message']. The raised exception is stored onerr.data['exc'].- Additional keyword arguments passed to
Argare stored as metadata.
- Fix bug in
TornadoParser'shandle_errormethod. Thanks Josh Carp. - Add
errorparameter toParserconstructor that allows a custom error message to be used if schema-level validation fails. - Fix bug that raised a
UnicodeEncodeErroron Python 2 when an Arg's validator function received non-ASCII input.
- Fix regression with parsing an
Argwith bothdefaultandtargetset (see issue #11).
- Add
validateparameter toParser.parseandParser.use_args. Allows validation of the full parsed output. - If
allow_missingisTrueon anArgfor whichNoneis explicitly passed, the value will still be present in the parsed arguments dictionary. - Backwards-incompatible:
Parser'sparse_*methods returnwebargs.core.Missingif the value cannot be found on the request. NOTE:webargs.core.Missingwill not show up in the final output ofParser.parse. - Fix bug with parsing empty request bodies with
TornadoParser.
- Fix behavior of
Arg'sallow_missingparameter whenmultiple=True. - Fix bug in tornadoparser that caused parsing JSON arguments to fail.
- Fix JSON parsing in Flask parser when Content-Type header contains more than just application/json. Thanks Samir Uppaluru for reporting.
- Backwards-incompatible: The
useparameter toArgis called before type conversion occurs. Thanks Eric Wang for the suggestion. - Tested on Tornado>=4.0.
- Custom target handlers can be defined using the
Parser.target_handlerdecorator. - Error handler can be specified using the
Parser.error_handlerdecorator. Argscan define their request target by passing in atargetargument.- Backwards-incompatible:
DEFAULT_TARGETSis now a class member ofParser. This allows subclasses to override it.
- Fix bug that caused
use_argsto fail on class-based views in Flask. - Add
allow_missingparameter toArg.
- Awesome contributions from the open-source community!
- Add
use_kwargsdecorator. Thanks @venuatu. - Tornado support thanks to @jvrsantacruz.
- Tested on Python 3.4.
- Fix bug with parsing JSON in Flask and Bottle.
- Remove print statements in core.py. Oops.
- Add support for repeated parameters (#1).
- Backwards-incompatible: All parse_* methods take arg as their fourth argument.
- Add
error_handlerparam toParser.
- Bottle support.
- Add
targetsparam toParser. Allows setting default targets. - Add
filestarget.
- First release.
- Parses JSON, querystring, forms, headers, and cookies.
- Support for Flask and Django.