skip to navigation
skip to content

Not Logged In

flask-marshmallow 0.1.0

Flask + marshmallow for beautiful APIs

Latest Version: 0.6.0

Flask + marshmallow for beautiful APIs

Flask-Marshmallow is a thin integration layer for Flask and marshmallow that adds additional features to marshmallow, including URL and Hyperlinks fields for HATEOAS-ready APIs.

from myapp.database import Model, Integer, String, DateTime
from flask_marshmallow import Serializer, fields, pprint

class User(Model):
    id = Column(Integer)
    email = Column(String)
    password = Column(String)
    date_created = Column(DateTime, auto_now_add=True)

class UserMarshal(Serializer):

    class Meta:
        # Fields to expose
        fields = ('email', 'date_created', '_links')

    _links = fields.Hyperlinks({
        # Same params as Flask.url_for, but args can be attribute names
        # surrounded by < >
        'self': fields.URL('author_detail', id='<id>'),
        'collection': fields.URL('authors')
    })

user = User(email='fred@queen.com', password='secret')
user.save()

serialized = UserMarshal(user)
pprint(serialized.data)
# {
#     "email": "fred@queen.com",
#     "date_created": "Fri, 25 Apr 2014 06:02:56 -0000",
#     "_links": {
#         "self": "/api/authors/42",
#         "collection": "/api/authors/"
#     }
# }

Get it now

pip install flask-marshmallow

License

MIT licensed. See the bundled LICENSE file for more details.

Changelog

0.1.0-pre (unreleased)

  • First release.
 
File Type Py Version Uploaded on Size
flask-marshmallow-0.1.0.tar.gz (md5) Source 2014-04-26 5KB
flask_marshmallow-0.1.0-py2.py3-none-any.whl (md5) Python Wheel 2.7 2014-04-26 7KB
  • Downloads (All Versions):
  • 36 downloads in the last day
  • 548 downloads in the last week
  • 3927 downloads in the last month