Implementation of Slotted Data Classes compatible with Python 2.7 and 3.7+.
Project description
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'])
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
datta-0.1.0.tar.gz
(12.2 kB
view hashes)
Built Distribution
datta-0.1.0-py2.py3-none-any.whl
(14.8 kB
view hashes)
Close
Hashes for datta-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e073a3fe4d71f178461b5773da8c9e81141c8725fa74dd8c77f0c26f96eddce |
|
MD5 | feda63cbaca7aa67c714b349e6ba8cca |
|
BLAKE2b-256 | 07d10ad6771c5f01fbe0d5d2e059015530b2c38f4b30ee2a14f0ac0a56e73a77 |