Skip to main content

Totally Awesome Type-aware TOML Loader

Reason this release was yanked:

Broken CI release, use v0.3.1 instead

Project description

TATTL: a Totally Awesome Type-aware TOML Loader

Usage example

import tattl
import tomllib

from dataclasses import dataclass, field
from pprint import pp

my_toml = """
title = "TOML Example"

[points]
alice = 17
bob = 12
charlie = 7

[garden]
sunny = true
elevation-map = [
    [1, 1, 1, 2, 1],
    [1, 2, 2, 2, 1],
    [1, 2, 3, 3, 2],
    [1, 2, 2, 3, 1],
    [1, 1, 1, 2, 1],
]

[garden.flowers]
roses = { amount = 7, growth = 0.90 }
daffodils = { amount = 3, growth = 0.54 }
daisies = { amount = 12, growth = 0.21 }

[fruits.apples]
color = "red"
tastes = ["sweet", "sour"]

[fruits.mangoes]
color = "orange"
tastes = ["sweet", "citrus"]
"""


@dataclass
class Structure:
    title: str
    points: dict[str, int]

    @dataclass
    class Garden:
        sunny: bool
        elevation_map: list[list[int]] = field(metadata={"name": "elevation-map"})

        @dataclass
        class Flower:
            amount: int
            growth: float

        flowers: dict[str, Flower]

    garden: Garden

    @dataclass
    class Fruit:
        color: str
        tastes: list[str]

    fruits: dict[str, Fruit]


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

pp(data)

# Structure(title='TOML Example',
#           points={'alice': 17, 'bob': 12, 'charlie': 7},
#           garden=Garden(sunny=True,
#                         elevation_map=[[1, 1, 1, 2, 1],
#                                        [1, 2, 2, 2, 1],
#                                        [1, 2, 3, 3, 2],
#                                        [1, 2, 2, 3, 1],
#                                        [1, 1, 1, 2, 1]],
#                         flowers={'roses': Flower(amount=7,
#                                                  growth=0.9),
#                                  'daffodils': Flower(amount=3,
#                                                      growth=0.54),
#                                  'daisies': Flower(amount=12,
#                                                    growth=0.21)}),
#           fruits={'apples': Fruit(color='red',
#                                   tastes=['sweet', 'sour']),
#                   'mangoes': Fruit(color='orange',
#                                    tastes=['sweet', 'citrus'])})

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

tattl-0.3.0.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

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

tattl-0.3.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file tattl-0.3.0.tar.gz.

File metadata

  • Download URL: tattl-0.3.0.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.6

File hashes

Hashes for tattl-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6a210c0a1fdf2dc64b602f78f5e8336be65088910ab2b710c467b2fabe780c18
MD5 23299cb1c8d6efd92bb682394a5a0c16
BLAKE2b-256 7073f0c323cc33350f0e6bb33348cc7c9fa002270224e859b7b2c9aa7a560127

See more details on using hashes here.

File details

Details for the file tattl-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: tattl-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.6

File hashes

Hashes for tattl-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e682dc4834361d0f1c4327422ccfba51e7c4a68486c1fdb9f1af07215324755
MD5 e6cb649570cf09ce11b57bfa550eae5a
BLAKE2b-256 579569c8c2854b1c6fbedb6a029071a0ee1303fb49e0d5a3acbd44b1c79f18b9

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