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 type forms
The following type forms are supported out of the box:
- bool
- int
- float
- str
- complex
- tuple[T1, ..., Tn], typing.Tuple[T1, ..., Tn]
- tuple[T, ...], typing.Tuple[T, ...] a.k.a homogeneous tuple
- typing.NamedTuple
- list[T], typing.List[T]
- set[T], typing.Set[T]
- frozenset[T], typing.FrozenSet[T]
- dict[K, V], typing.Dict[K, V]
- typing.TypedDict, typing_extensions.TypedDict, including support for PEP 728 closed and extra_items.
- dataclasses.dataclass
- typing.NewType[T]
- ipaddress.{IPv4Address,IPv6Address,IPv4Interface,IPv6Interface,IPv4Network,IPv6Network}
It is easy to add support for custom types as needed when creating a loader.
Supported source types
Data can be loaded from the following basic types, matching types used by common serialization formats.
Additionally data can be loaded from argparse namespaces to support easily loading arguments into data types for simple CLI applications.
- int
- float
- bool
- str
- list
- dict
- argparse.Namespace
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
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.2.tar.gz.
File metadata
- Download URL: tressed-0.0.2.tar.gz
- Upload date:
- Size: 15.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 |
766b5e371fcdc0b53cfb2dcfd3c6c767612fc810b621b90a58eeb8eb9dc73d12
|
|
| MD5 |
c635823828de5b10c14d578c40405b1f
|
|
| BLAKE2b-256 |
8d6839155d092831dc6c2d4f67b25db40a216dcbd7cb9365fcb4545077816498
|
File details
Details for the file tressed-0.0.2-py3-none-any.whl.
File metadata
- Download URL: tressed-0.0.2-py3-none-any.whl
- Upload date:
- Size: 13.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 |
2fcaafa0bde9cfc6de87ca2d1835fa4e7aba2b543a7edd69d4c4c174e165c790
|
|
| MD5 |
c7e84f52f53efb360a40542b0aa24071
|
|
| BLAKE2b-256 |
5425bdce1b3a94d1cc1b070ea9ca59851b583a31b040d872fe5c0796930786df
|