Skip to content

thcrt/tattl

Repository files navigation

TATTL: a Totally Awesome Type-aware TOML Loader

UV Badge Python Version Badge PyPI Downloads Badge License Badge

Build Status Badge Maintenance Status Badge Free Palestine Badge

TATTL is a library that deserializes arbitrary data and validates that it conforms to a type structure you define. It will either return an instance of a dataclass that you give it, or it will throw an exception indicating that the data's types don't fit. TATTL supports nesting and modern type annotations.

Source | Docs | PyPI

Installation

Install TATTL with your favourite Python package manager. We recommend uv, but pip works too.

pip install tattl
uv add tattl

Get started

TATTL will take some TOML-structured data and transform it into an instance of a dataclass while validating type annotations. As a basic example:

import tattl
import tomllib
from dataclasses import dataclass

data = """
foo = "Hello, world!"
bar = 3.14
"""

@dataclass
class Structure:
    foo: str
    bar: float

loaded_data = tattl.unpack_dict(
    tomllib.loads(data),
    Structure
)

For advanced usage and an API reference, see the documentation.

License

This work is available under the terms of the BSD 3-Clause License.