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.2.tar.gz
(6.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.2-py3-none-any.whl
(6.0 kB
view details)
File details
Details for the file tattl-0.2.2.tar.gz.
File metadata
- Download URL: tattl-0.2.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47986a2c6174a5d136db0bf106b7d43d1caaf45141b3f36e06033d57c1f06fa0
|
|
| MD5 |
cbf769446eb96f148a8977bb9c3d0016
|
|
| BLAKE2b-256 |
c316ee1e2ed9202859bb5490f03eb972dd93649adf3eebb15deead4368b19ad9
|
File details
Details for the file tattl-0.2.2-py3-none-any.whl.
File metadata
- Download URL: tattl-0.2.2-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 |
278806a83de5de63a6edbd79bb0d781d266a3fcc1968ed8ef8525fa9fba4d677
|
|
| MD5 |
5417ba89e23106c110e335f091e20eea
|
|
| BLAKE2b-256 |
795a7f188870730a6368bacbd5829a62a57c73dafc314b6f5bcfdba48d3aa417
|