Skip to main content

Mongoengine integration with the marshmallow (de)serialization library

Project description

Travis-CI

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


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.5.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

marshmallow_mongoengine-0.5.0-py2.py3-none-any.whl (13.2 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for marshmallow-mongoengine-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2292dbffcc181d2dd7b8fceb22636783de70a5b528da6c53adcc3a0c358f2ec4
MD5 5621edffb35a5870b5c6a1b567d5e5f2
BLAKE2b-256 fe5412e854db2db9dd52c4506cbaa8f4a71625c7bef9568d9199360aeae37b0b

See more details on using hashes here.

File details

Details for the file marshmallow_mongoengine-0.5.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for marshmallow_mongoengine-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 311b23a3719807ef7a9d1cf0481b96e9c75c657601067b734e841a6e09c31e72
MD5 54867d830b86fe158ce058e7b4103d60
BLAKE2b-256 e48ece3972685a61517cb8116bb078620f0827ffef74ec44fcf9f1f39ad34677

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