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-1.0.1.tar.gz
(12.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
datta-1.0.1-py2.py3-none-any.whl
(14.8 kB
view details)
File details
Details for the file datta-1.0.1.tar.gz.
File metadata
- Download URL: datta-1.0.1.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c687727cda3545857a4fc0c010c43457d9bcbf4328fe5b0988a33f9186a5917a
|
|
| MD5 |
73bc485680ddd36d1db4b8de91324f88
|
|
| BLAKE2b-256 |
964951de4f967a9e6fa98790b8234ff4fe59322efd1179524a72d32ddecad701
|
File details
Details for the file datta-1.0.1-py2.py3-none-any.whl.
File metadata
- Download URL: datta-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c10a35a3ad380ad19ce973de94bde2720bfc0abfc8a204fa7fa60a2ab256abc
|
|
| MD5 |
ed5647e34eba033b2df372079f9fe153
|
|
| BLAKE2b-256 |
d44ab3f69bbb3e76d980350ccc7d05781cf8f07f5dd8291f760b43f5b511d6c0
|