Skip to main content

Mongoengine integration with the marshmallow (de)serialization library

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

marshmallow-mongoengine-0.7.8.tar.gz (9.5 kB view details)

Uploaded Source

File details

Details for the file marshmallow-mongoengine-0.7.8.tar.gz.

File metadata

File hashes

Hashes for marshmallow-mongoengine-0.7.8.tar.gz
Algorithm Hash digest
SHA256 e32e9033be7c64e8da71ad5d4b1677742de3544df0038ffe682b7d6dd4908c0f
MD5 51564bc5a7856518a52b140e3b0c9917
BLAKE2b-256 9f14d6789039e54c991b6f8112f3eda992f6181fb636277a74867fc749eecace

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page