Package: marshmallow-models
Marshmallow Models==================Installation------------```pip install marshmallow-models```Contributing------------Feature requests, feedback,[issues](https://github.com/douglas-treadwell/marshmallow-models/issues),and pull requests are welcome and appreciated.Please follow the [Marshmallow Contributing Guidelines](https://github.com/marshmallow-code/marshmallow/blob/dev/CONTRIBUTING.rst).Overview--------Inspired by [Schematics](https://github.com/schematics/schematics),powered by [Marshmallow](https://github.com/marshmallow-code/marshmallow).Whereas Marshmallow is an excellent serialization/deserializationand validation library, it wasn't intended to be a class or typedefinition library, which Schematics was.This library provides a Schematics-like Model butusing Marshmallow's Fields and validation.  This library alsointentionally maintains the usage style of marshmallow so thatusers of Marshmallow Schemas will be able to use these Models easily.Usage-----Models are defined like Schemas, but whereas a Schema is instantiatedwith parameters and then used to schema.dump(data) or schema.load(data),or schema.validate(data),Models are instantiated, attributes may be assigned to them, and thenthey can be .dump()'d, .dumps()'d or .validate()'d.### Basic Usage```pythonfrom marshmallow_models import Modelfrom marshmallow.fields import String, Integerclass PersonModel(Model):name = String(required=True)age = Integer(required=True)person = PersonModel()person.name = 'Tester'person.age = 100# or equivalently:person = PersonModel({'name': 'Tester', 'age': 100})# or equivalently:person = PersonModel(name='Tester', age=100)# throws marshmallow.exceptions.ValidationError if invalidperson.validate()person.dump().data  # {'name': 'Tester', 'age': 100}```### Missing and Default Attributes```pythonclass PersonModel(Model):name = String(missing='Anonymous')age = Integer(default=0)person = PersonModel()person.name  # 'Anonymous'person.age  # 0```Default and missing parameters may be provided as they are toMarshmallow Schemas.Constructing a model is treated like"loading" data (as in, schema.load(data)).  If attributes aremissing and a `missing` configuration was provided, those valueswill be assigned to the missing attributes.Reading attributes is treated like "dumping" data (as in,schema.dump(data)), as are calls to model.dump() and dumps().If a value doesn't exist when read or dumped, the default valuewill be substituted for that attribute.In many cases `default` and `missing` can be used interchangeablyin the context of Models, but there may be cases where theirdifferent treatment is meaningful.### Nested ModelsNested models are also supported.```pythonclass ParentModel(PersonModel):child = NestedModel(PersonModel)parent = ParentModel(name='Tester', age=40, child=dict(name='Child', age=10))self.assertEqual(parent.child.name, 'Child')parent.child.name = 'Kid'self.assertEqual(parent.child.name, 'Kid')```Configuration-------------Marshmallow Models support the "class Meta" configuration method.An additional Meta attribute is supported: `strict_constructor`.In Marshmallow Schemas, transformation of input data to output datawas a single step process.  In Marshmallow Models, it might bereasonable for users to instantiate a model with incomplete attributesand then fill in the attributes before attempting to validate() ordump() the data.By default, even for Models with `strict = True`the constructor does not raise exceptions for incomplete attributes.If exceptions are wanted in this case, set `strict_constructor = True`.```pythonclass PersonWithStrictConstructorModel(Model):class Meta:strict_constructor = Truename = String(required=True)age = Integer(required=True)with self.assertRaises(ValidationError):person = PersonWithStrictConstructorModel()```