Skip to main content

Object models with validation and serialization using Marshmallow fields and validators.

Project description

Marshmallow Models
==================


Inspired by [Schematics](https://github.com/schematics/schematics).

Whereas Marshmallow is an excellent serialization/deserialization
and validation library, it wasn't intended to be a class or type
definition library, which Schematics was.

This library provides a Schematics-like Model but
using Marshmallow's Fields and validation.


Usage
-----

Models are defined like Schemas, but whereas a Schema is instantiated
with 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 then
they can be .dump()'d, .dumps()'d or .validate()'d.

```python
from marshmallow_models import Model
from marshmallow.fields import String, Integer

class PersonModel(Model):
name = String(required=True, default='Anonymous')
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 invalid
person.validate()

person.dump().data # {'name': 'Tester', 'age': 100}
```

Configuration
-------------

Marshmallow Models support the "class Meta" configuration method,
and also support defining the "class Meta" using the alias
"class Options".


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for marshmallow-models, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size marshmallow_models-0.1.0-py2.py3-none-any.whl (5.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size marshmallow_models-0.1.0.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page