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_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
Release history Release notifications | RSS feed
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.2.3.tar.gz
(11.9 kB
view details)
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
tattl-0.2.3-py3-none-any.whl
(6.0 kB
view details)
File details
Details for the file tattl-0.2.3.tar.gz.
File metadata
- Download URL: tattl-0.2.3.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f58d4270716f44ebaf43da8803c73e17dee71590bcd79123bd15fb9996d10271
|
|
| MD5 |
8c1d2aa215039a34cb1c0aebce82aba7
|
|
| BLAKE2b-256 |
c133a61b4062cb6eef55759b212373da7b01f39172a16eb3792da1bdb2d3874d
|
File details
Details for the file tattl-0.2.3-py3-none-any.whl.
File metadata
- Download URL: tattl-0.2.3-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f48f45e8cd7b7742d53516eb549f36230bd80380f31fdfee07427c76a5c4cd44
|
|
| MD5 |
458f9f4873218b00cf59777d521d6b38
|
|
| BLAKE2b-256 |
6b63db548b254fc8c7d8645211bc2262b7a822f15ee33e8d80329059ee1ae241
|