template-dict


Nametemplate-dict JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/violet-black/template-dict
SummaryData templates for Python - dynamically fill complex dictionaries with values
upload_time2024-04-13 14:20:04
maintainerNone
docs_urlNone
authorvioletblackdev@gmail.com
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![pypi](https://img.shields.io/pypi/v/template-dict.svg)](https://pypi.python.org/pypi/template-dict/)
[![docs](https://readthedocs.org/projects/template-dict/badge/?version=latest&style=flat)](https://template-dict.readthedocs.io)
[![codecov](https://codecov.io/gh/violet-black/template-dict/graph/badge.svg?token=FEUUMQELFX)](https://codecov.io/gh/violet-black/template-dict)
[![tests](https://github.com/violet-black/template-dict/actions/workflows/tests.yaml/badge.svg)](https://github.com/violet-black/template-dict/actions/workflows/tests.yaml)
[![mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

[![python](https://img.shields.io/pypi/pyversions/template-dict.svg)](https://pypi.python.org/pypi/template-dict/)

**template-dict** - JSON compatible Python dictionary templates. You can use them to fill some schema with data
dynamically. Template dicts support nested data, lists. functions and eval of simple Python data types.

# Installation

With pip and python 3.8+:

```bash
pip3 install template-dict
```

# How to use

See the [user guide](https://template-dict.readthedocs.io/guide.html) for more info.

`Template` objects can be used to fill dictionary-like schema with dynamic data.

Note that these are not Jinja templates but rather a tool to manipulate Python data dynamically.
To create a template you must define a schema and then feed it with some data mapping.

```python
from template_dict import Template

t = Template({'value': '[key.nested]'})
t.eval({'key': {'nested': True}})  # -> {'value': True}
```

Template can accept a string or an iterable as a schema.

```python
t = Template(['[name]', '[name]', '[name]'])
t.eval({'name': 'dogs'})  # -> ["dogs", "dogs", "dogs"]
```

You can access template keys before evaluating it.

```python
t = Template({'value': '[key]'})
t.keys  # -> ['key']
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/violet-black/template-dict",
    "name": "template-dict",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "violetblackdev@gmail.com",
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "[![pypi](https://img.shields.io/pypi/v/template-dict.svg)](https://pypi.python.org/pypi/template-dict/)\n[![docs](https://readthedocs.org/projects/template-dict/badge/?version=latest&style=flat)](https://template-dict.readthedocs.io)\n[![codecov](https://codecov.io/gh/violet-black/template-dict/graph/badge.svg?token=FEUUMQELFX)](https://codecov.io/gh/violet-black/template-dict)\n[![tests](https://github.com/violet-black/template-dict/actions/workflows/tests.yaml/badge.svg)](https://github.com/violet-black/template-dict/actions/workflows/tests.yaml)\n[![mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)\n[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n[![python](https://img.shields.io/pypi/pyversions/template-dict.svg)](https://pypi.python.org/pypi/template-dict/)\n\n**template-dict** - JSON compatible Python dictionary templates. You can use them to fill some schema with data\ndynamically. Template dicts support nested data, lists. functions and eval of simple Python data types.\n\n# Installation\n\nWith pip and python 3.8+:\n\n```bash\npip3 install template-dict\n```\n\n# How to use\n\nSee the [user guide](https://template-dict.readthedocs.io/guide.html) for more info.\n\n`Template` objects can be used to fill dictionary-like schema with dynamic data.\n\nNote that these are not Jinja templates but rather a tool to manipulate Python data dynamically.\nTo create a template you must define a schema and then feed it with some data mapping.\n\n```python\nfrom template_dict import Template\n\nt = Template({'value': '[key.nested]'})\nt.eval({'key': {'nested': True}})  # -> {'value': True}\n```\n\nTemplate can accept a string or an iterable as a schema.\n\n```python\nt = Template(['[name]', '[name]', '[name]'])\nt.eval({'name': 'dogs'})  # -> [\"dogs\", \"dogs\", \"dogs\"]\n```\n\nYou can access template keys before evaluating it.\n\n```python\nt = Template({'value': '[key]'})\nt.keys  # -> ['key']\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Data templates for Python - dynamically fill complex dictionaries with values",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/violet-black/template-dict"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9ac820bf7a0c9a29862d6f39bceb6c8695f5b716e5f88592d778fd7c53af7f19",
                "md5": "ead4d99a60e600c262e8aca64d3f7830",
                "sha256": "80f312ea85dae9de66d0e2450551ab77e7a4503ba9ea99718e1f50fbd8fb6e4d"
            },
            "downloads": -1,
            "filename": "template_dict-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ead4d99a60e600c262e8aca64d3f7830",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7122,
            "upload_time": "2024-04-13T14:20:04",
            "upload_time_iso_8601": "2024-04-13T14:20:04.943121Z",
            "url": "https://files.pythonhosted.org/packages/9a/c8/20bf7a0c9a29862d6f39bceb6c8695f5b716e5f88592d778fd7c53af7f19/template_dict-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-13 14:20:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "violet-black",
    "github_project": "template-dict",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "template-dict"
}
        
Elapsed time: 0.56352s