Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Marrying marshmallow and annotations

Project description

marshmallow-annotations allows you to create marshmallow schema from classes with annotations on them

from marshmallow_annotations import AnnotationSchema
from .music import Album, Artist

class AlbumScheme(AnnotationSchema):
    class Meta:
        target = Album
        register_as_scheme = True


class ArtistScheme(AnnotationSchema):
    class Meta:
        target = Artist
        register_as_scheme = True


scheme = ArtistScheme()
scheme.dump(
    Artist(
        id=1, name="Abominable Putridity",
        albums=[
            Album(
                id=1,
                name="The Anomalies of Artificial Origin"
            )
        ]
    )
)

# {
#     "albums": [
#         {
#             "id": 1,
#             "name": "The Anomalies of Artificial Origin"
#         }
#     ],
#     "id": 1,
#     "name": "Abominable Putridity"
# }

Installation

marshmallow-annotations is available on pypi and installable with:

pip install marshmallow-annotations

marshmallow-annotations supports Python 3.6+ and marshmallow 2.x.x

Note

If you are install marshmallow-annotations outside of a virtual environment, consider installing with pip install --user marshmallow-annotations rather than using sudo or adminstrator privileges to avoid installing it into your system Python.

Why?

Keeping up with entity definitions, ORM mappings and schema shapes can be a huge pain the butt. If you change one thing, you need to change three things.

Instead, marshmallow-annotations wants to drive schema shapes from your entity defintions (with a little help from you of course).

More Information

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
marshmallow_annotations-2.3.0-py3-none-any.whl (12.1 kB) Copy SHA256 hash SHA256 Wheel py3 Aug 5, 2018
marshmallow-annotations-2.3.0.tar.gz (10.6 kB) Copy SHA256 hash SHA256 Source None Aug 5, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page