|
marshmallow package from marshmallow repomarshmallow |
Third-Party Package
This third-party package's source repository does not contain a package manifest. Instead, its package manifest is stored in its release repository. In order to build this package from source in a Catkin workspace, please download its package manifest.Package Summary
| Tags | No category tags. |
| Version | 2.9.1 |
| License | BSD |
| Build type | CATKIN |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/marshmallow-code/marshmallow.git |
| VCS Type | git |
| VCS Version | 2.9.1 |
| Last Updated | 2016-07-22 |
| Dev Status | MAINTAINED |
| CI status | No Continuous Integration |
| Released | RELEASED |
| Tags | No category tags. |
| Contributing |
Help Wanted (0)
Good First Issues (0) Pull Requests to Review (0) |
Package Description
Additional Links
Maintainers
- AlexV
Authors
- Steven Loria
marshmallow: simplified object serialization
marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.
``` {.sourceCode .python} from datetime import date from marshmallow import Schema, fields, pprint
class ArtistSchema(Schema): name = fields.Str()
class AlbumSchema(Schema): title = fields.Str() release_date = fields.Date() artist = fields.Nested(ArtistSchema())
bowie = dict(name=’David Bowie’) album = dict(artist=bowie, title=’Hunky Dory’, release_date=date(1971, 12, 17))
schema = AlbumSchema() result = schema.dump(album) pprint(result.data, indent=2)
{ ‘artist’: {‘name’: ‘David Bowie’},
‘release_date’: ‘1971-12-17’,
‘title’: ‘Hunky Dory’}
```
In short, marshmallow schemas can be used to:
- Validate input data.
- Deserialize input data to app-level objects.
- Serialize app-level objects to primitive Python types. The serialized objects can then be rendered to standard formats such as JSON for use in an HTTP API.
Get It Now
$ pip install -U marshmallow
Documentation
Full documentation is available at http://marshmallow.readthedocs.io/ .
Requirements
- Python >= 2.6 or >= 3.3
marshmallow has no external dependencies outside of the Python standard library, although python-dateutil is recommended for robust datetime deserialization.
Ecosystem
A list of marshmallow-related libraries can be found at the GitHub wiki here:
https://github.com/marshmallow-code/marshmallow/wiki/Ecosystem
Project Links
- Docs: http://marshmallow.readthedocs.io/
- Changelog: http://marshmallow.readthedocs.io/en/latest/changelog.html
- PyPI: https://pypi.python.org/pypi/marshmallow
- Issues: https://github.com/marshmallow-code/marshmallow/issues
License
MIT licensed. See the bundled LICENSE file for more details.
Changelog
2.9.1 (2016-07-21)
Bug fixes:
- Fix serialization of
datetime.timeobjects with microseconds (464{.interpreted-text role=”issue”}). ThanksTim-Erwin{.interpreted-text role=”user”} for reporting and thanksvuonghv{.interpreted-text role=”user”} for the fix. - Make
@validatesconsistent with field validator behavior: if validation fails, the field will not be included in the deserialized output (391{.interpreted-text role=”issue”}). Thanksmartinstein{.interpreted-text role=”user”} for reporting and thanks@vuonghv{.interpreted-text role=”user”} for the fix.
2.9.0 (2016-07-06)
-
Decimalfield coerces input values to a string before deserializing to a [decimal.Decimal]{.title-ref} object in order to avoid transformation of float values under 12 significant digits (434{.interpreted-text role=”issue”},435{.interpreted-text role=”issue”}). Thanksdavidthornton{.interpreted-text role=”user”} for the PR.
2.8.0 (2016-06-23)
Features:
- Allow
onlyandexcludeparameters to take nested fields, using dot-delimited syntax (e.g.only=['blog.author.email']) (402{.interpreted-text role=”issue”}). ThanksTim-Erwin{.interpreted-text role=”user”} anddeckar01{.interpreted-text role=”user”} for the discussion and implementation.
Support:
- Update tasks.py for compatibility with invoke>=0.13.0. Thanks
deckar01{.interpreted-text role=”user”}.
2.7.3 (2016-05-05)
- Make
field.parentandfield.nameaccessible toon_bind_field(449{.interpreted-text role=”issue”}). Thanksimmerrr{.interpreted-text role=”user”}.
2.7.2 (2016-04-27)
No code changes in this release. This is a reupload in order to
distribute an sdist for the last hotfix release. See
443{.interpreted-text role=”issue”}.
Support:
- Update license entry in setup.py to fix RPM distributions
(
433{.interpreted-text role=”issue”}). Thanksrrajaravi{.interpreted-text role=”user”} for reporting.
2.7.1 (2016-04-08)
Bug fixes:
- Only add Schemas to class registry if a class name is provided. This
allows Schemas to be constructed dynamically using the
typeconstructor without getting added to the class registry (which is useful for saving memory).
2.7.0 (2016-04-04)
Features:
- Make context available to
Nestedfield'son_bind_fieldmethod (408{.interpreted-text role=”issue”}). Thanksimmerrr{.interpreted-text role=”user”} for the PR. - Pass through user
ValidationErrorkwargs (418{.interpreted-text role=”issue”}). Thanksrusselldavies{.interpreted-text role=”user”} for helping implement this.
Other changes:
- Remove unused attributes
root,parent, andnamefromSchemaABC(410{.interpreted-text role=”issue”}). ThanksTim-Erwin{.interpreted-text role=”user”} for the PR.
2.6.1 (2016-03-17)
Bug fixes:
- Respect [load_from]{.title-ref} when reporting errors for nested
required fields (
414{.interpreted-text role=”issue”}). Thanksyumike{.interpreted-text role=”user”}.
2.6.0 (2016-02-01)
Features:
- Add
partialargument toSchema.validate(379{.interpreted-text role=”issue”}). Thankstdevelioglu{.interpreted-text role=”user”} for the PR. - Add
equalargument tovalidate.Length. Thanksdaniloakamine{.interpreted-text role=”user”}. - Collect all validation errors for each item deserialized by a
Listfield (345{.interpreted-text role=”issue”}). Thanksmaximkulkin{.interpreted-text role=”user”} for the report and the PR.
2.5.0 (2016-01-16)
Features:
- Allow a tuple of field names to be passed as the
partialargument toSchema.load(369{.interpreted-text role=”issue”}). Thankstdevelioglu{.interpreted-text role=”user”} for the PR. - Add
schemesargument tovalidate.URL(356{.interpreted-text role=”issue”}).
2.4.2 (2015-12-08)
Bug fixes:
- Prevent duplicate error messages when validating nested collections
(
360{.interpreted-text role=”issue”}). Thanksalexmorken{.interpreted-text role=”user”} for the catch and patch.
2.4.1 (2015-12-07)
Bug fixes:
- Serializing an iterator will not drop the first item
(
343{.interpreted-text role=”issue”},353{.interpreted-text role=”issue”}). Thanksjmcarp{.interpreted-text role=”user”} for the patch. Thanksedgarallang{.interpreted-text role=”user”} andjmcarp{.interpreted-text role=”user”} for reporting.
2.4.0 (2015-12-06)
Features:
- Add
skip_on_field_errorsparameter tovalidates_schema(323{.interpreted-text role=”issue”}). Thanksjjvattamattom{.interpreted-text role=”user”} for the suggestion andd-sutherland{.interpreted-text role=”user”} for the PR.
Bug fixes:
- Fix
FormattedStringserialization (348{.interpreted-text role=”issue”}). Thanksacaird{.interpreted-text role=”user”} for reporting. - Fix
@validatesbehavior when used whenattributeis specified andstrict=True(350{.interpreted-text role=”issue”}). Thanksdensity{.interpreted-text role=”user”} for reporting.
2.3.0 (2015-11-22)
Features:
- Add
dump_toparameter to fields (310{.interpreted-text role=”issue”}). ThanksShayanArmanPercolate{.interpreted-text role=”user”} for the suggestion. Thanksfranciscod{.interpreted-text role=”user”} andewang{.interpreted-text role=”user”} for the PRs. - The
deserializefunction passed tofields.Functioncan optionally receive acontextargument (324{.interpreted-text role=”issue”}). ThanksDamianHeard{.interpreted-text role=”user”}. - The
serializefunction passed tofields.Functionis optional (325{.interpreted-text role=”issue”}). Thanks againDamianHeard{.interpreted-text role=”user”}. - The
serializefunction passed tofields.Methodis optional (329{.interpreted-text role=”issue”}). Thanksjustanr{.interpreted-text role=”user”}.
Deprecation/Removal:
- The
funcargument offields.Functionhas been renamed toserialize. - The
method_nameargument offields.Methodhas been renamed toserialize.
func and method_name are still present for backwards-compatibility,
but they will both be removed in marshmallow 3.0.
2.2.1 (2015-11-11)
Bug fixes:
- Skip field validators for fields that aren't included in
only(320{.interpreted-text role=”issue”}). Thankscarlos-alberto{.interpreted-text role=”user”} for reporting andeprikazc{.interpreted-text role=”user”} for the PR.
2.2.0 (2015-10-26)
Features:
- Add support for partial deserialization with the
partialargument toSchemaandSchema.load(290{.interpreted-text role=”issue”}). Thankstaion{.interpreted-text role=”user”}.
Deprecation/Removals:
-
QueryandQuerySelectfields are removed. - Passing of strings to
requiredandallow_noneis removed. Pass theerror_messagesargument instead.
Support:
- Add example of Schema inheritance in docs (
225{.interpreted-text role=”issue”}). Thanksmartinstein{.interpreted-text role=”user”} for the suggestion andjuanrossi{.interpreted-text role=”user”} for the PR. - Add "Customizing Error Messages" section to custom fields docs.
2.1.3 (2015-10-18)
Bug fixes:
- Fix serialization of collections for which [iter]{.title-ref} will
modify position, e.g. Pymongo cursors (
303{.interpreted-text role=”issue”}). ThanksMise{.interpreted-text role=”user”} for the catch and patch.
2.1.2 (2015-10-14)
Bug fixes:
- Fix passing data to schema validator when using
@validates_schema(many=True)(297{.interpreted-text role=”issue”}). Thanksd-sutherland{.interpreted-text role=”user”} for reporting. - Fix usage of
@validateswith a nested field whenmany=True(298{.interpreted-text role=”issue”}). Thanksnelfin{.interpreted-text role=”user”} for the catch and patch.
2.1.1 (2015-10-07)
Bug fixes:
-
Constantfield deserializes to its value regardless of whether its field name is present in input data (291{.interpreted-text role=”issue”}). Thanksfayazkhan{.interpreted-text role=”user”} for reporting.
2.1.0 (2015-09-30)
Features:
- Add
Dictfield for arbitrary mapping data (251{.interpreted-text role=”issue”}). Thanksdwieeb{.interpreted-text role=”user”} for adding this andDowwie{.interpreted-text role=”user”} for the suggestion. - Add
Field.rootproperty, which references the field's Schema.
Deprecation/Removals:
- The
extraparam ofSchemais deprecated. Add extra data in apost_loadmethod instead. -
UnmarshallingErrorandMarshallingErrorare removed.
Bug fixes:
- Fix storing multiple schema-level validation errors
(
287{.interpreted-text role=”issue”}). Thanksevgeny-sureev{.interpreted-text role=”user”} for the patch. - If
missing=Noneon a field,allow_nonewill be set toTrue.
Other changes:
- A
List'sinner field will have the list field set as its parent. Userootto access theSchema.
2.0.0 (2015-09-25)
Features:
- Make error messages configurable at the class level and instance
level (
Field.default_error_messagesattribute anderror_messagesparameter, respectively).
Deprecation/Removals:
- Remove
make_object. Use apost_loadmethod instead (277{.interpreted-text role=”issue”}). - Remove the
errorparameter and attribute ofField. - Passing string arguments to
requiredandallow_noneis deprecated. Pass theerror_messagesargument instead. This API will be removed in version 2.2. - Remove
Arbitrary,Fixed, andPricefields (86{.interpreted-text role=”issue”}). UseDecimalinstead. - Remove
Select/Enumfields (135{.interpreted-text role=”issue”}). Use theOneOfvalidator instead.
Bug fixes:
- Fix error format for
Nestedfields whenmany=True. Thanksalexmorken{.interpreted-text role=”user”}. -
pre_dumpmethods are invoked before implicit field creation. Thanksmakmanalp{.interpreted-text role=”user”} for reporting. - Return correct "required" error message for
Nestedfield. - The
onlyargument passed to aSchemais bounded by thefieldsoption (183{.interpreted-text role=”issue”}). Thankslustdante{.interpreted-text role=”user”} for the suggestion.
Changes from 2.0.0rc2:
-
error_handlerandaccessoroptions are replaced with thehandle_errorandget_attributemethods284{.interpreted-text role=”issue”}. - Remove
marshmallow.compat.plain_functionsince it is no longer used. - Non-collection values are invalid input for
Listfield (231{.interpreted-text role=”issue”}). Thanksdensity{.interpreted-text role=”user”} for reporting. - Bug fix: Prevent infinite loop when validating a required,
self-nested field. Thanks
Bachmann1234{.interpreted-text role=”user”} for the fix.
2.0.0rc2 (2015-09-16)
Deprecation/Removals:
-
make_objectis deprecated. Use apost_loadmethod instead (277{.interpreted-text role=”issue”}). This method will be removed in the final 2.0 release. -
Schema.accessorandSchema.error_handlerdecorators are deprecated. Define theaccessoranderror_handlerclass Meta options instead.
Bug fixes:
- Allow non-field names to be passed to
ValidationError(273{.interpreted-text role=”issue”}). Thanksevgeny-sureev{.interpreted-text role=”user”} for the catch and patch.
Changes from 2.0.0rc1:
- The
rawparameter of thepre_*,post_*,validates_schemadecorators was renamed topass_many(276{.interpreted-text role=”issue”}). - Add
pass_originalparameter topost_loadandpost_dump(216{.interpreted-text role=”issue”}). - Methods decorated with the
pre_*,post_*, andvalidates_*decorators must be instance methods. Class methods and instance methods are not supported at this time.
2.0.0rc1 (2015-09-13)
Features:
-
Backwards-incompatible:
fields.Field._deserializenow takesattranddataas arguments (172{.interpreted-text role=”issue”}). Thanksalexmic{.interpreted-text role=”user”} andkevinastone{.interpreted-text role=”user”} for the suggestion. - Allow a
Field'sattributeto be modified during deserialization (266{.interpreted-text role=”issue”}). Thanksfloqqi{.interpreted-text role=”user”}. - Allow partially-valid data to be returned for
Nestedfields (269{.interpreted-text role=”issue”}). Thanksjomag{.interpreted-text role=”user”} for the suggestion. - Add
Schema.on_bind_fieldhook which allows aSchemato modify its fields when they are bound. - Stricter validation of string, boolean, and number fields
(
231{.interpreted-text role=”issue”}). ThankstouilleMan{.interpreted-text role=”user”} for the suggestion. - Improve consistency of error messages.
Deprecation/Removals:
-
Schema.validator,Schema.preprocessor, andSchema.data_handlerare removed. Usevalidates_schema,pre_load, andpost_dumpinstead. -
QuerySelectandQuerySelectListare deprecated (227{.interpreted-text role=”issue”}). These fields will be removed in version 2.1. -
utils.get_callable_nameis removed.
Bug fixes:
- If a date format string is passed to a
DateTimefield, it is always used for deserialization (248{.interpreted-text role=”issue”}). Thanksbartaelterman{.interpreted-text role=”user”} andpraveen-p{.interpreted-text role=”user”}.
Support:
- Documentation: Add "Using Context" section to "Extending
Schemas" page (
224{.interpreted-text role=”issue”}). - Include tests and docs in release tarballs (
201{.interpreted-text role=”issue”}). - Test against Python 3.5.
2.0.0b5 (2015-08-23)
Features:
- If a field corresponds to a callable attribute, it will be called
upon serialization. Thanks
alexmorken{.interpreted-text role=”user”}. - Add
load_onlyanddump_onlyclass Meta options. Thankskelvinhammond{.interpreted-text role=”user”}. - If a
Nestedfield is required, recursively validate any required fields in the nested schema (235{.interpreted-text role=”issue”}). Thanksmax-orhai{.interpreted-text role=”user”}. - Improve error message if a list of dicts is not passed to a
Nestedfield for whichmany=True. Thanks againmax-orhai{.interpreted-text role=”user”}.
Bug fixes:
- [make_object]{.title-ref} is only called after all validators and
postprocessors have finished (
253{.interpreted-text role=”issue”}). Thankssunsongxp{.interpreted-text role=”user”} for reporting. - If an invalid type is passed to
Schemaandstrict=False, store a_schemaerror in the errors dict rather than raise an exception (261{.interpreted-text role=”issue”}). Thanksdensity{.interpreted-text role=”user”} for reporting.
Other changes:
-
make_objectis only called when input data are completely valid (243{.interpreted-text role=”issue”}). Thankskissgyorgy{.interpreted-text role=”user”} for reporting. - Change default error messages for
URLandEmailvalidators so that they don't include user input (255{.interpreted-text role=”issue”}). -
Emailvalidator permits email addresses with non-ASCII characters, as per RFC 6530 (221{.interpreted-text role=”issue”}). Thankslextoumbourou{.interpreted-text role=”user”} for reporting andmwstobo{.interpreted-text role=”user”} for sending the patch.
2.0.0b4 (2015-07-07)
Features:
-
Listfield respects theattributeargument of the inner field. Thanksjmcarp{.interpreted-text role=”user”}. - The
containerfieldListfield has access to its parentSchemavia itsparentattribute. Thanks againjmcarp{.interpreted-text role=”user”}.
Deprecation/Removals:
- Legacy validator functions have been removed (
73{.interpreted-text role=”issue”}). Use the class-based validators inmarshmallow.validateinstead.
Bug fixes:
-
fields.Nestedcorrectly serializes nestedsets(233{.interpreted-text role=”issue”}). Thankstraut{.interpreted-text role=”user”}.
Changes from 2.0.0b3:
- If
load_fromis used on deserialization, the value ofload_fromis used as the key in the errors dict (232{.interpreted-text role=”issue”}). Thanksalexmorken{.interpreted-text role=”user”}.
2.0.0b3 (2015-06-14)
Features:
- Add
marshmallow.validates_schemadecorator for defining schema-level validators (116{.interpreted-text role=”issue”}). - Add
marshmallow.validatesdecorator for defining field validators as Schema methods (116{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Performance improvements.
- Defining
__marshallable__on complex objects is no longer necessary. - Add
fields.Constant. Thankskevinastone{.interpreted-text role=”user”}.
Deprecation/Removals:
- Remove
skip_missingclass Meta option. By default, missing inputs are excluded from serialized output (211{.interpreted-text role=”issue”}). - Remove optional
contextparameter that gets passed to methods forMethodfields. -
Schema.validatoris deprecated. Usemarshmallow.validates_schemainstead. -
utils.get_func_nameis removed. Useutils.get_callable_nameinstead.
Bug fixes:
- Fix serializing values from keyed tuple types (regression of
28{.interpreted-text role=”issue”}). Thanksmakmanalp{.interpreted-text role=”user”} for reporting.
Other changes:
- Remove unnecessary call to
utils.get_valueforFunctionandMethodfields (208{.interpreted-text role=”issue”}). Thanksjmcarp{.interpreted-text role=”user”}. - Serializing a collection without passing
many=Truewill not result in an error. Be very careful to pass themanyargument when necessary.
Support:
- Documentation: Update Flask and Peewee examples. Update Quickstart.
Changes from 2.0.0b2:
-
Booleanfield serializesNonetoNone, for consistency with other fields (213{.interpreted-text role=”issue”}). Thankscmanallen{.interpreted-text role=”user”} for reporting. - Bug fix:
load_onlyfields do not get validated during serialization. - Implicit passing of original, raw data to Schema validators is
removed. Use
@marshmallow.validates_schema(pass_original=True)instead.
2.0.0b2 (2015-05-03)
Features:
- Add useful
__repr__methods to validators (204{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. -
Backwards-incompatible: By default,
NaN,Infinity, and-Infinityare invalid values forfields.Decimal. Passallow_nan=Trueto allow these values. Thanksphiltay{.interpreted-text role=”user”}.
Changes from 2.0.0b1:
- Fix serialization of
Nonefor [Time]{.title-ref}, [TimeDelta]{.title-ref}, and [Date]{.title-ref} fields (a regression introduced in 2.0.0a1).
Includes bug fixes from 1.2.6.
2.0.0b1 (2015-04-26)
Features:
- Errored fields will not appear in (de)serialized output dictionaries
(
153{.interpreted-text role=”issue”},202{.interpreted-text role=”issue”}). - Instantiate
OPTIONS_CLASSinSchemaMeta. This makesSchema.optsavailable in metaclass methods. It also causes validation to occur earlier (uponSchemaclass declaration rather than instantiation). - Add
SchemaMeta.get_declared_fieldsclass method to support adding additional declared fields.
Deprecation/Removals:
- Remove
allow_nullparameter offields.Nested(203{.interpreted-text role=”issue”}).
Changes from 2.0.0a1:
- Fix serialization of [None]{.title-ref} for
fields.Email.
2.0.0a1 (2015-04-25)
Features:
-
Backwards-incompatible: When
many=True, the errors dictionary returned bydumpandloadwill be keyed on the indices of invalid items in the (de)serialized collection (75{.interpreted-text role=”issue”}). Addindex_errors=Falseon a Schema'sclass Metaoptions to disable this behavior. -
Backwards-incompatible: By default, fields will raise a
ValidationError if the input is
None. Theallow_noneparameter can override this behavior. -
Backwards-incompatible: A
Field'sdefaultparameter is only used if explicitly set and the field's value is missing in the input to [Schema.dump]{.title-ref}. If not set, the key will not be present in the serialized output for missing values . This is the behavior for all fields.fields.Strno longer defaults to'',fields.Intno longer defaults to0, etc. (199{.interpreted-text role=”issue”}). Thanksjmcarp{.interpreted-text role=”user”} for the feedback. - In
strictmode, aValidationErroris raised. Error messages are accessed via theValidationError'smessagesattribute (128{.interpreted-text role=”issue”}). - Add
allow_noneparameter tofields.Field. IfFalse(the default), validation fails when the field's value isNone(76{.interpreted-text role=”issue”},111{.interpreted-text role=”issue”}). Ifallow_noneisTrue,Noneis considered valid and will deserialize toNone. - Schema-level validators can store error messages for multiple fields
(
118{.interpreted-text role=”issue”}). Thanksksesong{.interpreted-text role=”user”} for the suggestion. - Add
pre_load,post_load,pre_dump, andpost_dumpSchema method decorators for defining pre- and post- processing routines (153{.interpreted-text role=”issue”},179{.interpreted-text role=”issue”}). Thanksdavidism{.interpreted-text role=”user”},taion{.interpreted-text role=”user”}, andjmcarp{.interpreted-text role=”user”} for the suggestions and feedback. Thankstaion{.interpreted-text role=”user”} for the implementation. - Error message for
requiredvalidation is configurable. (78{.interpreted-text role=”issue”}). Thankssvenstaro{.interpreted-text role=”user”} for the suggestion. Thanks0xDCA{.interpreted-text role=”user”} for the implementation. - Add
load_fromparameter to fields (125{.interpreted-text role=”issue”}). Thankshakjoon{.interpreted-text role=”user”}. - Add
load_onlyanddump_onlyparameters to fields (61{.interpreted-text role=”issue”},87{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Add [missing]{.title-ref} parameter to fields
(
115{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Schema validators can take an optional
raw_dataargument which contains raw input data, incl. data not specified in the schema (127{.interpreted-text role=”issue”}). Thanksryanlowe0{.interpreted-text role=”user”}. - Add
validate.OneOf(135{.interpreted-text role=”issue”}) andvalidate.ContainsOnly(149{.interpreted-text role=”issue”}) validators. Thanksphiltay{.interpreted-text role=”user”}. - Error messages for validators can be interpolated with [{input}]{.title-ref} and other values (depending on the validator).
-
fields.TimeDeltaalways serializes to an integer value in order to avoid rounding errors (105{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Add
includeclass Meta option to support field names which are Python keywords (139{.interpreted-text role=”issue”}). Thanksnickretallack{.interpreted-text role=”user”} for the suggestion. -
excludeparameter is respected when used together withonlyparameter (165{.interpreted-text role=”issue”}). Thankslustdante{.interpreted-text role=”user”} for the catch and patch. -
fields.Listworks as expected with generators and sets (185{.interpreted-text role=”issue”}). Thankssergey-aganezov-jr{.interpreted-text role=”user”}.
Deprecation/Removals:
-
MarshallingErrorandUnmarshallingErrorerror are deprecated in favor of a singleValidationError(160{.interpreted-text role=”issue”}). -
contextargument passed to Method fields is deprecated. Useself.contextinstead (184{.interpreted-text role=”issue”}). - Remove
ForcedError. - Remove support for generator functions that yield validators
(
74{.interpreted-text role=”issue”}). Plain generators of validators are still supported. - The
Select/Enumfield is deprecated in favor of using [validate.OneOf]{.title-ref} validator (135{.interpreted-text role=”issue”}). - Remove legacy, pre-1.0 API (
Schema.dataandSchema.errorsproperties) (73{.interpreted-text role=”issue”}). - Remove
nullvalue.
Other changes:
-
Marshaller,Unmarshallerwere moved tomarshmallow.marshalling. These should be considered private API (129{.interpreted-text role=”issue”}). - Make
allow_null=Truethe default forNestedfields. This will makeNoneserialize toNonerather than a dictionary with empty values (132{.interpreted-text role=”issue”}). Thanksnickrellack{.interpreted-text role=”user”} for the suggestion.
1.2.6 (2015-05-03)
Bug fixes:
- Fix validation error message for
fields.Decimal. - Allow error message for
fields.Booleanto be customized with theerrorparameter (like other fields).
1.2.5 (2015-04-25)
Bug fixes:
- Fix validation of invalid types passed to a
Nestedfield whenmany=True(188{.interpreted-text role=”issue”}). Thanksjuanrossi{.interpreted-text role=”user”} for reporting.
Support:
- Fix pep8 dev dependency for flake8. Thanks
taion{.interpreted-text role=”user”}.
1.2.4 (2015-03-22)
Bug fixes:
- Fix behavior of
as_stringonfields.Integer(173{.interpreted-text role=”issue”}). Thankstaion{.interpreted-text role=”user”} for the catch and patch.
Other changes:
- Remove dead code from
fields.Field. Thankstaion{.interpreted-text role=”user”}.
Support:
- Correction to
_postprocessmethod in docs. Thanks againtaion{.interpreted-text role=”user”}.
1.2.3 (2015-03-15)
Bug fixes:
- Fix inheritance of
orderedclass Meta option (162{.interpreted-text role=”issue”}). Thanksstephenfin{.interpreted-text role=”user”} for reporting.
1.2.2 (2015-02-23)
Bug fixes:
- Fix behavior of
skip_missingandaccessoroptions whenmany=True(137{.interpreted-text role=”issue”}). Thanks3rdcycle{.interpreted-text role=”user”}. - Fix bug that could cause an
AttributeErrorwhen nesting schemas with schema-level validators (144{.interpreted-text role=”issue”}). Thanksvovanbo{.interpreted-text role=”user”} for reporting.
1.2.1 (2015-01-11)
Bug fixes:
- A
Schema'serror_handler--if defined--will execute ifSchema.validatereturns validation errors (121{.interpreted-text role=”issue”}). - Deserializing [None]{.title-ref} returns [None]{.title-ref} rather
than raising an
AttributeError(123{.interpreted-text role=”issue”}). ThanksRealSalmon{.interpreted-text role=”user”} for the catch and patch.
1.2.0 (2014-12-22)
Features:
- Add
QuerySelectandQuerySelectListfields (84{.interpreted-text role=”issue”}). - Convert validators in
marshmallow.validateinto class-based callables to make them easier to use when declaring fields (85{.interpreted-text role=”issue”}). - Add
Decimalfield which is safe to use when dealing with precise numbers (86{.interpreted-text role=”issue”}).
Thanks philtay{.interpreted-text role=”user”} for these contributions.
Bug fixes:
-
Datefields correctly deserializes to adatetime.dateobject whenpython-dateutilis not installed (79{.interpreted-text role=”issue”}). Thanksmalexer{.interpreted-text role=”user”} for the catch and patch. - Fix bug that raised an
AttributeErrorwhen using a class-based validator. - Fix
as_stringbehavior of Number fields when serializing to default value. - Deserializing
Noneor the empty string with either aDateTime,Date,TimeorTimeDeltaresults in the correct unmarshalling errors (96{.interpreted-text role=”issue”}). Thankssvenstaro{.interpreted-text role=”user”} for reporting and helping with this. - Fix error handling when deserializing invalid UUIDs
(
106{.interpreted-text role=”issue”}). Thanksvesauimonen{.interpreted-text role=”user”} for the catch and patch. -
Schema.loadscorrectly defaults to use the value ofself.manyrather than defaulting toFalse(108{.interpreted-text role=”issue”}). Thanksdavidism{.interpreted-text role=”user”} for the catch and patch. - Validators, data handlers, and preprocessors are no longer shared
between schema subclasses (
88{.interpreted-text role=”issue”}). Thanksamikholap{.interpreted-text role=”user”} for reporting. - Fix error handling when passing a
dictorlistto aValidationError(110{.interpreted-text role=”issue”}). Thanksksesong{.interpreted-text role=”user”} for reporting.
Deprecation:
- The validator functions in the
validatemodule are deprecated in favor of the class-based validators (85{.interpreted-text role=”issue”}). - The
Arbitrary,Price, andFixedfields are deprecated in favor of theDecimalfield (86{.interpreted-text role=”issue”}).
Support:
- Update docs theme.
- Update contributing docs (
77{.interpreted-text role=”issue”}). - Fix namespacing example in "Extending Schema" docs. Thanks
Ch00k{.interpreted-text role=”user”}. - Exclude virtualenv directories from syntax checking
(
99{.interpreted-text role=”issue”}). Thankssvenstaro{.interpreted-text role=”user”}.
1.1.0 (2014-12-02)
Features:
- Add
Schema.validatemethod which validates input data against a schema. Similar toSchema.load, but does not callmake_objectand only returns the errors dictionary. - Add several validation functions to the
validatemodule. Thanksphiltay{.interpreted-text role=”user”}. - Store field name and instance on exceptions raised in
strictmode.
Bug fixes:
- Fix serializing dictionaries when field names are methods of
dict(e.g."items"). Thanksrozenm{.interpreted-text role=”user”} for reporting. - If a Nested field is passed
many=True,Noneserializes to an empty list. Thanksnickretallack{.interpreted-text role=”user”} for reporting. - Fix behavior of
manyargument passed todumpandload. Thankssvenstaro{.interpreted-text role=”user”} for reporting and helping with this. - Fix
skip_missingbehavior forStringandListfields. Thanksmalexer{.interpreted-text role=”user”} for reporting. - Fix compatibility with python-dateutil 2.3.
- More consistent error messages across DateTime, TimeDelta, Date, and Time fields.
Support:
- Update Flask and Peewee examples.
1.0.1 (2014-11-18)
Hotfix release.
- Ensure that errors dictionary is correctly cleared on each call to Schema.dump and Schema.load.
1.0.0 (2014-11-16)
Adds new features, speed improvements, better error handling, and updated documentation.
- Add
skip_missingclass Metaoption. - A field's
defaultmay be a callable. - Allow accessor function to be configured via the
Schema.accessordecorator or the__accessor__class member. -
URLandEmailfields are validated upon serialization. -
dumpandloadcan receive themanyargument. - Move a number of utility functions from fields.py to utils.py.
- More useful
reprforFieldclasses. - If a field's default is
fields.missingand its serialized value isNone, it will not be included in the final serialized result. - Schema.dumps no longer coerces its result to a binary string on Python 3.
-
Backwards-incompatible: Schema output is no longer an
OrderedDictby default. If you want ordered field output, you must explicitly set theorderedoption toTrue. - Backwards-incompatible: [error]{.title-ref} parameter of the [Field]{.title-ref} constructor is deprecated. Raise a [ValidationError]{.title-ref} instead.
- Expanded test coverage.
- Updated docs.
1.0.0-a (2014-10-19)
Major reworking and simplification of the public API, centered around
support for deserialization, improved validation, and a less stateful
Schema class.
- Rename
SerializertoSchema. - Support for deserialization.
- Use the
Schema.dumpandSchema.loadmethods for serializing and deserializing, respectively. -
Backwards-incompatible: Remove
Serializer.jsonandSerializer.to_json. UseSchema.dumpsinstead. - Reworked fields interface.
-
Backwards-incompatible:
Fieldclasses implement_serializeand_deserializemethods.serializeanddeserializecomprise the public API for aField.Field.formatandField.outputhave been removed. - Add
exceptions.ForcedErrorwhich allows errors to be raised during serialization (instead of storing errors in theerrorsdict). -
Backwards-incompatible:
DateTimefield serializes to ISO8601 format by default (instead of RFC822). -
Backwards-incompatible: Remove
Serializer.factorymethod. It is no longer necessary with thedumpmethod. -
Backwards-incompatible: Allow nesting a serializer within itself
recursively. Use
excludeoronlyto prevent infinite recursion. -
Backwards-incompatible: Multiple errors can be stored for a single
field. The errors dictionary returned by
loadanddumphave lists of error messages keyed by field name. - Remove
validateddecorator. Validation occurs withinFieldmethods. -
Functionfield raises aValueErrorif an uncallable object is passed to its constructor. -
Nestedfields inherit context from their parent. - Add
Schema.preprocessorandSchema.validatordecorators for registering preprocessing and schema-level validation functions respectively. - Custom error messages can be specified by raising a
ValidationErrorwithin a validation function. - Extra keyword arguments passed to a Field are stored as metadata.
- Fix ordering of field output.
- Fix behavior of the
requiredparameter onNestedfields. - Fix serializing keyed tuple types (e.g.
namedtuple) withclass Metaoptions. - Fix default value for
FixedandPricefields. - Fix serialization of binary strings.
-
Schemascan inherit fields from non-Schemabase classes (e.g. mixins). Also, fields are inherited according to the MRO (rather than recursing over base classes). Thanksjmcarp{.interpreted-text role=”user”}. - Add
Str,Bool, andIntfield class aliases.
0.7.0 (2014-06-22)
- Add
Serializer.error_handlerdecorator that registers a custom error handler. - Add
Serializer.data_handlerdecorator that registers data post-processing callbacks. -
Backwards-incompatible:
process_datamethod is deprecated. Use thedata_handlerdecorator instead. - Fix bug that raised error when passing
extradata together withmany=True. Thanksbuttsicles{.interpreted-text role=”user”} for reporting. - If
required=Truevalidation is violated for a givenField, it will raise an error message that is different from the message specified by theerrorargument. Thanksasteinlein{.interpreted-text role=”user”}. - More generic error message raised when required field is missing.
-
validateddecorator should only wrap aFieldclass'soutputmethod.
0.6.0 (2014-06-03)
- Fix bug in serializing keyed tuple types, e.g.
namedtupleandKeyedTuple. - Nested field can load a serializer by its class name as a string. This makes it easier to implement 2-way nesting.
- Make Serializer.data override-able.
0.5.5 (2014-05-02)
- Add
Serializer.factoryfor creating a factory function that returns a Serializer instance. -
MarshallingErrorstores its underlying exception as an instance variable. This is useful for inspecting errors. -
fields.Selectis aliased tofields.Enum. - Add
fields.__all__andmarshmallow.__all__so that the modules can be more easily extended. - Expose
Serializer.OPTIONS_CLASSas a class variable so that options defaults can be overridden. - Add
Serializer.process_datahook that allows subclasses to manipulate the final output data.
0.5.4 (2014-04-17)
- Add
json_moduleclass Meta option. - Add
requiredoption to fields . ThanksDeaconDesperado{.interpreted-text role=”user”}. - Tested on Python 3.4 and PyPy.
0.5.3 (2014-03-02)
- Fix
Integerfield default. It is now0instead of0.0. Thankskalasjocke{.interpreted-text role=”user”}. - Add
contextparam toSerializer. Allows accessing arbitrary objects inFunctionandMethodfields. -
FunctionandMethodfields raiseMarshallingErrorif their argument is uncallable.
0.5.2 (2014-02-10)
- Enable custom field validation via the
validateparameter. - Add
utils.from_rfcfor parsing RFC datestring to Python datetime object.
0.5.1 (2014-02-02)
- Avoid unnecessary attribute access in
utils.to_marshallable_typefor improved performance. - Fix RFC822 formatting for localized datetimes.
0.5.0 (2013-12-29)
- Can customize validation error messages by passing the
errorparameter to a field. -
Backwards-incompatible: Rename
fields.NumberField->fields.Number. - Add
fields.Select. Thanksecarreras{.interpreted-text role=”user”}. - Support nesting a Serializer within itself by passing
"self"intofields.Nested(only up to depth=1). -
Backwards-incompatible: No implicit serializing of collections.
Must set
many=Trueif serializing to a list. This ensures that marshmallow handles singular objects correctly, even if they are iterable. - If Nested field
onlyparameter is a field name, only return a single value for the nested object (instead of a dict) or a flat list of values. - Improved performance and stability.
0.4.1 (2013-12-01)
- An object's
__marshallable__method, if defined, takes precedence over__getitem__. - Generator expressions can be passed to a serializer.
- Better support for serializing list-like collections (e.g. ORM querysets).
- Other minor bugfixes.
0.4.0 (2013-11-24)
- Add
additional[class Meta]{.title-ref} option. - Add
dateformat[class Meta]{.title-ref} option. - Support for serializing UUID, date, time, and timedelta objects.
- Remove
Serializer.to_datamethod. Just useSerialize.dataproperty. - String field defaults to empty string instead of
None. -
Backwards-incompatible:
isoformatandrfcformatfunctions moved to utils.py. - Backwards-incompatible: Validation functions moved to validate.py.
- Backwards-incompatible: Remove types.py.
- Reorder parameters to
DateTimefield (first parameter is dateformat). - Ensure that
to_jsonreturns bytestrings. - Fix bug with including an object property in
fieldsMeta option. - Fix bug with passing
Noneto a serializer.
0.3.1 (2013-11-16)
- Fix bug with serializing dictionaries.
- Fix error raised when serializing empty list.
- Add
onlyandexcludeparameters to Serializer constructor. - Add
strictparameter and option: causes Serializer to raise an error if invalid data are passed in, rather than storing errors. - Updated Flask + SQLA example in docs.
0.3.0 (2013-11-14)
- Declaring Serializers just got easier. The class Meta paradigm
allows you to specify fields more concisely. Can specify
fieldsandexcludeoptions. - Allow date formats to be changed by passing
formatparameter toDateTimefield constructor. Can either be"rfc"(default),"iso", or a date format string. - More useful error message when declaring fields as classes (instead of an instance, which is the correct usage).
- Rename MarshallingException -> MarshallingError.
- Rename marshmallow.core -> marshmallow.serializer.
0.2.1 (2013-11-12)
- Allow prefixing field names.
- Fix storing errors on Nested Serializers.
- Python 2.6 support.
0.2.0 (2013-11-11)
- Field-level validation.
- Add
fields.Method. - Add
fields.Function. - Allow binding of extra data to a serialized object by passing the
extraparam when initializing aSerializer. - Add
relativeparamater tofields.Urlthat allows for relative URLs.
0.1.0 (2013-11-10)
- First release.
Wiki Tutorials
Dependant Packages
| Name | Deps |
|---|---|
| webargs | |
| pyros_msgs |
Launch files
Messages
Services
Plugins
Recent questions tagged marshmallow at Robotics Stack Exchange
|
marshmallow package from marshmallow repomarshmallow |
Third-Party Package
This third-party package's source repository does not contain a package manifest. Instead, its package manifest is stored in its release repository. In order to build this package from source in a Catkin workspace, please download its package manifest.Package Summary
| Tags | No category tags. |
| Version | 2.9.1 |
| License | BSD |
| Build type | CATKIN |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/marshmallow-code/marshmallow.git |
| VCS Type | git |
| VCS Version | 2.9.1 |
| Last Updated | 2016-07-22 |
| Dev Status | MAINTAINED |
| CI status | No Continuous Integration |
| Released | RELEASED |
| Tags | No category tags. |
| Contributing |
Help Wanted (0)
Good First Issues (0) Pull Requests to Review (0) |
Package Description
Additional Links
Maintainers
- AlexV
Authors
- Steven Loria
marshmallow: simplified object serialization
marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.
``` {.sourceCode .python} from datetime import date from marshmallow import Schema, fields, pprint
class ArtistSchema(Schema): name = fields.Str()
class AlbumSchema(Schema): title = fields.Str() release_date = fields.Date() artist = fields.Nested(ArtistSchema())
bowie = dict(name=’David Bowie’) album = dict(artist=bowie, title=’Hunky Dory’, release_date=date(1971, 12, 17))
schema = AlbumSchema() result = schema.dump(album) pprint(result.data, indent=2)
{ ‘artist’: {‘name’: ‘David Bowie’},
‘release_date’: ‘1971-12-17’,
‘title’: ‘Hunky Dory’}
```
In short, marshmallow schemas can be used to:
- Validate input data.
- Deserialize input data to app-level objects.
- Serialize app-level objects to primitive Python types. The serialized objects can then be rendered to standard formats such as JSON for use in an HTTP API.
Get It Now
$ pip install -U marshmallow
Documentation
Full documentation is available at http://marshmallow.readthedocs.io/ .
Requirements
- Python >= 2.6 or >= 3.3
marshmallow has no external dependencies outside of the Python standard library, although python-dateutil is recommended for robust datetime deserialization.
Ecosystem
A list of marshmallow-related libraries can be found at the GitHub wiki here:
https://github.com/marshmallow-code/marshmallow/wiki/Ecosystem
Project Links
- Docs: http://marshmallow.readthedocs.io/
- Changelog: http://marshmallow.readthedocs.io/en/latest/changelog.html
- PyPI: https://pypi.python.org/pypi/marshmallow
- Issues: https://github.com/marshmallow-code/marshmallow/issues
License
MIT licensed. See the bundled LICENSE file for more details.
Changelog
2.9.1 (2016-07-21)
Bug fixes:
- Fix serialization of
datetime.timeobjects with microseconds (464{.interpreted-text role=”issue”}). ThanksTim-Erwin{.interpreted-text role=”user”} for reporting and thanksvuonghv{.interpreted-text role=”user”} for the fix. - Make
@validatesconsistent with field validator behavior: if validation fails, the field will not be included in the deserialized output (391{.interpreted-text role=”issue”}). Thanksmartinstein{.interpreted-text role=”user”} for reporting and thanks@vuonghv{.interpreted-text role=”user”} for the fix.
2.9.0 (2016-07-06)
-
Decimalfield coerces input values to a string before deserializing to a [decimal.Decimal]{.title-ref} object in order to avoid transformation of float values under 12 significant digits (434{.interpreted-text role=”issue”},435{.interpreted-text role=”issue”}). Thanksdavidthornton{.interpreted-text role=”user”} for the PR.
2.8.0 (2016-06-23)
Features:
- Allow
onlyandexcludeparameters to take nested fields, using dot-delimited syntax (e.g.only=['blog.author.email']) (402{.interpreted-text role=”issue”}). ThanksTim-Erwin{.interpreted-text role=”user”} anddeckar01{.interpreted-text role=”user”} for the discussion and implementation.
Support:
- Update tasks.py for compatibility with invoke>=0.13.0. Thanks
deckar01{.interpreted-text role=”user”}.
2.7.3 (2016-05-05)
- Make
field.parentandfield.nameaccessible toon_bind_field(449{.interpreted-text role=”issue”}). Thanksimmerrr{.interpreted-text role=”user”}.
2.7.2 (2016-04-27)
No code changes in this release. This is a reupload in order to
distribute an sdist for the last hotfix release. See
443{.interpreted-text role=”issue”}.
Support:
- Update license entry in setup.py to fix RPM distributions
(
433{.interpreted-text role=”issue”}). Thanksrrajaravi{.interpreted-text role=”user”} for reporting.
2.7.1 (2016-04-08)
Bug fixes:
- Only add Schemas to class registry if a class name is provided. This
allows Schemas to be constructed dynamically using the
typeconstructor without getting added to the class registry (which is useful for saving memory).
2.7.0 (2016-04-04)
Features:
- Make context available to
Nestedfield'son_bind_fieldmethod (408{.interpreted-text role=”issue”}). Thanksimmerrr{.interpreted-text role=”user”} for the PR. - Pass through user
ValidationErrorkwargs (418{.interpreted-text role=”issue”}). Thanksrusselldavies{.interpreted-text role=”user”} for helping implement this.
Other changes:
- Remove unused attributes
root,parent, andnamefromSchemaABC(410{.interpreted-text role=”issue”}). ThanksTim-Erwin{.interpreted-text role=”user”} for the PR.
2.6.1 (2016-03-17)
Bug fixes:
- Respect [load_from]{.title-ref} when reporting errors for nested
required fields (
414{.interpreted-text role=”issue”}). Thanksyumike{.interpreted-text role=”user”}.
2.6.0 (2016-02-01)
Features:
- Add
partialargument toSchema.validate(379{.interpreted-text role=”issue”}). Thankstdevelioglu{.interpreted-text role=”user”} for the PR. - Add
equalargument tovalidate.Length. Thanksdaniloakamine{.interpreted-text role=”user”}. - Collect all validation errors for each item deserialized by a
Listfield (345{.interpreted-text role=”issue”}). Thanksmaximkulkin{.interpreted-text role=”user”} for the report and the PR.
2.5.0 (2016-01-16)
Features:
- Allow a tuple of field names to be passed as the
partialargument toSchema.load(369{.interpreted-text role=”issue”}). Thankstdevelioglu{.interpreted-text role=”user”} for the PR. - Add
schemesargument tovalidate.URL(356{.interpreted-text role=”issue”}).
2.4.2 (2015-12-08)
Bug fixes:
- Prevent duplicate error messages when validating nested collections
(
360{.interpreted-text role=”issue”}). Thanksalexmorken{.interpreted-text role=”user”} for the catch and patch.
2.4.1 (2015-12-07)
Bug fixes:
- Serializing an iterator will not drop the first item
(
343{.interpreted-text role=”issue”},353{.interpreted-text role=”issue”}). Thanksjmcarp{.interpreted-text role=”user”} for the patch. Thanksedgarallang{.interpreted-text role=”user”} andjmcarp{.interpreted-text role=”user”} for reporting.
2.4.0 (2015-12-06)
Features:
- Add
skip_on_field_errorsparameter tovalidates_schema(323{.interpreted-text role=”issue”}). Thanksjjvattamattom{.interpreted-text role=”user”} for the suggestion andd-sutherland{.interpreted-text role=”user”} for the PR.
Bug fixes:
- Fix
FormattedStringserialization (348{.interpreted-text role=”issue”}). Thanksacaird{.interpreted-text role=”user”} for reporting. - Fix
@validatesbehavior when used whenattributeis specified andstrict=True(350{.interpreted-text role=”issue”}). Thanksdensity{.interpreted-text role=”user”} for reporting.
2.3.0 (2015-11-22)
Features:
- Add
dump_toparameter to fields (310{.interpreted-text role=”issue”}). ThanksShayanArmanPercolate{.interpreted-text role=”user”} for the suggestion. Thanksfranciscod{.interpreted-text role=”user”} andewang{.interpreted-text role=”user”} for the PRs. - The
deserializefunction passed tofields.Functioncan optionally receive acontextargument (324{.interpreted-text role=”issue”}). ThanksDamianHeard{.interpreted-text role=”user”}. - The
serializefunction passed tofields.Functionis optional (325{.interpreted-text role=”issue”}). Thanks againDamianHeard{.interpreted-text role=”user”}. - The
serializefunction passed tofields.Methodis optional (329{.interpreted-text role=”issue”}). Thanksjustanr{.interpreted-text role=”user”}.
Deprecation/Removal:
- The
funcargument offields.Functionhas been renamed toserialize. - The
method_nameargument offields.Methodhas been renamed toserialize.
func and method_name are still present for backwards-compatibility,
but they will both be removed in marshmallow 3.0.
2.2.1 (2015-11-11)
Bug fixes:
- Skip field validators for fields that aren't included in
only(320{.interpreted-text role=”issue”}). Thankscarlos-alberto{.interpreted-text role=”user”} for reporting andeprikazc{.interpreted-text role=”user”} for the PR.
2.2.0 (2015-10-26)
Features:
- Add support for partial deserialization with the
partialargument toSchemaandSchema.load(290{.interpreted-text role=”issue”}). Thankstaion{.interpreted-text role=”user”}.
Deprecation/Removals:
-
QueryandQuerySelectfields are removed. - Passing of strings to
requiredandallow_noneis removed. Pass theerror_messagesargument instead.
Support:
- Add example of Schema inheritance in docs (
225{.interpreted-text role=”issue”}). Thanksmartinstein{.interpreted-text role=”user”} for the suggestion andjuanrossi{.interpreted-text role=”user”} for the PR. - Add "Customizing Error Messages" section to custom fields docs.
2.1.3 (2015-10-18)
Bug fixes:
- Fix serialization of collections for which [iter]{.title-ref} will
modify position, e.g. Pymongo cursors (
303{.interpreted-text role=”issue”}). ThanksMise{.interpreted-text role=”user”} for the catch and patch.
2.1.2 (2015-10-14)
Bug fixes:
- Fix passing data to schema validator when using
@validates_schema(many=True)(297{.interpreted-text role=”issue”}). Thanksd-sutherland{.interpreted-text role=”user”} for reporting. - Fix usage of
@validateswith a nested field whenmany=True(298{.interpreted-text role=”issue”}). Thanksnelfin{.interpreted-text role=”user”} for the catch and patch.
2.1.1 (2015-10-07)
Bug fixes:
-
Constantfield deserializes to its value regardless of whether its field name is present in input data (291{.interpreted-text role=”issue”}). Thanksfayazkhan{.interpreted-text role=”user”} for reporting.
2.1.0 (2015-09-30)
Features:
- Add
Dictfield for arbitrary mapping data (251{.interpreted-text role=”issue”}). Thanksdwieeb{.interpreted-text role=”user”} for adding this andDowwie{.interpreted-text role=”user”} for the suggestion. - Add
Field.rootproperty, which references the field's Schema.
Deprecation/Removals:
- The
extraparam ofSchemais deprecated. Add extra data in apost_loadmethod instead. -
UnmarshallingErrorandMarshallingErrorare removed.
Bug fixes:
- Fix storing multiple schema-level validation errors
(
287{.interpreted-text role=”issue”}). Thanksevgeny-sureev{.interpreted-text role=”user”} for the patch. - If
missing=Noneon a field,allow_nonewill be set toTrue.
Other changes:
- A
List'sinner field will have the list field set as its parent. Userootto access theSchema.
2.0.0 (2015-09-25)
Features:
- Make error messages configurable at the class level and instance
level (
Field.default_error_messagesattribute anderror_messagesparameter, respectively).
Deprecation/Removals:
- Remove
make_object. Use apost_loadmethod instead (277{.interpreted-text role=”issue”}). - Remove the
errorparameter and attribute ofField. - Passing string arguments to
requiredandallow_noneis deprecated. Pass theerror_messagesargument instead. This API will be removed in version 2.2. - Remove
Arbitrary,Fixed, andPricefields (86{.interpreted-text role=”issue”}). UseDecimalinstead. - Remove
Select/Enumfields (135{.interpreted-text role=”issue”}). Use theOneOfvalidator instead.
Bug fixes:
- Fix error format for
Nestedfields whenmany=True. Thanksalexmorken{.interpreted-text role=”user”}. -
pre_dumpmethods are invoked before implicit field creation. Thanksmakmanalp{.interpreted-text role=”user”} for reporting. - Return correct "required" error message for
Nestedfield. - The
onlyargument passed to aSchemais bounded by thefieldsoption (183{.interpreted-text role=”issue”}). Thankslustdante{.interpreted-text role=”user”} for the suggestion.
Changes from 2.0.0rc2:
-
error_handlerandaccessoroptions are replaced with thehandle_errorandget_attributemethods284{.interpreted-text role=”issue”}. - Remove
marshmallow.compat.plain_functionsince it is no longer used. - Non-collection values are invalid input for
Listfield (231{.interpreted-text role=”issue”}). Thanksdensity{.interpreted-text role=”user”} for reporting. - Bug fix: Prevent infinite loop when validating a required,
self-nested field. Thanks
Bachmann1234{.interpreted-text role=”user”} for the fix.
2.0.0rc2 (2015-09-16)
Deprecation/Removals:
-
make_objectis deprecated. Use apost_loadmethod instead (277{.interpreted-text role=”issue”}). This method will be removed in the final 2.0 release. -
Schema.accessorandSchema.error_handlerdecorators are deprecated. Define theaccessoranderror_handlerclass Meta options instead.
Bug fixes:
- Allow non-field names to be passed to
ValidationError(273{.interpreted-text role=”issue”}). Thanksevgeny-sureev{.interpreted-text role=”user”} for the catch and patch.
Changes from 2.0.0rc1:
- The
rawparameter of thepre_*,post_*,validates_schemadecorators was renamed topass_many(276{.interpreted-text role=”issue”}). - Add
pass_originalparameter topost_loadandpost_dump(216{.interpreted-text role=”issue”}). - Methods decorated with the
pre_*,post_*, andvalidates_*decorators must be instance methods. Class methods and instance methods are not supported at this time.
2.0.0rc1 (2015-09-13)
Features:
-
Backwards-incompatible:
fields.Field._deserializenow takesattranddataas arguments (172{.interpreted-text role=”issue”}). Thanksalexmic{.interpreted-text role=”user”} andkevinastone{.interpreted-text role=”user”} for the suggestion. - Allow a
Field'sattributeto be modified during deserialization (266{.interpreted-text role=”issue”}). Thanksfloqqi{.interpreted-text role=”user”}. - Allow partially-valid data to be returned for
Nestedfields (269{.interpreted-text role=”issue”}). Thanksjomag{.interpreted-text role=”user”} for the suggestion. - Add
Schema.on_bind_fieldhook which allows aSchemato modify its fields when they are bound. - Stricter validation of string, boolean, and number fields
(
231{.interpreted-text role=”issue”}). ThankstouilleMan{.interpreted-text role=”user”} for the suggestion. - Improve consistency of error messages.
Deprecation/Removals:
-
Schema.validator,Schema.preprocessor, andSchema.data_handlerare removed. Usevalidates_schema,pre_load, andpost_dumpinstead. -
QuerySelectandQuerySelectListare deprecated (227{.interpreted-text role=”issue”}). These fields will be removed in version 2.1. -
utils.get_callable_nameis removed.
Bug fixes:
- If a date format string is passed to a
DateTimefield, it is always used for deserialization (248{.interpreted-text role=”issue”}). Thanksbartaelterman{.interpreted-text role=”user”} andpraveen-p{.interpreted-text role=”user”}.
Support:
- Documentation: Add "Using Context" section to "Extending
Schemas" page (
224{.interpreted-text role=”issue”}). - Include tests and docs in release tarballs (
201{.interpreted-text role=”issue”}). - Test against Python 3.5.
2.0.0b5 (2015-08-23)
Features:
- If a field corresponds to a callable attribute, it will be called
upon serialization. Thanks
alexmorken{.interpreted-text role=”user”}. - Add
load_onlyanddump_onlyclass Meta options. Thankskelvinhammond{.interpreted-text role=”user”}. - If a
Nestedfield is required, recursively validate any required fields in the nested schema (235{.interpreted-text role=”issue”}). Thanksmax-orhai{.interpreted-text role=”user”}. - Improve error message if a list of dicts is not passed to a
Nestedfield for whichmany=True. Thanks againmax-orhai{.interpreted-text role=”user”}.
Bug fixes:
- [make_object]{.title-ref} is only called after all validators and
postprocessors have finished (
253{.interpreted-text role=”issue”}). Thankssunsongxp{.interpreted-text role=”user”} for reporting. - If an invalid type is passed to
Schemaandstrict=False, store a_schemaerror in the errors dict rather than raise an exception (261{.interpreted-text role=”issue”}). Thanksdensity{.interpreted-text role=”user”} for reporting.
Other changes:
-
make_objectis only called when input data are completely valid (243{.interpreted-text role=”issue”}). Thankskissgyorgy{.interpreted-text role=”user”} for reporting. - Change default error messages for
URLandEmailvalidators so that they don't include user input (255{.interpreted-text role=”issue”}). -
Emailvalidator permits email addresses with non-ASCII characters, as per RFC 6530 (221{.interpreted-text role=”issue”}). Thankslextoumbourou{.interpreted-text role=”user”} for reporting andmwstobo{.interpreted-text role=”user”} for sending the patch.
2.0.0b4 (2015-07-07)
Features:
-
Listfield respects theattributeargument of the inner field. Thanksjmcarp{.interpreted-text role=”user”}. - The
containerfieldListfield has access to its parentSchemavia itsparentattribute. Thanks againjmcarp{.interpreted-text role=”user”}.
Deprecation/Removals:
- Legacy validator functions have been removed (
73{.interpreted-text role=”issue”}). Use the class-based validators inmarshmallow.validateinstead.
Bug fixes:
-
fields.Nestedcorrectly serializes nestedsets(233{.interpreted-text role=”issue”}). Thankstraut{.interpreted-text role=”user”}.
Changes from 2.0.0b3:
- If
load_fromis used on deserialization, the value ofload_fromis used as the key in the errors dict (232{.interpreted-text role=”issue”}). Thanksalexmorken{.interpreted-text role=”user”}.
2.0.0b3 (2015-06-14)
Features:
- Add
marshmallow.validates_schemadecorator for defining schema-level validators (116{.interpreted-text role=”issue”}). - Add
marshmallow.validatesdecorator for defining field validators as Schema methods (116{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Performance improvements.
- Defining
__marshallable__on complex objects is no longer necessary. - Add
fields.Constant. Thankskevinastone{.interpreted-text role=”user”}.
Deprecation/Removals:
- Remove
skip_missingclass Meta option. By default, missing inputs are excluded from serialized output (211{.interpreted-text role=”issue”}). - Remove optional
contextparameter that gets passed to methods forMethodfields. -
Schema.validatoris deprecated. Usemarshmallow.validates_schemainstead. -
utils.get_func_nameis removed. Useutils.get_callable_nameinstead.
Bug fixes:
- Fix serializing values from keyed tuple types (regression of
28{.interpreted-text role=”issue”}). Thanksmakmanalp{.interpreted-text role=”user”} for reporting.
Other changes:
- Remove unnecessary call to
utils.get_valueforFunctionandMethodfields (208{.interpreted-text role=”issue”}). Thanksjmcarp{.interpreted-text role=”user”}. - Serializing a collection without passing
many=Truewill not result in an error. Be very careful to pass themanyargument when necessary.
Support:
- Documentation: Update Flask and Peewee examples. Update Quickstart.
Changes from 2.0.0b2:
-
Booleanfield serializesNonetoNone, for consistency with other fields (213{.interpreted-text role=”issue”}). Thankscmanallen{.interpreted-text role=”user”} for reporting. - Bug fix:
load_onlyfields do not get validated during serialization. - Implicit passing of original, raw data to Schema validators is
removed. Use
@marshmallow.validates_schema(pass_original=True)instead.
2.0.0b2 (2015-05-03)
Features:
- Add useful
__repr__methods to validators (204{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. -
Backwards-incompatible: By default,
NaN,Infinity, and-Infinityare invalid values forfields.Decimal. Passallow_nan=Trueto allow these values. Thanksphiltay{.interpreted-text role=”user”}.
Changes from 2.0.0b1:
- Fix serialization of
Nonefor [Time]{.title-ref}, [TimeDelta]{.title-ref}, and [Date]{.title-ref} fields (a regression introduced in 2.0.0a1).
Includes bug fixes from 1.2.6.
2.0.0b1 (2015-04-26)
Features:
- Errored fields will not appear in (de)serialized output dictionaries
(
153{.interpreted-text role=”issue”},202{.interpreted-text role=”issue”}). - Instantiate
OPTIONS_CLASSinSchemaMeta. This makesSchema.optsavailable in metaclass methods. It also causes validation to occur earlier (uponSchemaclass declaration rather than instantiation). - Add
SchemaMeta.get_declared_fieldsclass method to support adding additional declared fields.
Deprecation/Removals:
- Remove
allow_nullparameter offields.Nested(203{.interpreted-text role=”issue”}).
Changes from 2.0.0a1:
- Fix serialization of [None]{.title-ref} for
fields.Email.
2.0.0a1 (2015-04-25)
Features:
-
Backwards-incompatible: When
many=True, the errors dictionary returned bydumpandloadwill be keyed on the indices of invalid items in the (de)serialized collection (75{.interpreted-text role=”issue”}). Addindex_errors=Falseon a Schema'sclass Metaoptions to disable this behavior. -
Backwards-incompatible: By default, fields will raise a
ValidationError if the input is
None. Theallow_noneparameter can override this behavior. -
Backwards-incompatible: A
Field'sdefaultparameter is only used if explicitly set and the field's value is missing in the input to [Schema.dump]{.title-ref}. If not set, the key will not be present in the serialized output for missing values . This is the behavior for all fields.fields.Strno longer defaults to'',fields.Intno longer defaults to0, etc. (199{.interpreted-text role=”issue”}). Thanksjmcarp{.interpreted-text role=”user”} for the feedback. - In
strictmode, aValidationErroris raised. Error messages are accessed via theValidationError'smessagesattribute (128{.interpreted-text role=”issue”}). - Add
allow_noneparameter tofields.Field. IfFalse(the default), validation fails when the field's value isNone(76{.interpreted-text role=”issue”},111{.interpreted-text role=”issue”}). Ifallow_noneisTrue,Noneis considered valid and will deserialize toNone. - Schema-level validators can store error messages for multiple fields
(
118{.interpreted-text role=”issue”}). Thanksksesong{.interpreted-text role=”user”} for the suggestion. - Add
pre_load,post_load,pre_dump, andpost_dumpSchema method decorators for defining pre- and post- processing routines (153{.interpreted-text role=”issue”},179{.interpreted-text role=”issue”}). Thanksdavidism{.interpreted-text role=”user”},taion{.interpreted-text role=”user”}, andjmcarp{.interpreted-text role=”user”} for the suggestions and feedback. Thankstaion{.interpreted-text role=”user”} for the implementation. - Error message for
requiredvalidation is configurable. (78{.interpreted-text role=”issue”}). Thankssvenstaro{.interpreted-text role=”user”} for the suggestion. Thanks0xDCA{.interpreted-text role=”user”} for the implementation. - Add
load_fromparameter to fields (125{.interpreted-text role=”issue”}). Thankshakjoon{.interpreted-text role=”user”}. - Add
load_onlyanddump_onlyparameters to fields (61{.interpreted-text role=”issue”},87{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Add [missing]{.title-ref} parameter to fields
(
115{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Schema validators can take an optional
raw_dataargument which contains raw input data, incl. data not specified in the schema (127{.interpreted-text role=”issue”}). Thanksryanlowe0{.interpreted-text role=”user”}. - Add
validate.OneOf(135{.interpreted-text role=”issue”}) andvalidate.ContainsOnly(149{.interpreted-text role=”issue”}) validators. Thanksphiltay{.interpreted-text role=”user”}. - Error messages for validators can be interpolated with [{input}]{.title-ref} and other values (depending on the validator).
-
fields.TimeDeltaalways serializes to an integer value in order to avoid rounding errors (105{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Add
includeclass Meta option to support field names which are Python keywords (139{.interpreted-text role=”issue”}). Thanksnickretallack{.interpreted-text role=”user”} for the suggestion. -
excludeparameter is respected when used together withonlyparameter (165{.interpreted-text role=”issue”}). Thankslustdante{.interpreted-text role=”user”} for the catch and patch. -
fields.Listworks as expected with generators and sets (185{.interpreted-text role=”issue”}). Thankssergey-aganezov-jr{.interpreted-text role=”user”}.
Deprecation/Removals:
-
MarshallingErrorandUnmarshallingErrorerror are deprecated in favor of a singleValidationError(160{.interpreted-text role=”issue”}). -
contextargument passed to Method fields is deprecated. Useself.contextinstead (184{.interpreted-text role=”issue”}). - Remove
ForcedError. - Remove support for generator functions that yield validators
(
74{.interpreted-text role=”issue”}). Plain generators of validators are still supported. - The
Select/Enumfield is deprecated in favor of using [validate.OneOf]{.title-ref} validator (135{.interpreted-text role=”issue”}). - Remove legacy, pre-1.0 API (
Schema.dataandSchema.errorsproperties) (73{.interpreted-text role=”issue”}). - Remove
nullvalue.
Other changes:
-
Marshaller,Unmarshallerwere moved tomarshmallow.marshalling. These should be considered private API (129{.interpreted-text role=”issue”}). - Make
allow_null=Truethe default forNestedfields. This will makeNoneserialize toNonerather than a dictionary with empty values (132{.interpreted-text role=”issue”}). Thanksnickrellack{.interpreted-text role=”user”} for the suggestion.
1.2.6 (2015-05-03)
Bug fixes:
- Fix validation error message for
fields.Decimal. - Allow error message for
fields.Booleanto be customized with theerrorparameter (like other fields).
1.2.5 (2015-04-25)
Bug fixes:
- Fix validation of invalid types passed to a
Nestedfield whenmany=True(188{.interpreted-text role=”issue”}). Thanksjuanrossi{.interpreted-text role=”user”} for reporting.
Support:
- Fix pep8 dev dependency for flake8. Thanks
taion{.interpreted-text role=”user”}.
1.2.4 (2015-03-22)
Bug fixes:
- Fix behavior of
as_stringonfields.Integer(173{.interpreted-text role=”issue”}). Thankstaion{.interpreted-text role=”user”} for the catch and patch.
Other changes:
- Remove dead code from
fields.Field. Thankstaion{.interpreted-text role=”user”}.
Support:
- Correction to
_postprocessmethod in docs. Thanks againtaion{.interpreted-text role=”user”}.
1.2.3 (2015-03-15)
Bug fixes:
- Fix inheritance of
orderedclass Meta option (162{.interpreted-text role=”issue”}). Thanksstephenfin{.interpreted-text role=”user”} for reporting.
1.2.2 (2015-02-23)
Bug fixes:
- Fix behavior of
skip_missingandaccessoroptions whenmany=True(137{.interpreted-text role=”issue”}). Thanks3rdcycle{.interpreted-text role=”user”}. - Fix bug that could cause an
AttributeErrorwhen nesting schemas with schema-level validators (144{.interpreted-text role=”issue”}). Thanksvovanbo{.interpreted-text role=”user”} for reporting.
1.2.1 (2015-01-11)
Bug fixes:
- A
Schema'serror_handler--if defined--will execute ifSchema.validatereturns validation errors (121{.interpreted-text role=”issue”}). - Deserializing [None]{.title-ref} returns [None]{.title-ref} rather
than raising an
AttributeError(123{.interpreted-text role=”issue”}). ThanksRealSalmon{.interpreted-text role=”user”} for the catch and patch.
1.2.0 (2014-12-22)
Features:
- Add
QuerySelectandQuerySelectListfields (84{.interpreted-text role=”issue”}). - Convert validators in
marshmallow.validateinto class-based callables to make them easier to use when declaring fields (85{.interpreted-text role=”issue”}). - Add
Decimalfield which is safe to use when dealing with precise numbers (86{.interpreted-text role=”issue”}).
Thanks philtay{.interpreted-text role=”user”} for these contributions.
Bug fixes:
-
Datefields correctly deserializes to adatetime.dateobject whenpython-dateutilis not installed (79{.interpreted-text role=”issue”}). Thanksmalexer{.interpreted-text role=”user”} for the catch and patch. - Fix bug that raised an
AttributeErrorwhen using a class-based validator. - Fix
as_stringbehavior of Number fields when serializing to default value. - Deserializing
Noneor the empty string with either aDateTime,Date,TimeorTimeDeltaresults in the correct unmarshalling errors (96{.interpreted-text role=”issue”}). Thankssvenstaro{.interpreted-text role=”user”} for reporting and helping with this. - Fix error handling when deserializing invalid UUIDs
(
106{.interpreted-text role=”issue”}). Thanksvesauimonen{.interpreted-text role=”user”} for the catch and patch. -
Schema.loadscorrectly defaults to use the value ofself.manyrather than defaulting toFalse(108{.interpreted-text role=”issue”}). Thanksdavidism{.interpreted-text role=”user”} for the catch and patch. - Validators, data handlers, and preprocessors are no longer shared
between schema subclasses (
88{.interpreted-text role=”issue”}). Thanksamikholap{.interpreted-text role=”user”} for reporting. - Fix error handling when passing a
dictorlistto aValidationError(110{.interpreted-text role=”issue”}). Thanksksesong{.interpreted-text role=”user”} for reporting.
Deprecation:
- The validator functions in the
validatemodule are deprecated in favor of the class-based validators (85{.interpreted-text role=”issue”}). - The
Arbitrary,Price, andFixedfields are deprecated in favor of theDecimalfield (86{.interpreted-text role=”issue”}).
Support:
- Update docs theme.
- Update contributing docs (
77{.interpreted-text role=”issue”}). - Fix namespacing example in "Extending Schema" docs. Thanks
Ch00k{.interpreted-text role=”user”}. - Exclude virtualenv directories from syntax checking
(
99{.interpreted-text role=”issue”}). Thankssvenstaro{.interpreted-text role=”user”}.
1.1.0 (2014-12-02)
Features:
- Add
Schema.validatemethod which validates input data against a schema. Similar toSchema.load, but does not callmake_objectand only returns the errors dictionary. - Add several validation functions to the
validatemodule. Thanksphiltay{.interpreted-text role=”user”}. - Store field name and instance on exceptions raised in
strictmode.
Bug fixes:
- Fix serializing dictionaries when field names are methods of
dict(e.g."items"). Thanksrozenm{.interpreted-text role=”user”} for reporting. - If a Nested field is passed
many=True,Noneserializes to an empty list. Thanksnickretallack{.interpreted-text role=”user”} for reporting. - Fix behavior of
manyargument passed todumpandload. Thankssvenstaro{.interpreted-text role=”user”} for reporting and helping with this. - Fix
skip_missingbehavior forStringandListfields. Thanksmalexer{.interpreted-text role=”user”} for reporting. - Fix compatibility with python-dateutil 2.3.
- More consistent error messages across DateTime, TimeDelta, Date, and Time fields.
Support:
- Update Flask and Peewee examples.
1.0.1 (2014-11-18)
Hotfix release.
- Ensure that errors dictionary is correctly cleared on each call to Schema.dump and Schema.load.
1.0.0 (2014-11-16)
Adds new features, speed improvements, better error handling, and updated documentation.
- Add
skip_missingclass Metaoption. - A field's
defaultmay be a callable. - Allow accessor function to be configured via the
Schema.accessordecorator or the__accessor__class member. -
URLandEmailfields are validated upon serialization. -
dumpandloadcan receive themanyargument. - Move a number of utility functions from fields.py to utils.py.
- More useful
reprforFieldclasses. - If a field's default is
fields.missingand its serialized value isNone, it will not be included in the final serialized result. - Schema.dumps no longer coerces its result to a binary string on Python 3.
-
Backwards-incompatible: Schema output is no longer an
OrderedDictby default. If you want ordered field output, you must explicitly set theorderedoption toTrue. - Backwards-incompatible: [error]{.title-ref} parameter of the [Field]{.title-ref} constructor is deprecated. Raise a [ValidationError]{.title-ref} instead.
- Expanded test coverage.
- Updated docs.
1.0.0-a (2014-10-19)
Major reworking and simplification of the public API, centered around
support for deserialization, improved validation, and a less stateful
Schema class.
- Rename
SerializertoSchema. - Support for deserialization.
- Use the
Schema.dumpandSchema.loadmethods for serializing and deserializing, respectively. -
Backwards-incompatible: Remove
Serializer.jsonandSerializer.to_json. UseSchema.dumpsinstead. - Reworked fields interface.
-
Backwards-incompatible:
Fieldclasses implement_serializeand_deserializemethods.serializeanddeserializecomprise the public API for aField.Field.formatandField.outputhave been removed. - Add
exceptions.ForcedErrorwhich allows errors to be raised during serialization (instead of storing errors in theerrorsdict). -
Backwards-incompatible:
DateTimefield serializes to ISO8601 format by default (instead of RFC822). -
Backwards-incompatible: Remove
Serializer.factorymethod. It is no longer necessary with thedumpmethod. -
Backwards-incompatible: Allow nesting a serializer within itself
recursively. Use
excludeoronlyto prevent infinite recursion. -
Backwards-incompatible: Multiple errors can be stored for a single
field. The errors dictionary returned by
loadanddumphave lists of error messages keyed by field name. - Remove
validateddecorator. Validation occurs withinFieldmethods. -
Functionfield raises aValueErrorif an uncallable object is passed to its constructor. -
Nestedfields inherit context from their parent. - Add
Schema.preprocessorandSchema.validatordecorators for registering preprocessing and schema-level validation functions respectively. - Custom error messages can be specified by raising a
ValidationErrorwithin a validation function. - Extra keyword arguments passed to a Field are stored as metadata.
- Fix ordering of field output.
- Fix behavior of the
requiredparameter onNestedfields. - Fix serializing keyed tuple types (e.g.
namedtuple) withclass Metaoptions. - Fix default value for
FixedandPricefields. - Fix serialization of binary strings.
-
Schemascan inherit fields from non-Schemabase classes (e.g. mixins). Also, fields are inherited according to the MRO (rather than recursing over base classes). Thanksjmcarp{.interpreted-text role=”user”}. - Add
Str,Bool, andIntfield class aliases.
0.7.0 (2014-06-22)
- Add
Serializer.error_handlerdecorator that registers a custom error handler. - Add
Serializer.data_handlerdecorator that registers data post-processing callbacks. -
Backwards-incompatible:
process_datamethod is deprecated. Use thedata_handlerdecorator instead. - Fix bug that raised error when passing
extradata together withmany=True. Thanksbuttsicles{.interpreted-text role=”user”} for reporting. - If
required=Truevalidation is violated for a givenField, it will raise an error message that is different from the message specified by theerrorargument. Thanksasteinlein{.interpreted-text role=”user”}. - More generic error message raised when required field is missing.
-
validateddecorator should only wrap aFieldclass'soutputmethod.
0.6.0 (2014-06-03)
- Fix bug in serializing keyed tuple types, e.g.
namedtupleandKeyedTuple. - Nested field can load a serializer by its class name as a string. This makes it easier to implement 2-way nesting.
- Make Serializer.data override-able.
0.5.5 (2014-05-02)
- Add
Serializer.factoryfor creating a factory function that returns a Serializer instance. -
MarshallingErrorstores its underlying exception as an instance variable. This is useful for inspecting errors. -
fields.Selectis aliased tofields.Enum. - Add
fields.__all__andmarshmallow.__all__so that the modules can be more easily extended. - Expose
Serializer.OPTIONS_CLASSas a class variable so that options defaults can be overridden. - Add
Serializer.process_datahook that allows subclasses to manipulate the final output data.
0.5.4 (2014-04-17)
- Add
json_moduleclass Meta option. - Add
requiredoption to fields . ThanksDeaconDesperado{.interpreted-text role=”user”}. - Tested on Python 3.4 and PyPy.
0.5.3 (2014-03-02)
- Fix
Integerfield default. It is now0instead of0.0. Thankskalasjocke{.interpreted-text role=”user”}. - Add
contextparam toSerializer. Allows accessing arbitrary objects inFunctionandMethodfields. -
FunctionandMethodfields raiseMarshallingErrorif their argument is uncallable.
0.5.2 (2014-02-10)
- Enable custom field validation via the
validateparameter. - Add
utils.from_rfcfor parsing RFC datestring to Python datetime object.
0.5.1 (2014-02-02)
- Avoid unnecessary attribute access in
utils.to_marshallable_typefor improved performance. - Fix RFC822 formatting for localized datetimes.
0.5.0 (2013-12-29)
- Can customize validation error messages by passing the
errorparameter to a field. -
Backwards-incompatible: Rename
fields.NumberField->fields.Number. - Add
fields.Select. Thanksecarreras{.interpreted-text role=”user”}. - Support nesting a Serializer within itself by passing
"self"intofields.Nested(only up to depth=1). -
Backwards-incompatible: No implicit serializing of collections.
Must set
many=Trueif serializing to a list. This ensures that marshmallow handles singular objects correctly, even if they are iterable. - If Nested field
onlyparameter is a field name, only return a single value for the nested object (instead of a dict) or a flat list of values. - Improved performance and stability.
0.4.1 (2013-12-01)
- An object's
__marshallable__method, if defined, takes precedence over__getitem__. - Generator expressions can be passed to a serializer.
- Better support for serializing list-like collections (e.g. ORM querysets).
- Other minor bugfixes.
0.4.0 (2013-11-24)
- Add
additional[class Meta]{.title-ref} option. - Add
dateformat[class Meta]{.title-ref} option. - Support for serializing UUID, date, time, and timedelta objects.
- Remove
Serializer.to_datamethod. Just useSerialize.dataproperty. - String field defaults to empty string instead of
None. -
Backwards-incompatible:
isoformatandrfcformatfunctions moved to utils.py. - Backwards-incompatible: Validation functions moved to validate.py.
- Backwards-incompatible: Remove types.py.
- Reorder parameters to
DateTimefield (first parameter is dateformat). - Ensure that
to_jsonreturns bytestrings. - Fix bug with including an object property in
fieldsMeta option. - Fix bug with passing
Noneto a serializer.
0.3.1 (2013-11-16)
- Fix bug with serializing dictionaries.
- Fix error raised when serializing empty list.
- Add
onlyandexcludeparameters to Serializer constructor. - Add
strictparameter and option: causes Serializer to raise an error if invalid data are passed in, rather than storing errors. - Updated Flask + SQLA example in docs.
0.3.0 (2013-11-14)
- Declaring Serializers just got easier. The class Meta paradigm
allows you to specify fields more concisely. Can specify
fieldsandexcludeoptions. - Allow date formats to be changed by passing
formatparameter toDateTimefield constructor. Can either be"rfc"(default),"iso", or a date format string. - More useful error message when declaring fields as classes (instead of an instance, which is the correct usage).
- Rename MarshallingException -> MarshallingError.
- Rename marshmallow.core -> marshmallow.serializer.
0.2.1 (2013-11-12)
- Allow prefixing field names.
- Fix storing errors on Nested Serializers.
- Python 2.6 support.
0.2.0 (2013-11-11)
- Field-level validation.
- Add
fields.Method. - Add
fields.Function. - Allow binding of extra data to a serialized object by passing the
extraparam when initializing aSerializer. - Add
relativeparamater tofields.Urlthat allows for relative URLs.
0.1.0 (2013-11-10)
- First release.
Wiki Tutorials
Dependant Packages
| Name | Deps |
|---|---|
| webargs |
Launch files
Messages
Services
Plugins
Recent questions tagged marshmallow at Robotics Stack Exchange
|
marshmallow package from marshmallow repomarshmallow |
Third-Party Package
This third-party package's source repository does not contain a package manifest. Instead, its package manifest is stored in its release repository. In order to build this package from source in a Catkin workspace, please download its package manifest.Package Summary
| Tags | No category tags. |
| Version | 2.9.1 |
| License | BSD |
| Build type | CATKIN |
| Use | RECOMMENDED |
Repository Summary
| Checkout URI | https://github.com/marshmallow-code/marshmallow.git |
| VCS Type | git |
| VCS Version | 2.9.1 |
| Last Updated | 2016-07-22 |
| Dev Status | MAINTAINED |
| CI status | No Continuous Integration |
| Released | RELEASED |
| Tags | No category tags. |
| Contributing |
Help Wanted (0)
Good First Issues (0) Pull Requests to Review (0) |
Package Description
Additional Links
Maintainers
- AlexV
Authors
- Steven Loria
marshmallow: simplified object serialization
marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.
``` {.sourceCode .python} from datetime import date from marshmallow import Schema, fields, pprint
class ArtistSchema(Schema): name = fields.Str()
class AlbumSchema(Schema): title = fields.Str() release_date = fields.Date() artist = fields.Nested(ArtistSchema())
bowie = dict(name=’David Bowie’) album = dict(artist=bowie, title=’Hunky Dory’, release_date=date(1971, 12, 17))
schema = AlbumSchema() result = schema.dump(album) pprint(result.data, indent=2)
{ ‘artist’: {‘name’: ‘David Bowie’},
‘release_date’: ‘1971-12-17’,
‘title’: ‘Hunky Dory’}
```
In short, marshmallow schemas can be used to:
- Validate input data.
- Deserialize input data to app-level objects.
- Serialize app-level objects to primitive Python types. The serialized objects can then be rendered to standard formats such as JSON for use in an HTTP API.
Get It Now
$ pip install -U marshmallow
Documentation
Full documentation is available at http://marshmallow.readthedocs.io/ .
Requirements
- Python >= 2.6 or >= 3.3
marshmallow has no external dependencies outside of the Python standard library, although python-dateutil is recommended for robust datetime deserialization.
Ecosystem
A list of marshmallow-related libraries can be found at the GitHub wiki here:
https://github.com/marshmallow-code/marshmallow/wiki/Ecosystem
Project Links
- Docs: http://marshmallow.readthedocs.io/
- Changelog: http://marshmallow.readthedocs.io/en/latest/changelog.html
- PyPI: https://pypi.python.org/pypi/marshmallow
- Issues: https://github.com/marshmallow-code/marshmallow/issues
License
MIT licensed. See the bundled LICENSE file for more details.
Changelog
2.9.1 (2016-07-21)
Bug fixes:
- Fix serialization of
datetime.timeobjects with microseconds (464{.interpreted-text role=”issue”}). ThanksTim-Erwin{.interpreted-text role=”user”} for reporting and thanksvuonghv{.interpreted-text role=”user”} for the fix. - Make
@validatesconsistent with field validator behavior: if validation fails, the field will not be included in the deserialized output (391{.interpreted-text role=”issue”}). Thanksmartinstein{.interpreted-text role=”user”} for reporting and thanks@vuonghv{.interpreted-text role=”user”} for the fix.
2.9.0 (2016-07-06)
-
Decimalfield coerces input values to a string before deserializing to a [decimal.Decimal]{.title-ref} object in order to avoid transformation of float values under 12 significant digits (434{.interpreted-text role=”issue”},435{.interpreted-text role=”issue”}). Thanksdavidthornton{.interpreted-text role=”user”} for the PR.
2.8.0 (2016-06-23)
Features:
- Allow
onlyandexcludeparameters to take nested fields, using dot-delimited syntax (e.g.only=['blog.author.email']) (402{.interpreted-text role=”issue”}). ThanksTim-Erwin{.interpreted-text role=”user”} anddeckar01{.interpreted-text role=”user”} for the discussion and implementation.
Support:
- Update tasks.py for compatibility with invoke>=0.13.0. Thanks
deckar01{.interpreted-text role=”user”}.
2.7.3 (2016-05-05)
- Make
field.parentandfield.nameaccessible toon_bind_field(449{.interpreted-text role=”issue”}). Thanksimmerrr{.interpreted-text role=”user”}.
2.7.2 (2016-04-27)
No code changes in this release. This is a reupload in order to
distribute an sdist for the last hotfix release. See
443{.interpreted-text role=”issue”}.
Support:
- Update license entry in setup.py to fix RPM distributions
(
433{.interpreted-text role=”issue”}). Thanksrrajaravi{.interpreted-text role=”user”} for reporting.
2.7.1 (2016-04-08)
Bug fixes:
- Only add Schemas to class registry if a class name is provided. This
allows Schemas to be constructed dynamically using the
typeconstructor without getting added to the class registry (which is useful for saving memory).
2.7.0 (2016-04-04)
Features:
- Make context available to
Nestedfield'son_bind_fieldmethod (408{.interpreted-text role=”issue”}). Thanksimmerrr{.interpreted-text role=”user”} for the PR. - Pass through user
ValidationErrorkwargs (418{.interpreted-text role=”issue”}). Thanksrusselldavies{.interpreted-text role=”user”} for helping implement this.
Other changes:
- Remove unused attributes
root,parent, andnamefromSchemaABC(410{.interpreted-text role=”issue”}). ThanksTim-Erwin{.interpreted-text role=”user”} for the PR.
2.6.1 (2016-03-17)
Bug fixes:
- Respect [load_from]{.title-ref} when reporting errors for nested
required fields (
414{.interpreted-text role=”issue”}). Thanksyumike{.interpreted-text role=”user”}.
2.6.0 (2016-02-01)
Features:
- Add
partialargument toSchema.validate(379{.interpreted-text role=”issue”}). Thankstdevelioglu{.interpreted-text role=”user”} for the PR. - Add
equalargument tovalidate.Length. Thanksdaniloakamine{.interpreted-text role=”user”}. - Collect all validation errors for each item deserialized by a
Listfield (345{.interpreted-text role=”issue”}). Thanksmaximkulkin{.interpreted-text role=”user”} for the report and the PR.
2.5.0 (2016-01-16)
Features:
- Allow a tuple of field names to be passed as the
partialargument toSchema.load(369{.interpreted-text role=”issue”}). Thankstdevelioglu{.interpreted-text role=”user”} for the PR. - Add
schemesargument tovalidate.URL(356{.interpreted-text role=”issue”}).
2.4.2 (2015-12-08)
Bug fixes:
- Prevent duplicate error messages when validating nested collections
(
360{.interpreted-text role=”issue”}). Thanksalexmorken{.interpreted-text role=”user”} for the catch and patch.
2.4.1 (2015-12-07)
Bug fixes:
- Serializing an iterator will not drop the first item
(
343{.interpreted-text role=”issue”},353{.interpreted-text role=”issue”}). Thanksjmcarp{.interpreted-text role=”user”} for the patch. Thanksedgarallang{.interpreted-text role=”user”} andjmcarp{.interpreted-text role=”user”} for reporting.
2.4.0 (2015-12-06)
Features:
- Add
skip_on_field_errorsparameter tovalidates_schema(323{.interpreted-text role=”issue”}). Thanksjjvattamattom{.interpreted-text role=”user”} for the suggestion andd-sutherland{.interpreted-text role=”user”} for the PR.
Bug fixes:
- Fix
FormattedStringserialization (348{.interpreted-text role=”issue”}). Thanksacaird{.interpreted-text role=”user”} for reporting. - Fix
@validatesbehavior when used whenattributeis specified andstrict=True(350{.interpreted-text role=”issue”}). Thanksdensity{.interpreted-text role=”user”} for reporting.
2.3.0 (2015-11-22)
Features:
- Add
dump_toparameter to fields (310{.interpreted-text role=”issue”}). ThanksShayanArmanPercolate{.interpreted-text role=”user”} for the suggestion. Thanksfranciscod{.interpreted-text role=”user”} andewang{.interpreted-text role=”user”} for the PRs. - The
deserializefunction passed tofields.Functioncan optionally receive acontextargument (324{.interpreted-text role=”issue”}). ThanksDamianHeard{.interpreted-text role=”user”}. - The
serializefunction passed tofields.Functionis optional (325{.interpreted-text role=”issue”}). Thanks againDamianHeard{.interpreted-text role=”user”}. - The
serializefunction passed tofields.Methodis optional (329{.interpreted-text role=”issue”}). Thanksjustanr{.interpreted-text role=”user”}.
Deprecation/Removal:
- The
funcargument offields.Functionhas been renamed toserialize. - The
method_nameargument offields.Methodhas been renamed toserialize.
func and method_name are still present for backwards-compatibility,
but they will both be removed in marshmallow 3.0.
2.2.1 (2015-11-11)
Bug fixes:
- Skip field validators for fields that aren't included in
only(320{.interpreted-text role=”issue”}). Thankscarlos-alberto{.interpreted-text role=”user”} for reporting andeprikazc{.interpreted-text role=”user”} for the PR.
2.2.0 (2015-10-26)
Features:
- Add support for partial deserialization with the
partialargument toSchemaandSchema.load(290{.interpreted-text role=”issue”}). Thankstaion{.interpreted-text role=”user”}.
Deprecation/Removals:
-
QueryandQuerySelectfields are removed. - Passing of strings to
requiredandallow_noneis removed. Pass theerror_messagesargument instead.
Support:
- Add example of Schema inheritance in docs (
225{.interpreted-text role=”issue”}). Thanksmartinstein{.interpreted-text role=”user”} for the suggestion andjuanrossi{.interpreted-text role=”user”} for the PR. - Add "Customizing Error Messages" section to custom fields docs.
2.1.3 (2015-10-18)
Bug fixes:
- Fix serialization of collections for which [iter]{.title-ref} will
modify position, e.g. Pymongo cursors (
303{.interpreted-text role=”issue”}). ThanksMise{.interpreted-text role=”user”} for the catch and patch.
2.1.2 (2015-10-14)
Bug fixes:
- Fix passing data to schema validator when using
@validates_schema(many=True)(297{.interpreted-text role=”issue”}). Thanksd-sutherland{.interpreted-text role=”user”} for reporting. - Fix usage of
@validateswith a nested field whenmany=True(298{.interpreted-text role=”issue”}). Thanksnelfin{.interpreted-text role=”user”} for the catch and patch.
2.1.1 (2015-10-07)
Bug fixes:
-
Constantfield deserializes to its value regardless of whether its field name is present in input data (291{.interpreted-text role=”issue”}). Thanksfayazkhan{.interpreted-text role=”user”} for reporting.
2.1.0 (2015-09-30)
Features:
- Add
Dictfield for arbitrary mapping data (251{.interpreted-text role=”issue”}). Thanksdwieeb{.interpreted-text role=”user”} for adding this andDowwie{.interpreted-text role=”user”} for the suggestion. - Add
Field.rootproperty, which references the field's Schema.
Deprecation/Removals:
- The
extraparam ofSchemais deprecated. Add extra data in apost_loadmethod instead. -
UnmarshallingErrorandMarshallingErrorare removed.
Bug fixes:
- Fix storing multiple schema-level validation errors
(
287{.interpreted-text role=”issue”}). Thanksevgeny-sureev{.interpreted-text role=”user”} for the patch. - If
missing=Noneon a field,allow_nonewill be set toTrue.
Other changes:
- A
List'sinner field will have the list field set as its parent. Userootto access theSchema.
2.0.0 (2015-09-25)
Features:
- Make error messages configurable at the class level and instance
level (
Field.default_error_messagesattribute anderror_messagesparameter, respectively).
Deprecation/Removals:
- Remove
make_object. Use apost_loadmethod instead (277{.interpreted-text role=”issue”}). - Remove the
errorparameter and attribute ofField. - Passing string arguments to
requiredandallow_noneis deprecated. Pass theerror_messagesargument instead. This API will be removed in version 2.2. - Remove
Arbitrary,Fixed, andPricefields (86{.interpreted-text role=”issue”}). UseDecimalinstead. - Remove
Select/Enumfields (135{.interpreted-text role=”issue”}). Use theOneOfvalidator instead.
Bug fixes:
- Fix error format for
Nestedfields whenmany=True. Thanksalexmorken{.interpreted-text role=”user”}. -
pre_dumpmethods are invoked before implicit field creation. Thanksmakmanalp{.interpreted-text role=”user”} for reporting. - Return correct "required" error message for
Nestedfield. - The
onlyargument passed to aSchemais bounded by thefieldsoption (183{.interpreted-text role=”issue”}). Thankslustdante{.interpreted-text role=”user”} for the suggestion.
Changes from 2.0.0rc2:
-
error_handlerandaccessoroptions are replaced with thehandle_errorandget_attributemethods284{.interpreted-text role=”issue”}. - Remove
marshmallow.compat.plain_functionsince it is no longer used. - Non-collection values are invalid input for
Listfield (231{.interpreted-text role=”issue”}). Thanksdensity{.interpreted-text role=”user”} for reporting. - Bug fix: Prevent infinite loop when validating a required,
self-nested field. Thanks
Bachmann1234{.interpreted-text role=”user”} for the fix.
2.0.0rc2 (2015-09-16)
Deprecation/Removals:
-
make_objectis deprecated. Use apost_loadmethod instead (277{.interpreted-text role=”issue”}). This method will be removed in the final 2.0 release. -
Schema.accessorandSchema.error_handlerdecorators are deprecated. Define theaccessoranderror_handlerclass Meta options instead.
Bug fixes:
- Allow non-field names to be passed to
ValidationError(273{.interpreted-text role=”issue”}). Thanksevgeny-sureev{.interpreted-text role=”user”} for the catch and patch.
Changes from 2.0.0rc1:
- The
rawparameter of thepre_*,post_*,validates_schemadecorators was renamed topass_many(276{.interpreted-text role=”issue”}). - Add
pass_originalparameter topost_loadandpost_dump(216{.interpreted-text role=”issue”}). - Methods decorated with the
pre_*,post_*, andvalidates_*decorators must be instance methods. Class methods and instance methods are not supported at this time.
2.0.0rc1 (2015-09-13)
Features:
-
Backwards-incompatible:
fields.Field._deserializenow takesattranddataas arguments (172{.interpreted-text role=”issue”}). Thanksalexmic{.interpreted-text role=”user”} andkevinastone{.interpreted-text role=”user”} for the suggestion. - Allow a
Field'sattributeto be modified during deserialization (266{.interpreted-text role=”issue”}). Thanksfloqqi{.interpreted-text role=”user”}. - Allow partially-valid data to be returned for
Nestedfields (269{.interpreted-text role=”issue”}). Thanksjomag{.interpreted-text role=”user”} for the suggestion. - Add
Schema.on_bind_fieldhook which allows aSchemato modify its fields when they are bound. - Stricter validation of string, boolean, and number fields
(
231{.interpreted-text role=”issue”}). ThankstouilleMan{.interpreted-text role=”user”} for the suggestion. - Improve consistency of error messages.
Deprecation/Removals:
-
Schema.validator,Schema.preprocessor, andSchema.data_handlerare removed. Usevalidates_schema,pre_load, andpost_dumpinstead. -
QuerySelectandQuerySelectListare deprecated (227{.interpreted-text role=”issue”}). These fields will be removed in version 2.1. -
utils.get_callable_nameis removed.
Bug fixes:
- If a date format string is passed to a
DateTimefield, it is always used for deserialization (248{.interpreted-text role=”issue”}). Thanksbartaelterman{.interpreted-text role=”user”} andpraveen-p{.interpreted-text role=”user”}.
Support:
- Documentation: Add "Using Context" section to "Extending
Schemas" page (
224{.interpreted-text role=”issue”}). - Include tests and docs in release tarballs (
201{.interpreted-text role=”issue”}). - Test against Python 3.5.
2.0.0b5 (2015-08-23)
Features:
- If a field corresponds to a callable attribute, it will be called
upon serialization. Thanks
alexmorken{.interpreted-text role=”user”}. - Add
load_onlyanddump_onlyclass Meta options. Thankskelvinhammond{.interpreted-text role=”user”}. - If a
Nestedfield is required, recursively validate any required fields in the nested schema (235{.interpreted-text role=”issue”}). Thanksmax-orhai{.interpreted-text role=”user”}. - Improve error message if a list of dicts is not passed to a
Nestedfield for whichmany=True. Thanks againmax-orhai{.interpreted-text role=”user”}.
Bug fixes:
- [make_object]{.title-ref} is only called after all validators and
postprocessors have finished (
253{.interpreted-text role=”issue”}). Thankssunsongxp{.interpreted-text role=”user”} for reporting. - If an invalid type is passed to
Schemaandstrict=False, store a_schemaerror in the errors dict rather than raise an exception (261{.interpreted-text role=”issue”}). Thanksdensity{.interpreted-text role=”user”} for reporting.
Other changes:
-
make_objectis only called when input data are completely valid (243{.interpreted-text role=”issue”}). Thankskissgyorgy{.interpreted-text role=”user”} for reporting. - Change default error messages for
URLandEmailvalidators so that they don't include user input (255{.interpreted-text role=”issue”}). -
Emailvalidator permits email addresses with non-ASCII characters, as per RFC 6530 (221{.interpreted-text role=”issue”}). Thankslextoumbourou{.interpreted-text role=”user”} for reporting andmwstobo{.interpreted-text role=”user”} for sending the patch.
2.0.0b4 (2015-07-07)
Features:
-
Listfield respects theattributeargument of the inner field. Thanksjmcarp{.interpreted-text role=”user”}. - The
containerfieldListfield has access to its parentSchemavia itsparentattribute. Thanks againjmcarp{.interpreted-text role=”user”}.
Deprecation/Removals:
- Legacy validator functions have been removed (
73{.interpreted-text role=”issue”}). Use the class-based validators inmarshmallow.validateinstead.
Bug fixes:
-
fields.Nestedcorrectly serializes nestedsets(233{.interpreted-text role=”issue”}). Thankstraut{.interpreted-text role=”user”}.
Changes from 2.0.0b3:
- If
load_fromis used on deserialization, the value ofload_fromis used as the key in the errors dict (232{.interpreted-text role=”issue”}). Thanksalexmorken{.interpreted-text role=”user”}.
2.0.0b3 (2015-06-14)
Features:
- Add
marshmallow.validates_schemadecorator for defining schema-level validators (116{.interpreted-text role=”issue”}). - Add
marshmallow.validatesdecorator for defining field validators as Schema methods (116{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Performance improvements.
- Defining
__marshallable__on complex objects is no longer necessary. - Add
fields.Constant. Thankskevinastone{.interpreted-text role=”user”}.
Deprecation/Removals:
- Remove
skip_missingclass Meta option. By default, missing inputs are excluded from serialized output (211{.interpreted-text role=”issue”}). - Remove optional
contextparameter that gets passed to methods forMethodfields. -
Schema.validatoris deprecated. Usemarshmallow.validates_schemainstead. -
utils.get_func_nameis removed. Useutils.get_callable_nameinstead.
Bug fixes:
- Fix serializing values from keyed tuple types (regression of
28{.interpreted-text role=”issue”}). Thanksmakmanalp{.interpreted-text role=”user”} for reporting.
Other changes:
- Remove unnecessary call to
utils.get_valueforFunctionandMethodfields (208{.interpreted-text role=”issue”}). Thanksjmcarp{.interpreted-text role=”user”}. - Serializing a collection without passing
many=Truewill not result in an error. Be very careful to pass themanyargument when necessary.
Support:
- Documentation: Update Flask and Peewee examples. Update Quickstart.
Changes from 2.0.0b2:
-
Booleanfield serializesNonetoNone, for consistency with other fields (213{.interpreted-text role=”issue”}). Thankscmanallen{.interpreted-text role=”user”} for reporting. - Bug fix:
load_onlyfields do not get validated during serialization. - Implicit passing of original, raw data to Schema validators is
removed. Use
@marshmallow.validates_schema(pass_original=True)instead.
2.0.0b2 (2015-05-03)
Features:
- Add useful
__repr__methods to validators (204{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. -
Backwards-incompatible: By default,
NaN,Infinity, and-Infinityare invalid values forfields.Decimal. Passallow_nan=Trueto allow these values. Thanksphiltay{.interpreted-text role=”user”}.
Changes from 2.0.0b1:
- Fix serialization of
Nonefor [Time]{.title-ref}, [TimeDelta]{.title-ref}, and [Date]{.title-ref} fields (a regression introduced in 2.0.0a1).
Includes bug fixes from 1.2.6.
2.0.0b1 (2015-04-26)
Features:
- Errored fields will not appear in (de)serialized output dictionaries
(
153{.interpreted-text role=”issue”},202{.interpreted-text role=”issue”}). - Instantiate
OPTIONS_CLASSinSchemaMeta. This makesSchema.optsavailable in metaclass methods. It also causes validation to occur earlier (uponSchemaclass declaration rather than instantiation). - Add
SchemaMeta.get_declared_fieldsclass method to support adding additional declared fields.
Deprecation/Removals:
- Remove
allow_nullparameter offields.Nested(203{.interpreted-text role=”issue”}).
Changes from 2.0.0a1:
- Fix serialization of [None]{.title-ref} for
fields.Email.
2.0.0a1 (2015-04-25)
Features:
-
Backwards-incompatible: When
many=True, the errors dictionary returned bydumpandloadwill be keyed on the indices of invalid items in the (de)serialized collection (75{.interpreted-text role=”issue”}). Addindex_errors=Falseon a Schema'sclass Metaoptions to disable this behavior. -
Backwards-incompatible: By default, fields will raise a
ValidationError if the input is
None. Theallow_noneparameter can override this behavior. -
Backwards-incompatible: A
Field'sdefaultparameter is only used if explicitly set and the field's value is missing in the input to [Schema.dump]{.title-ref}. If not set, the key will not be present in the serialized output for missing values . This is the behavior for all fields.fields.Strno longer defaults to'',fields.Intno longer defaults to0, etc. (199{.interpreted-text role=”issue”}). Thanksjmcarp{.interpreted-text role=”user”} for the feedback. - In
strictmode, aValidationErroris raised. Error messages are accessed via theValidationError'smessagesattribute (128{.interpreted-text role=”issue”}). - Add
allow_noneparameter tofields.Field. IfFalse(the default), validation fails when the field's value isNone(76{.interpreted-text role=”issue”},111{.interpreted-text role=”issue”}). Ifallow_noneisTrue,Noneis considered valid and will deserialize toNone. - Schema-level validators can store error messages for multiple fields
(
118{.interpreted-text role=”issue”}). Thanksksesong{.interpreted-text role=”user”} for the suggestion. - Add
pre_load,post_load,pre_dump, andpost_dumpSchema method decorators for defining pre- and post- processing routines (153{.interpreted-text role=”issue”},179{.interpreted-text role=”issue”}). Thanksdavidism{.interpreted-text role=”user”},taion{.interpreted-text role=”user”}, andjmcarp{.interpreted-text role=”user”} for the suggestions and feedback. Thankstaion{.interpreted-text role=”user”} for the implementation. - Error message for
requiredvalidation is configurable. (78{.interpreted-text role=”issue”}). Thankssvenstaro{.interpreted-text role=”user”} for the suggestion. Thanks0xDCA{.interpreted-text role=”user”} for the implementation. - Add
load_fromparameter to fields (125{.interpreted-text role=”issue”}). Thankshakjoon{.interpreted-text role=”user”}. - Add
load_onlyanddump_onlyparameters to fields (61{.interpreted-text role=”issue”},87{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Add [missing]{.title-ref} parameter to fields
(
115{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Schema validators can take an optional
raw_dataargument which contains raw input data, incl. data not specified in the schema (127{.interpreted-text role=”issue”}). Thanksryanlowe0{.interpreted-text role=”user”}. - Add
validate.OneOf(135{.interpreted-text role=”issue”}) andvalidate.ContainsOnly(149{.interpreted-text role=”issue”}) validators. Thanksphiltay{.interpreted-text role=”user”}. - Error messages for validators can be interpolated with [{input}]{.title-ref} and other values (depending on the validator).
-
fields.TimeDeltaalways serializes to an integer value in order to avoid rounding errors (105{.interpreted-text role=”issue”}). Thanksphiltay{.interpreted-text role=”user”}. - Add
includeclass Meta option to support field names which are Python keywords (139{.interpreted-text role=”issue”}). Thanksnickretallack{.interpreted-text role=”user”} for the suggestion. -
excludeparameter is respected when used together withonlyparameter (165{.interpreted-text role=”issue”}). Thankslustdante{.interpreted-text role=”user”} for the catch and patch. -
fields.Listworks as expected with generators and sets (185{.interpreted-text role=”issue”}). Thankssergey-aganezov-jr{.interpreted-text role=”user”}.
Deprecation/Removals:
-
MarshallingErrorandUnmarshallingErrorerror are deprecated in favor of a singleValidationError(160{.interpreted-text role=”issue”}). -
contextargument passed to Method fields is deprecated. Useself.contextinstead (184{.interpreted-text role=”issue”}). - Remove
ForcedError. - Remove support for generator functions that yield validators
(
74{.interpreted-text role=”issue”}). Plain generators of validators are still supported. - The
Select/Enumfield is deprecated in favor of using [validate.OneOf]{.title-ref} validator (135{.interpreted-text role=”issue”}). - Remove legacy, pre-1.0 API (
Schema.dataandSchema.errorsproperties) (73{.interpreted-text role=”issue”}). - Remove
nullvalue.
Other changes:
-
Marshaller,Unmarshallerwere moved tomarshmallow.marshalling. These should be considered private API (129{.interpreted-text role=”issue”}). - Make
allow_null=Truethe default forNestedfields. This will makeNoneserialize toNonerather than a dictionary with empty values (132{.interpreted-text role=”issue”}). Thanksnickrellack{.interpreted-text role=”user”} for the suggestion.
1.2.6 (2015-05-03)
Bug fixes:
- Fix validation error message for
fields.Decimal. - Allow error message for
fields.Booleanto be customized with theerrorparameter (like other fields).
1.2.5 (2015-04-25)
Bug fixes:
- Fix validation of invalid types passed to a
Nestedfield whenmany=True(188{.interpreted-text role=”issue”}). Thanksjuanrossi{.interpreted-text role=”user”} for reporting.
Support:
- Fix pep8 dev dependency for flake8. Thanks
taion{.interpreted-text role=”user”}.
1.2.4 (2015-03-22)
Bug fixes:
- Fix behavior of
as_stringonfields.Integer(173{.interpreted-text role=”issue”}). Thankstaion{.interpreted-text role=”user”} for the catch and patch.
Other changes:
- Remove dead code from
fields.Field. Thankstaion{.interpreted-text role=”user”}.
Support:
- Correction to
_postprocessmethod in docs. Thanks againtaion{.interpreted-text role=”user”}.
1.2.3 (2015-03-15)
Bug fixes:
- Fix inheritance of
orderedclass Meta option (162{.interpreted-text role=”issue”}). Thanksstephenfin{.interpreted-text role=”user”} for reporting.
1.2.2 (2015-02-23)
Bug fixes:
- Fix behavior of
skip_missingandaccessoroptions whenmany=True(137{.interpreted-text role=”issue”}). Thanks3rdcycle{.interpreted-text role=”user”}. - Fix bug that could cause an
AttributeErrorwhen nesting schemas with schema-level validators (144{.interpreted-text role=”issue”}). Thanksvovanbo{.interpreted-text role=”user”} for reporting.
1.2.1 (2015-01-11)
Bug fixes:
- A
Schema'serror_handler--if defined--will execute ifSchema.validatereturns validation errors (121{.interpreted-text role=”issue”}). - Deserializing [None]{.title-ref} returns [None]{.title-ref} rather
than raising an
AttributeError(123{.interpreted-text role=”issue”}). ThanksRealSalmon{.interpreted-text role=”user”} for the catch and patch.
1.2.0 (2014-12-22)
Features:
- Add
QuerySelectandQuerySelectListfields (84{.interpreted-text role=”issue”}). - Convert validators in
marshmallow.validateinto class-based callables to make them easier to use when declaring fields (85{.interpreted-text role=”issue”}). - Add
Decimalfield which is safe to use when dealing with precise numbers (86{.interpreted-text role=”issue”}).
Thanks philtay{.interpreted-text role=”user”} for these contributions.
Bug fixes:
-
Datefields correctly deserializes to adatetime.dateobject whenpython-dateutilis not installed (79{.interpreted-text role=”issue”}). Thanksmalexer{.interpreted-text role=”user”} for the catch and patch. - Fix bug that raised an
AttributeErrorwhen using a class-based validator. - Fix
as_stringbehavior of Number fields when serializing to default value. - Deserializing
Noneor the empty string with either aDateTime,Date,TimeorTimeDeltaresults in the correct unmarshalling errors (96{.interpreted-text role=”issue”}). Thankssvenstaro{.interpreted-text role=”user”} for reporting and helping with this. - Fix error handling when deserializing invalid UUIDs
(
106{.interpreted-text role=”issue”}). Thanksvesauimonen{.interpreted-text role=”user”} for the catch and patch. -
Schema.loadscorrectly defaults to use the value ofself.manyrather than defaulting toFalse(108{.interpreted-text role=”issue”}). Thanksdavidism{.interpreted-text role=”user”} for the catch and patch. - Validators, data handlers, and preprocessors are no longer shared
between schema subclasses (
88{.interpreted-text role=”issue”}). Thanksamikholap{.interpreted-text role=”user”} for reporting. - Fix error handling when passing a
dictorlistto aValidationError(110{.interpreted-text role=”issue”}). Thanksksesong{.interpreted-text role=”user”} for reporting.
Deprecation:
- The validator functions in the
validatemodule are deprecated in favor of the class-based validators (85{.interpreted-text role=”issue”}). - The
Arbitrary,Price, andFixedfields are deprecated in favor of theDecimalfield (86{.interpreted-text role=”issue”}).
Support:
- Update docs theme.
- Update contributing docs (
77{.interpreted-text role=”issue”}). - Fix namespacing example in "Extending Schema" docs. Thanks
Ch00k{.interpreted-text role=”user”}. - Exclude virtualenv directories from syntax checking
(
99{.interpreted-text role=”issue”}). Thankssvenstaro{.interpreted-text role=”user”}.
1.1.0 (2014-12-02)
Features:
- Add
Schema.validatemethod which validates input data against a schema. Similar toSchema.load, but does not callmake_objectand only returns the errors dictionary. - Add several validation functions to the
validatemodule. Thanksphiltay{.interpreted-text role=”user”}. - Store field name and instance on exceptions raised in
strictmode.
Bug fixes:
- Fix serializing dictionaries when field names are methods of
dict(e.g."items"). Thanksrozenm{.interpreted-text role=”user”} for reporting. - If a Nested field is passed
many=True,Noneserializes to an empty list. Thanksnickretallack{.interpreted-text role=”user”} for reporting. - Fix behavior of
manyargument passed todumpandload. Thankssvenstaro{.interpreted-text role=”user”} for reporting and helping with this. - Fix
skip_missingbehavior forStringandListfields. Thanksmalexer{.interpreted-text role=”user”} for reporting. - Fix compatibility with python-dateutil 2.3.
- More consistent error messages across DateTime, TimeDelta, Date, and Time fields.
Support:
- Update Flask and Peewee examples.
1.0.1 (2014-11-18)
Hotfix release.
- Ensure that errors dictionary is correctly cleared on each call to Schema.dump and Schema.load.
1.0.0 (2014-11-16)
Adds new features, speed improvements, better error handling, and updated documentation.
- Add
skip_missingclass Metaoption. - A field's
defaultmay be a callable. - Allow accessor function to be configured via the
Schema.accessordecorator or the__accessor__class member. -
URLandEmailfields are validated upon serialization. -
dumpandloadcan receive themanyargument. - Move a number of utility functions from fields.py to utils.py.
- More useful
reprforFieldclasses. - If a field's default is
fields.missingand its serialized value isNone, it will not be included in the final serialized result. - Schema.dumps no longer coerces its result to a binary string on Python 3.
-
Backwards-incompatible: Schema output is no longer an
OrderedDictby default. If you want ordered field output, you must explicitly set theorderedoption toTrue. - Backwards-incompatible: [error]{.title-ref} parameter of the [Field]{.title-ref} constructor is deprecated. Raise a [ValidationError]{.title-ref} instead.
- Expanded test coverage.
- Updated docs.
1.0.0-a (2014-10-19)
Major reworking and simplification of the public API, centered around
support for deserialization, improved validation, and a less stateful
Schema class.
- Rename
SerializertoSchema. - Support for deserialization.
- Use the
Schema.dumpandSchema.loadmethods for serializing and deserializing, respectively. -
Backwards-incompatible: Remove
Serializer.jsonandSerializer.to_json. UseSchema.dumpsinstead. - Reworked fields interface.
-
Backwards-incompatible:
Fieldclasses implement_serializeand_deserializemethods.serializeanddeserializecomprise the public API for aField.Field.formatandField.outputhave been removed. - Add
exceptions.ForcedErrorwhich allows errors to be raised during serialization (instead of storing errors in theerrorsdict). -
Backwards-incompatible:
DateTimefield serializes to ISO8601 format by default (instead of RFC822). -
Backwards-incompatible: Remove
Serializer.factorymethod. It is no longer necessary with thedumpmethod. -
Backwards-incompatible: Allow nesting a serializer within itself
recursively. Use
excludeoronlyto prevent infinite recursion. -
Backwards-incompatible: Multiple errors can be stored for a single
field. The errors dictionary returned by
loadanddumphave lists of error messages keyed by field name. - Remove
validateddecorator. Validation occurs withinFieldmethods. -
Functionfield raises aValueErrorif an uncallable object is passed to its constructor. -
Nestedfields inherit context from their parent. - Add
Schema.preprocessorandSchema.validatordecorators for registering preprocessing and schema-level validation functions respectively. - Custom error messages can be specified by raising a
ValidationErrorwithin a validation function. - Extra keyword arguments passed to a Field are stored as metadata.
- Fix ordering of field output.
- Fix behavior of the
requiredparameter onNestedfields. - Fix serializing keyed tuple types (e.g.
namedtuple) withclass Metaoptions. - Fix default value for
FixedandPricefields. - Fix serialization of binary strings.
-
Schemascan inherit fields from non-Schemabase classes (e.g. mixins). Also, fields are inherited according to the MRO (rather than recursing over base classes). Thanksjmcarp{.interpreted-text role=”user”}. - Add
Str,Bool, andIntfield class aliases.
0.7.0 (2014-06-22)
- Add
Serializer.error_handlerdecorator that registers a custom error handler. - Add
Serializer.data_handlerdecorator that registers data post-processing callbacks. -
Backwards-incompatible:
process_datamethod is deprecated. Use thedata_handlerdecorator instead. - Fix bug that raised error when passing
extradata together withmany=True. Thanksbuttsicles{.interpreted-text role=”user”} for reporting. - If
required=Truevalidation is violated for a givenField, it will raise an error message that is different from the message specified by theerrorargument. Thanksasteinlein{.interpreted-text role=”user”}. - More generic error message raised when required field is missing.
-
validateddecorator should only wrap aFieldclass'soutputmethod.
0.6.0 (2014-06-03)
- Fix bug in serializing keyed tuple types, e.g.
namedtupleandKeyedTuple. - Nested field can load a serializer by its class name as a string. This makes it easier to implement 2-way nesting.
- Make Serializer.data override-able.
0.5.5 (2014-05-02)
- Add
Serializer.factoryfor creating a factory function that returns a Serializer instance. -
MarshallingErrorstores its underlying exception as an instance variable. This is useful for inspecting errors. -
fields.Selectis aliased tofields.Enum. - Add
fields.__all__andmarshmallow.__all__so that the modules can be more easily extended. - Expose
Serializer.OPTIONS_CLASSas a class variable so that options defaults can be overridden. - Add
Serializer.process_datahook that allows subclasses to manipulate the final output data.
0.5.4 (2014-04-17)
- Add
json_moduleclass Meta option. - Add
requiredoption to fields . ThanksDeaconDesperado{.interpreted-text role=”user”}. - Tested on Python 3.4 and PyPy.
0.5.3 (2014-03-02)
- Fix
Integerfield default. It is now0instead of0.0. Thankskalasjocke{.interpreted-text role=”user”}. - Add
contextparam toSerializer. Allows accessing arbitrary objects inFunctionandMethodfields. -
FunctionandMethodfields raiseMarshallingErrorif their argument is uncallable.
0.5.2 (2014-02-10)
- Enable custom field validation via the
validateparameter. - Add
utils.from_rfcfor parsing RFC datestring to Python datetime object.
0.5.1 (2014-02-02)
- Avoid unnecessary attribute access in
utils.to_marshallable_typefor improved performance. - Fix RFC822 formatting for localized datetimes.
0.5.0 (2013-12-29)
- Can customize validation error messages by passing the
errorparameter to a field. -
Backwards-incompatible: Rename
fields.NumberField->fields.Number. - Add
fields.Select. Thanksecarreras{.interpreted-text role=”user”}. - Support nesting a Serializer within itself by passing
"self"intofields.Nested(only up to depth=1). -
Backwards-incompatible: No implicit serializing of collections.
Must set
many=Trueif serializing to a list. This ensures that marshmallow handles singular objects correctly, even if they are iterable. - If Nested field
onlyparameter is a field name, only return a single value for the nested object (instead of a dict) or a flat list of values. - Improved performance and stability.
0.4.1 (2013-12-01)
- An object's
__marshallable__method, if defined, takes precedence over__getitem__. - Generator expressions can be passed to a serializer.
- Better support for serializing list-like collections (e.g. ORM querysets).
- Other minor bugfixes.
0.4.0 (2013-11-24)
- Add
additional[class Meta]{.title-ref} option. - Add
dateformat[class Meta]{.title-ref} option. - Support for serializing UUID, date, time, and timedelta objects.
- Remove
Serializer.to_datamethod. Just useSerialize.dataproperty. - String field defaults to empty string instead of
None. -
Backwards-incompatible:
isoformatandrfcformatfunctions moved to utils.py. - Backwards-incompatible: Validation functions moved to validate.py.
- Backwards-incompatible: Remove types.py.
- Reorder parameters to
DateTimefield (first parameter is dateformat). - Ensure that
to_jsonreturns bytestrings. - Fix bug with including an object property in
fieldsMeta option. - Fix bug with passing
Noneto a serializer.
0.3.1 (2013-11-16)
- Fix bug with serializing dictionaries.
- Fix error raised when serializing empty list.
- Add
onlyandexcludeparameters to Serializer constructor. - Add
strictparameter and option: causes Serializer to raise an error if invalid data are passed in, rather than storing errors. - Updated Flask + SQLA example in docs.
0.3.0 (2013-11-14)
- Declaring Serializers just got easier. The class Meta paradigm
allows you to specify fields more concisely. Can specify
fieldsandexcludeoptions. - Allow date formats to be changed by passing
formatparameter toDateTimefield constructor. Can either be"rfc"(default),"iso", or a date format string. - More useful error message when declaring fields as classes (instead of an instance, which is the correct usage).
- Rename MarshallingException -> MarshallingError.
- Rename marshmallow.core -> marshmallow.serializer.
0.2.1 (2013-11-12)
- Allow prefixing field names.
- Fix storing errors on Nested Serializers.
- Python 2.6 support.
0.2.0 (2013-11-11)
- Field-level validation.
- Add
fields.Method. - Add
fields.Function. - Allow binding of extra data to a serialized object by passing the
extraparam when initializing aSerializer. - Add
relativeparamater tofields.Urlthat allows for relative URLs.
0.1.0 (2013-11-10)
- First release.
Wiki Tutorials
Dependant Packages
| Name | Deps |
|---|---|
| webargs |