tattl


Nametattl JSON
Version 0.3.1 PyPI version JSON
download
home_pageNone
SummaryTotally Awesome Type-aware TOML Loader
upload_time2024-12-17 21:19:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseBSD 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
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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'])})

```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tattl",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "config, configuration, dataclass, settings, toml, typing, validation, yaml",
    "author": null,
    "author_email": "thcrt <110127860+thcrt@users.noreply.github.com>",
    "download_url": "https://files.pythonhosted.org/packages/8a/81/4f4da16e74917d713744ca4a02cfaecf0ae2903a606b02f931c299328be0/tattl-0.3.1.tar.gz",
    "platform": null,
    "description": "# TATTL: a Totally Awesome Type-aware TOML Loader\n\n## Usage example\n\n```python\nimport tattl\nimport tomllib\n\nfrom dataclasses import dataclass, field\nfrom pprint import pp\n\nmy_toml = \"\"\"\ntitle = \"TOML Example\"\n\n[points]\nalice = 17\nbob = 12\ncharlie = 7\n\n[garden]\nsunny = true\nelevation-map = [\n    [1, 1, 1, 2, 1],\n    [1, 2, 2, 2, 1],\n    [1, 2, 3, 3, 2],\n    [1, 2, 2, 3, 1],\n    [1, 1, 1, 2, 1],\n]\n\n[garden.flowers]\nroses = { amount = 7, growth = 0.90 }\ndaffodils = { amount = 3, growth = 0.54 }\ndaisies = { amount = 12, growth = 0.21 }\n\n[fruits.apples]\ncolor = \"red\"\ntastes = [\"sweet\", \"sour\"]\n\n[fruits.mangoes]\ncolor = \"orange\"\ntastes = [\"sweet\", \"citrus\"]\n\"\"\"\n\n\n@dataclass\nclass Structure:\n    title: str\n    points: dict[str, int]\n\n    @dataclass\n    class Garden:\n        sunny: bool\n        elevation_map: list[list[int]] = field(metadata={\"name\": \"elevation-map\"})\n\n        @dataclass\n        class Flower:\n            amount: int\n            growth: float\n\n        flowers: dict[str, Flower]\n\n    garden: Garden\n\n    @dataclass\n    class Fruit:\n        color: str\n        tastes: list[str]\n\n    fruits: dict[str, Fruit]\n\n\ndata = tattl.unpack_dict(tomllib.loads(my_toml), Structure)\n\npp(data)\n\n# Structure(title='TOML Example',\n#           points={'alice': 17, 'bob': 12, 'charlie': 7},\n#           garden=Garden(sunny=True,\n#                         elevation_map=[[1, 1, 1, 2, 1],\n#                                        [1, 2, 2, 2, 1],\n#                                        [1, 2, 3, 3, 2],\n#                                        [1, 2, 2, 3, 1],\n#                                        [1, 1, 1, 2, 1]],\n#                         flowers={'roses': Flower(amount=7,\n#                                                  growth=0.9),\n#                                  'daffodils': Flower(amount=3,\n#                                                      growth=0.54),\n#                                  'daisies': Flower(amount=12,\n#                                                    growth=0.21)}),\n#           fruits={'apples': Fruit(color='red',\n#                                   tastes=['sweet', 'sour']),\n#                   'mangoes': Fruit(color='orange',\n#                                    tastes=['sweet', 'citrus'])})\n\n```\n",
    "bugtrack_url": null,
    "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.",
    "summary": "Totally Awesome Type-aware TOML Loader",
    "version": "0.3.1",
    "project_urls": {
        "Issues": "https://github.com/thcrt/tattl/issues",
        "PyPI": "https://pypi.org/project/tattl/",
        "Source": "https://github.com/thcrt/tattl"
    },
    "split_keywords": [
        "config",
        " configuration",
        " dataclass",
        " settings",
        " toml",
        " typing",
        " validation",
        " yaml"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3356d9c22fa0174a3259f4d894ad71df7d311697f6c04fa9828d7d6513ac7cbf",
                "md5": "13aa5de389bfde736d4c22fe302c628f",
                "sha256": "7d432aeb21459ef25b64432f4f5a316e8b7b8b9d6448ce887c1876b74c1de14f"
            },
            "downloads": -1,
            "filename": "tattl-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "13aa5de389bfde736d4c22fe302c628f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 6676,
            "upload_time": "2024-12-17T21:19:19",
            "upload_time_iso_8601": "2024-12-17T21:19:19.823144Z",
            "url": "https://files.pythonhosted.org/packages/33/56/d9c22fa0174a3259f4d894ad71df7d311697f6c04fa9828d7d6513ac7cbf/tattl-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8a814f4da16e74917d713744ca4a02cfaecf0ae2903a606b02f931c299328be0",
                "md5": "c8516a66eee3d27456c13971bf16b785",
                "sha256": "523cbeefb7a7f0045bf6417709e77b09fbad62313f44bfde5af84076046842eb"
            },
            "downloads": -1,
            "filename": "tattl-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c8516a66eee3d27456c13971bf16b785",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 33293,
            "upload_time": "2024-12-17T21:19:21",
            "upload_time_iso_8601": "2024-12-17T21:19:21.899207Z",
            "url": "https://files.pythonhosted.org/packages/8a/81/4f4da16e74917d713744ca4a02cfaecf0ae2903a606b02f931c299328be0/tattl-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-17 21:19:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thcrt",
    "github_project": "tattl",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "tattl"
}
        
Elapsed time: 0.41965s