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.0.tar.gz
(11.2 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.0-py3-none-any.whl
(5.2 kB
view details)
File details
Details for the file tattl-0.2.0.tar.gz.
File metadata
- Download URL: tattl-0.2.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7753c7db5ce4f36db139399cc8fee8d1a637939459b86e7ba15ddd2fcf062683
|
|
| MD5 |
4abaac4343a20752fe0c592e432f555c
|
|
| BLAKE2b-256 |
f749b3dddb53447020083957f57672da7c6ed494ae3ccdbe11de38ccb4b3d09b
|
File details
Details for the file tattl-0.2.0-py3-none-any.whl.
File metadata
- Download URL: tattl-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92d33f220177a3dde910e576f869d503f3eb618ae1ebee6c18a0a54024b7d7de
|
|
| MD5 |
26092ffcfeee9528796cced95d6d4a6a
|
|
| BLAKE2b-256 |
db8fe052d94584c054f0126cf6debdbd980c91221c5dd2ee56bad95ba4329a3d
|