Mongoengine integration with the marshmallow (de)serialization library
Project description
marshmallow-mongoengine
Mongoengine integration with the marshmallow (de)serialization library.
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.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5374e8fd499f7071cf76ce995c383f3fc9b070cdadeeb8530b2101d6f97592f |
|
MD5 | 05674b923100d477a40962774fae3d64 |
|
BLAKE2b-256 | c0474c011737d80a99f68392a77a478102d6e3863ba556ce67ed2b97e86a1917 |
Close
Hashes for marshmallow_mongoengine-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76c833b1085af4bcede6cea8e51886cfd9bbce549d73ca20ee17d683768d347d |
|
MD5 | ecc763e2966fc04b20a605e6945d2161 |
|
BLAKE2b-256 | a265473a5d283ad893edc15d0917066736d63ad84026d62f26e7d45381387fbc |