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 details)
Built Distribution
File details
Details for the file attrsmallow-0.0.1.tar.gz
.
File metadata
- Download URL: attrsmallow-0.0.1.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f25cef4da0577691ced8a8cd2273aedff008dd3852f1f6bf630d283af8e8113 |
|
MD5 | aa7f82228449e93b9b736c065ff12693 |
|
BLAKE2b-256 | 131654447bb60e5f3b4c3367b8b8291e47b2d9a9a62062a13eed00248cf9764c |
File details
Details for the file attrsmallow-0.0.1-py2-none-any.whl
.
File metadata
- Download URL: attrsmallow-0.0.1-py2-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f13db76d5390abf6697035da66c37b342e15ea9e474cc7bb1466f2974a03a092 |
|
MD5 | fdd7f279ab6bd45a70f388b3223fbdcd |
|
BLAKE2b-256 | 8e5a511d4ae7c8650db9b066a3c0c1097420f691eef911a5ebca5eb5f6dd6c9f |