Glue types together
Project description
tressed
Serialize and deserialize types, in any order.
Usage
from dataclasses import dataclass, field
from tressed.loader import Loader
@dataclass
class SomeDataclass:
foo: str
bar: str = "bar"
baz: list[int] = field(default_factory=lambda: [1, 2, 3])
bar_bar: tuple[int, str] = field(metadata={"alias": "barBar"}, kw_only=True)
value = {
"foo": "foo",
"barBar": (2, "humbug"),
}
loader = Loader()
loaded = loader.load(value, SomeDataclass)
assert loaded == SomeDataclass(
foo="foo",
bar="bar",
baz=[1, 2, 3],
bar_bar=(2, "humbug"),
)
Supported types
The following types are supported out of the box:
- bool
- int
- float
- str
- tuple[T1, ..., Tn], typing.Tuple[T1, ..., Tn]
- tuple[T, ...], typing.Tuple[T, ...] a.k.a homogeneous tuple
- list[T], typing.List[T]
- set[T], typing.Set[T]
- frozenset[T], typing.FrozenSet[T]
- dataclasses.dataclass
It is easy to add support for custom types as needed when creating a loader.
Installation
Using pip:
pip install tressed
Or using uv:
uv add tressed
Then just import tressed and get coding.
import tressed
Goals
- Provide easy serialization and deserialization to and from built-in and standard library types.
- Provide easy way to add support for custom types.
- Provide easy yet powerful support for serializaiton and deserialization aliases.
- Pure python, no additional runtime dependencies beyond the standard library.
- Do as little work as possible to be suitable for CLIs, for example using lazy imports as much as possible.
Stretch goals
- Add first class support for concurrent loading and dumping, with support for asyncio and threading, for example deserializing a list of M objects on N threads.
- Use code generation internally similarly to dataclasses. Instead of doing metaprogramming each time, generate an actual function for the type that does (de)serialization. Interpret the first time, compile the second, using source or ast module, and then reuse the compiled function.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tressed-0.0.1.tar.gz
(10.4 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
File details
Details for the file tressed-0.0.1.tar.gz.
File metadata
- Download URL: tressed-0.0.1.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86775b91ff57f3a7c4029ccb949f8873e06462ac8a7a59096ad9f23d6a6d4d78
|
|
| MD5 |
fca1e613e35a1c3706a40c89926d2f94
|
|
| BLAKE2b-256 |
9568b1259380b8c5f888fbb92e30f531ded83342567de7bd2f2a6026b813018e
|
File details
Details for the file tressed-0.0.1-py3-none-any.whl.
File metadata
- Download URL: tressed-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b89c474e3de2cb42f54cc047c2420a05f71e95c8c43a4ddab899f7ccd92ea12
|
|
| MD5 |
ec7ea83c5e501f4bd0392d4e3872d3b7
|
|
| BLAKE2b-256 |
483f3407ffa631ad939f0afe8e6ac38ca15aa725824226080e487a9f6266cbb0
|