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

Uploaded Source

Built Distribution

marshmallow_mongoengine-0.4.0-py2.py3-none-any.whl (12.9 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for marshmallow-mongoengine-0.4.0.tar.gz
Algorithm Hash digest
SHA256 80f89e8ee2e1640a57fb3ce740c9eca2e34a928864dd3c4fa91d9f90fc176201
MD5 dfd1fe8766e436e7525af8fb6a32839d
BLAKE2b-256 d4ee67db8ceadf9515f3032128860ecdccec42150e8023b041f6b9753737c487

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for marshmallow_mongoengine-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2fa4fb72fdd8b8bb0195703bf00572c7b12036e248ec4c7f0565b0a77d4bfd0b
MD5 0bc72d2131f79d830545408c465494da
BLAKE2b-256 7158328b46cb2d5a8525878a688418f767c137b5e7489b50163e0d0ab1b00d37

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