Python dataclass serializer/deserializer
Project description
Mew: python dataclass serializer/deserializer
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
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
mew-0.1.4.tar.gz
(5.0 kB
view hashes)