Skip to main content

Python dataclass serializer/deserializer

Project description

Mew: python dataclass serializer/deserializer

Build Status Python Version Support PyPI Version Coverage Code style: black image

from dataclasses import dataclass
from enum import Enum
from typing import List

import mew


class Type(Enum):
    normal = 'normal'
    electric = 'electric'
    fire = 'fire'
    fighting = 'fighting'
    water = 'water'
    psychic = 'psychic'


@mew.serializable
@dataclass
class Pokemon:
    name: str
    pokedex: int
    type: Type
    abilities: List[str]


>>> pikachu = Pokemon('Pikachu', 25, Type.electric, ['static', 'lightning rod'])

>>> pikachu
Pokemon(name='Pikachu', pokedex=25, type=<Type.electric: 'electric'>, abilities=['static', 'lightning rod'])

>>> pikachu.dumps()
'{"name": "Pikachu", "pokedex": 25, "type": "electric", "abilities": ["static", "lightning rod"]}'

>>> assert pikachu == Pokemon.loads(pikachu.dumps())

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

mew-0.1.4.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

mew-0.1.4-py2.py3-none-any.whl (5.7 kB view hashes)

Uploaded Python 2 Python 3

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