A human-readable format for nested data serialization
Project description
Tasty
Tasty - tab separated tables - a human-readable format for nested data serialization. The module allows to represent lists of objects with variable length in the following format:
pair triple
one 1 two 2 three two 2 three
three 3 four 4 five
six 6 seven 7 eight
Which corresponds to the following data (see examples/main.py
for more details):
(
(
(
(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:
pip install tasty
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):
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
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
tastier-0.1.0.tar.gz
(7.3 kB
view details)
File details
Details for the file tastier-0.1.0.tar.gz
.
File metadata
- Download URL: tastier-0.1.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa8ebbd4c165a8c3f00cec81e7d15e4a71feb86e80aa9c243991f314191bcdb0 |
|
MD5 | ab813312665108c6d37b1e88e4835276 |
|
BLAKE2b-256 | 9fa7df15808e4d79303d05d405361577d957535e2675f6b83fadcd758d28a947 |