Data templates for Python - dynamically fill complex dictionaries with values
Project description
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+:
pip3 install template-dict
How to use
See the user guide 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.
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.
t = Template(['[name]', '[name]', '[name]'])
t.eval({'name': 'dogs'}) # -> ["dogs", "dogs", "dogs"]
You can access template keys before evaluating it.
t = Template({'value': '[key]'})
t.keys # -> ['key']
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 Distributions
Built Distribution
File details
Details for the file template_dict-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: template_dict-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdf4cbaa8692ff66fb16c9c11f28238cedd4645645c9964140912dd8a89c5806 |
|
MD5 | 209c3688198544d2cf3d084ea8b707f0 |
|
BLAKE2b-256 | 58c6aa16a9500a57d9c5662d19373a3e68dc8f2b141564cffcc60bc3967dd65c |