Integration of attrs and marshmallow.
Project description
Welcome to attrsmallow Documentation
attrs is a powerful library helps you to write concise and correct classes. And marshmallow is a powerful framework to write serializer/deserializer and data validator for complex object.
attrsmallow is a glue layer to taking advantage from them.
Quick Links
Usage
A blog example:
import attr
import marshmallow
from attrsmallow import BaseModel, BaseSchema
@attr.s
class User(BaseModel):
id = attr.ib()
name = attr.ib()
class UserSchema(BaseSchema):
id = fields.Integer(required=True)
name = fields.String(required=True)
Model = User
User.Schema = UserSchema
@attr.s
class Post(BaseModel):
id = attr.ib()
title = attr.ib()
user = attr.ib()
class PostSchema(BaseSchema):
id = fields.Integer()
title = fields.String()
user = fields.Nested(UserSchema)
Model = Post
Post.Schema = PostSchema
post_data = dict(id=1, title="Hello World!", user=dict(id=1, name="Alice"))
post = Post.load(post_data)
Install
attrsmallow is released on PyPI, so all you need is:
$ pip install attrsmallow
To upgrade to latest version:
$ pip install --upgrade attrsmallow
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
attrsmallow-0.0.1.tar.gz
(9.5 kB
view hashes)
Built Distribution
Close
Hashes for attrsmallow-0.0.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f13db76d5390abf6697035da66c37b342e15ea9e474cc7bb1466f2974a03a092 |
|
MD5 | fdd7f279ab6bd45a70f388b3223fbdcd |
|
BLAKE2b-256 | 8e5a511d4ae7c8650db9b066a3c0c1097420f691eef911a5ebca5eb5f6dd6c9f |