Mongoengine integration with marshmallow
Clone or download
Latest commit 2122370 Jan 30, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Change docs theme Feb 18, 2016
marshmallow_mongoengine Bump version: 0.7.6 → 0.7.7 Jun 28, 2016
tests Add tests for email and url fields conversions Jun 24, 2016
.gitignore Initial commit Jun 26, 2015
.travis.yml Add coveralls support Feb 26, 2016
LICENSE Initial commit Jun 26, 2015
MANIFEST.in Initial commit Jun 26, 2015
README.rst Update README.rst Jan 30, 2017
dev-requirements.txt Initial commit Jun 26, 2015
setup.cfg Bump version: 0.7.6 → 0.7.7 Jun 28, 2016
setup.py Correct PEP8 Jan 30, 2017
tox.ini Add Python 3.5 in travis Jan 26, 2016

README.rst

Repository has changed !

Marshmallow-Mongoengine is now part of the MongoEngine project.

Travis-CI Documentation Status Code Coverage

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.