https://github.com/mongoengine/marshmallow-mongoengine
Mongoengine integration with marshmallow
https://github.com/mongoengine/marshmallow-mongoengine
Last synced: 3 months ago
JSON representation
Mongoengine integration with marshmallow
- Host: GitHub
- URL: https://github.com/mongoengine/marshmallow-mongoengine
- Owner: MongoEngine
- License: mit
- Created: 2017-01-09T10:58:50.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-08-27T04:20:06.000Z (almost 2 years ago)
- Last Synced: 2024-05-21T01:11:52.855Z (about 1 year ago)
- Language: Python
- Size: 166 KB
- Stars: 77
- Watchers: 6
- Forks: 34
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- Changelog: HISTORY.rst
- License: LICENSE
Awesome Lists containing this project
README
.. image:: https://travis-ci.org/MongoEngine/marshmallow-mongoengine.svg?branch=master
:target: https://travis-ci.org/MongoEngine/marshmallow-mongoengine
:alt: Travis-CI.. image:: https://readthedocs.org/projects/marshmallow-mongoengine/badge/?version=latest
:target: http://marshmallow-mongoengine.readthedocs.org/en/latest/?badge=latest
:alt: Documentation Status.. image:: https://coveralls.io/repos/github/MongoEngine/marshmallow-mongoengine/badge.svg?branch=master
:target: https://coveralls.io/github/MongoEngine/marshmallow-mongoengine?branch=master
:alt: Code Coveragemarshmallow-mongoengine
=======================`Mongoengine `_ integration with the `marshmallow
`_ (de)serialization library.See documentation at http://marshmallow-mongoengine.rtfd.org/
Declare your models
-------------------.. code-block:: python
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 ''.format(self=self)class Book(me.Document):
title = me.StringField()Generate marshmallow schemas
----------------------------.. code-block:: python
from marshmallow_mongoengine import ModelSchema
class AuthorSchema(ModelSchema):
class Meta:
model = Authorclass BookSchema(ModelSchema):
class Meta:
model = Bookauthor_schema = AuthorSchema()
(De)serialize your data
-----------------------.. code-block:: python
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
#Get it now
----------
::pip install -U marshmallow-mongoengine
License
-------MIT licensed. See the bundled `LICENSE `_ file for more details.