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
Built Distribution
Close
Hashes for marshmallow-mongoengine-0.31.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d38da075b9f2c44685a64f3de78780a61d2c7d3608e9e574de83d4ff725447e |
|
MD5 | ced6c78f5264654718c5a4f08873b309 |
|
BLAKE2b-256 | 76bdddbf02fd3d7fb9570a36e0f053890321daf64fa42c2bc31d6d6df029d5f9 |
Close
Hashes for marshmallow_mongoengine-0.31.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c27edb44499b2623a60275dbfdaaac3f5963446320f4f78f6d70a667eae9e919 |
|
MD5 | e06afbb3f3f81fedf4831b8995421273 |
|
BLAKE2b-256 | 12f10506373a435c82304f85d09eb6bc9c6885785cb8fe296a9fb1b1147ac9a2 |