Mongoengine integration with the marshmallow (de)serialization library
Project description
[![Build Status](https://travis-ci.org/touilleMan/marshmallow-mongoengine.svg?branch=master)](https://travis-ci.org/touilleMan/marshmallow-mongoengine)
# Marshmallow-Mongoengine
## Introduction
Mongoengine integration with the marshmallow (de)serialization library.
Heavilly ~~ripped~~ inspired by [marshmallow-sqlalchemy](http://marshmallow-sqlalchemy.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')>
```
# Marshmallow-Mongoengine
## Introduction
Mongoengine integration with the marshmallow (de)serialization library.
Heavilly ~~ripped~~ inspired by [marshmallow-sqlalchemy](http://marshmallow-sqlalchemy.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')>
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for marshmallow-mongoengine-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 925df19fe8fefba4ee1fa4ccdd013e2236990ff97c1fb01346ff56038db63e21 |
|
MD5 | 20ee2c4b040a4caa28350752d34886a4 |
|
BLAKE2b-256 | 542e73513a718dd5862de3ecef8128a79984b21a00a13e94cdeb8ff350089a7f |
Close
Hashes for marshmallow_mongoengine-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2641e77b3cea4074f501218f75c212b2e55cf9a41fb13d00f9d212d3f38da22c |
|
MD5 | 3177e70f81b622512c2621950cfafb0a |
|
BLAKE2b-256 | fc131e5a9608c752b61306979678609cb602be9ecbc2a604b1708d033411f79d |