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.6.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b02022cec6564f0eb37f5c2c11317c7d6c16e4816c96b4619a4a363f1b860023 |
|
MD5 | 29f04ef0bf272fbcdcfa3db2b6e0152b |
|
BLAKE2b-256 | 13a3438190db5d4bf24028b24f4d8077203fd06ad92952374e1770f087aa757a |
Close
Hashes for marshmallow_mongoengine-0.6.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af9cb1fd9ea2d3e0b8055ce9b36f5894978986ad6d266669cc80afde4cff0518 |
|
MD5 | 5e2e4e89fdb313c7af598eff0df7f87c |
|
BLAKE2b-256 | e016d2db8a552c7d11dd0c3d68cc76cf73602824ba3671586c85c8b84b23c54a |