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

Uploaded Source

Built Distribution

marshmallow_mongoengine-0.6.2-py2.py3-none-any.whl (14.0 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for marshmallow-mongoengine-0.6.2.tar.gz
Algorithm Hash digest
SHA256 a5d40881dd9c9d16c4c333bae2cf470a4854e8f26d2dc8905a2450bbed4aa1a7
MD5 335965c3c6ec8279f342841d33563885
BLAKE2b-256 23e38d0b8a41ba9d0e59f7c1614183860c4ca63994f706a12a1e58236cf44747

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for marshmallow_mongoengine-0.6.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 464fa957e7d5dc5de7eb4285f8a0f0073f6b12f58952e2d9e9a2c9b35fae4fe7
MD5 c92b52fa5aa8cf38708f4448f8ddf196
BLAKE2b-256 39621d1cce414ec1c61ee2a089e2e4d314d349a437d58bfbdba9f668e6c4ca10

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