Metadata-Version: 2.3
Name: tattl
Version: 0.2.2
Summary: Totally Awesome Type-aware TOML Loader
Project-URL: Source, https://github.com/thcrt/tattl
Project-URL: Issues, https://github.com/thcrt/tattl/issues
Project-URL: PyPI, https://pypi.org/project/tattl/
Author-email: thcrt <110127860+thcrt@users.noreply.github.com>
License: BSD 3-Clause License
        
        Copyright (c) 2024, Theo Court
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Keywords: config,configuration,dataclass,settings,toml,typing,validation,yaml
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: File Formats
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing
Classifier: Typing :: Typed
Requires-Python: >=3.12
Description-Content-Type: text/markdown

# TATTL: a Totally Awesome Type-aware TOML Loader

## Usage example
```python
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'])})

```