Skip to main content

The Toasted Marshmallow Enum package makes it possible to dump and load Enum values based on the ultra fast serialization that Toasted Marshmallow provides.

Project description

Inspired by Marshmallow Enum and by ORM libraries.

The Toasted Marshmallow Enum package makes it possible to dump and load Enum values based on the ultra fast serialization that Toasted Marshmallow provides.

Installing toastedmarshmallow-enum

pip install toastedmarshmallow-enum

Using Toasted Marshmallow Enum

Using Toasted Marshmallow Enum in an existing Marshmallow Schema is as easy as defining the enum class attribute as an EnumField. For example:

from enum import Enum

import toastedmarshmallow
from marshmallow import fields, Schema

from toastedmarshmallow_enum import EnumField

class Level(Enum):
    LOW = '0'
    MEDIUM = '1'
    HIGH = '2'

class UserSchema(Schema):
    class Meta:
        jit = toastedmarshmallow.Jit

    name = fields.String()
    level = EnumField(Level)

How it works

Dump methods:

class User:
    def __init(name, level):
        self.name = name
        self.level = level

schema = DummyUserSchema()

user = User(name='John Doe', level=Level.HIGH)
print(schema.dump(user).data)
# {'name': 'John Doe', 'level': 2}

print(schema.load({'name': 'John Doe', 'level: 2}).data)
# {'name': 'John Doe', 'level': 'HIGH'}

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

toastedmarshmallow-enum-1.0.1.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file toastedmarshmallow-enum-1.0.1.tar.gz.

File metadata

File hashes

Hashes for toastedmarshmallow-enum-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b4058a7f29e0a1210e5f52650b75858f77a01ec255d659793c0e52f57ddc9eb7
MD5 afb8e1aa210bcdf377bcf1c6fbb3227f
BLAKE2b-256 b22359f407d89275e392b9ab3cb5c9c7ebf16312cd4f3eaa28f9f92bced10091

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