Skip to main content

Totally Awesome Type-aware TOML Loader

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(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.1.0.tar.gz (9.1 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.1.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tattl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3dfe85b63c20e4273ed6011bf3c92865a28358027bd509450a610dabc9d2a4bc
MD5 87db7b1c98d7276e3f779301d1d3eba4
BLAKE2b-256 ed816f6de18707b60c3d2be541312556f56490ed9ebb87a6514a07c96dcd0a09

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for tattl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1615bfb47bdf138a01145453354ac7ff5601fbe5a61271ef10a70933dd5e15b3
MD5 7337be314a05657f698017335409eca3
BLAKE2b-256 d27722b9ef0ba8acfd5ca65751003259e3d188e0c64d65dac7d63c85b64efd3d

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