dataclass_structor

Typed object structure/destructure.


License
MIT
Install
pip install dataclass_structor==0.0.6

Documentation

dataclass_structor

Documentation Status PyPI - License PyPI - Python Version PyPI - License Build Status

A type aware structor/destructor for python value objects.

Install

pip install dataclass_structor

Documentation

The docs for this project can be found here.

Example

import dataclasses

from dataclass_structor import structure, unstructure


@dataclasses.dataclass
class Invite:
    email: str
    guests: typing.List["Guest"]


@dataclasses.dataclass
class Guest:
    first_name: typing.Optional[str] = None


value_type = Invite(
    email="testing",
    guests=[
      Guest(first_name="John"),
      Guest(),
    ],
)

x = unstructure(value_type)
assert x == {"email": "", "guests": [{"first_name": "John"}, {"first_name": None}]}

assert structure(x, Invite) == value_type