Skip to main content

Integration of attrs and marshmallow.

Project description

https://travis-ci.org/MacHu-GWU/attrsmallow-project.svg?branch=master https://codecov.io/gh/MacHu-GWU/attrsmallow-project/branch/master/graph/badge.svg https://img.shields.io/pypi/v/attrsmallow.svg https://img.shields.io/pypi/l/attrsmallow.svg https://img.shields.io/pypi/pyversions/attrsmallow.svg https://img.shields.io/badge/Star_Me_on_GitHub!--None.svg?style=social

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.

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


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)

Uploaded Source

Built Distribution

attrsmallow-0.0.1-py2-none-any.whl (15.1 kB view details)

Uploaded Python 2

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

Hashes for attrsmallow-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4f25cef4da0577691ced8a8cd2273aedff008dd3852f1f6bf630d283af8e8113
MD5 aa7f82228449e93b9b736c065ff12693
BLAKE2b-256 131654447bb60e5f3b4c3367b8b8291e47b2d9a9a62062a13eed00248cf9764c

See more details on using hashes here.

File details

Details for the file attrsmallow-0.0.1-py2-none-any.whl.

File metadata

File hashes

Hashes for attrsmallow-0.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 f13db76d5390abf6697035da66c37b342e15ea9e474cc7bb1466f2974a03a092
MD5 fdd7f279ab6bd45a70f388b3223fbdcd
BLAKE2b-256 8e5a511d4ae7c8650db9b066a3c0c1097420f691eef911a5ebca5eb5f6dd6c9f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page