https://github.com/zeionara/tasty
A human-readable format for nested data serialization
https://github.com/zeionara/tasty
Last synced: 3 months ago
JSON representation
A human-readable format for nested data serialization
- Host: GitHub
- URL: https://github.com/zeionara/tasty
- Owner: zeionara
- License: apache-2.0
- Created: 2023-01-27T16:57:00.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-27T17:28:15.000Z (over 2 years ago)
- Last Synced: 2025-02-03T08:16:36.879Z (4 months ago)
- Language: Python
- Size: 64.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tasty
![]()
Tasty - **ta**b **s**eparated **t**ables - a human-readable format for nested data serialization. The module allows to represent lists of objects with variable length in the following format:
```sh
pair triple
one 1 two 2 three two 2 three
three 3 four 4 fivesix 6 seven 7 eight
```Which corresponds to the following data (see `examples/main.py` for more details):
```py
(
(
(
(TastyPair('one', 1), ),
(TastyTriple('two', 2, Quux('three')), TastyTriple('two', 2, Quux('three')))
),
(
(TastyPair('three', 3), ),
(TastyTriple('four', 4, Quux('five')), )
)
),
(
(
(TastyPair('six', 6), ),
(TastyTriple('seven', 7, Quux('eight')), )
),
)
)
```## Installation
The module doesn't require any additional dependencies. To install from pypi, run the following command:
```sh
pip install tastier
```## Usage
Default methods for dataset serialization and deserialization are implemented, so the module can be used as follows (see the `main.py` script in the `examples` folder):
```py
from dataclasses import dataclass
from tasty import Corpus, CellComponent, encode, pipe@dataclass
class TastyPair(CellComponent):
foo: str
bar: int@property
def serialized(self):
return self._serialize(
self.foo | pipe | encode,
self.bar | pipe | str
)@dataclass
class Quux:
value: str@dataclass
class TastyTriple(CellComponent):
baz: str
qux: int
quux: Quux@property
def serialized(self):
return self._serialize(
self.baz | pipe | encode,
self.qux | pipe | str,
self.quux.value | pipe | encode
)written_corpus = Corpus(
(
(
(
(TastyPair('one', 1), ),
(TastyTriple('two', 2, Quux('three')), TastyTriple('two', 2, Quux('three')))
),
(
(TastyPair('three', 3), ),
(TastyTriple('four', 4, Quux('five')), )
)
),
(
(
(TastyPair('six', 6), ),
(TastyTriple('seven', 7, Quux('eight')), )
),
)
)
).write('corpus.txt', header = ('pair', 'triple'))read_corpus = Corpus.read('corpus.txt', parsers = (TastyPair, TastyTriple))
assert read_corpus.data == written_corpus.data
```