Skip to main content

Deserialize and serialize types, in any order

Project description

tressed - Deserialize and serialize types, in any order.

Package version

Tressed is a easy to use pure python library to deserialize and serialize to and from Python types.


Install tressed using pip:

$ pip install tressed

Now, let's get started:

>>> from dataclasses import dataclass, field
>>> from pprint import pprint
>>> 
>>> from tressed.loader import Loader
>>> from tressed.alias import to_camel
>>> 
>>> @dataclass
... class SomeDataclass:
...     some_field: str
...     some_default_field: str = "bar"
...     some_default_factory_field: list[int] = field(default_factory=lambda: [1, 2, 3])
...     other_field: tuple[int, str] = field(metadata={"alias": "OTHER"}, kw_only=True)
...     
>>> value = {
...     "someField": "foo",
...     "OTHER": (2, "humbug"),
... }
... 
>>> pprint(loader.load(value, SomeDataclass))
SomeDataclass(some_field='foo',
              some_default_field='bar',
              some_default_factory_field=[1, 2, 3],
              other_field=(2, 'humbug'))

Features

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:

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.3.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tressed-0.0.3-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file tressed-0.0.3.tar.gz.

File metadata

  • Download URL: tressed-0.0.3.tar.gz
  • Upload date:
  • Size: 16.8 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

Hashes for tressed-0.0.3.tar.gz
Algorithm Hash digest
SHA256 8691b670a5c5c1502fe68dac3ad39093496bc906619eba7a27a015f21be1f388
MD5 38ce9f3fbbf38436b2077edc35dc32ab
BLAKE2b-256 d424d2552852437a8eb8bfd3f38cb6aa4248b244b56627d2890d61e2ac972d94

See more details on using hashes here.

File details

Details for the file tressed-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: tressed-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 15.1 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

Hashes for tressed-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0957cfd6d484e009302530cb8e7b21359d6be324e929c26fab27dfcc5e9436bc
MD5 1deff01eeef5eae1d24496730850b78a
BLAKE2b-256 75ac5235de8067f9e7c2b48b2d2e13f7d2843cb849289790d17c08a6c9e7ef0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page