Skip to content

Implementation of Slotted Data Classes compatible with Python 2.7 and 3.7+.

License

Notifications You must be signed in to change notification settings

brunonicko/datta

Repository files navigation

datta

https://readthedocs.org/projects/datta/badge/?version=stable https://img.shields.io/github/license/brunonicko/datta?color=light-green https://static.pepy.tech/personalized-badge/datta?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads https://img.shields.io/pypi/pyversions/datta?color=light-green&style=flat

Overview

Immutable data structures based on estruttura.

Examples

>>> from datta import Data, attribute
>>> class Point(Data):
...     x = attribute(types=int)
...     y = attribute(types=int)
...
>>> point_a = Point(3, 4)
>>> point_a
Point(3, 4)
>>> point_b = point_a.update(x=30, y=40)
>>> point_b
Point(30, 40)
>>> from datta import Data, attribute, list_attribute
>>> from tippo import Literal
>>> class Vehicle(Data):
...     kind = attribute(types=str)
...
>>> class Garage(Data):
...     vehicles = list_attribute(types=Vehicle)
...     gate = attribute(default="automatic", types=str)  # type: Literal["automatic", "manual"]
...
>>> garage = Garage([Vehicle("bicycle"), Vehicle("car")], gate="manual")
>>> garage
Garage([Vehicle('bicycle'), Vehicle('car')], gate='manual')
>>> garage.serialize() == {"vehicles": [{"kind": "bicycle"}, {"kind": "car"}], "gate": "manual"}
True
>>> Garage.deserialize({"vehicles": [{"kind": "bicycle"}, {"kind": "car"}], "gate": "manual"}) == garage
True
>>> from datta import list_cls
>>> MyStrList = list_cls(converter=str, qualified_name="MyStrList")
>>> my_str_list = MyStrList([1, 2.2, None, True])
>>> my_str_list
MyStrList(['1', '2.2', 'None', 'True'])

About

Implementation of Slotted Data Classes compatible with Python 2.7 and 3.7+.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages