Giter Site home page Giter Site logo

marshmallow-mongoengine's Introduction

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.

marshmallow-mongoengine's People

Contributors

kevin-lyn avatar touilleman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.