Mongoengine integration with the marshmallow (de)serialization library
Project description
marshmallow-mongoengine
Mongoengine integration with the marshmallow (de)serialization library.
See documentation at http://marshmallow-mongoengine.rtfd.org/
Declare your models
import mongoengine as me
class Author(me.Document):
id = me.IntField(primary_key=True, default=1)
name = me.StringField()
books = me.ListField(me.ReferenceField('Book'))
def __repr__(self):
return '<Author(name={self.name!r})>'.format(self=self)
class Book(me.Document):
title = me.StringField()
Generate marshmallow schemas
from marshmallow_mongoengine import ModelSchema
class AuthorSchema(ModelSchema):
class Meta:
model = Author
class BookSchema(ModelSchema):
class Meta:
model = Book
author_schema = AuthorSchema()
(De)serialize your data
author = Author(name='Chuck Paluhniuk').save()
book = Book(title='Fight Club', author=author).save()
dump_data = author_schema.dump(author).data
# {'id': 1, 'name': 'Chuck Paluhniuk', 'books': ['5578726b7a58012298a5a7e2']}
author_schema.load(dump_data).data
# <Author(name='Chuck Paluhniuk')>
Get it now
pip install -U marshmallow-mongoengine
License
MIT licensed. See the bundled LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for marshmallow-mongoengine-0.8.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53c868ecf09952843f3cd45facfa64de7ad0a9202de2a720c3d0595a6a3e0143 |
|
MD5 | f21c41185b7afd15a078b27caa9ef11c |
|
BLAKE2b-256 | 8b2d8d90ac0770c21d440a54922dc023660f7000413d8598210e4666749ec4e1 |