data interpolation templating engine
Project description
dinterpol
dinterpol is a python library for data interpolation that supports both scalar and structured types generation.
Motivation
When dealing with structured data types like dictionaries, or data formats like JSON and YAML it can be useful to generate scalar or structured types resulting from the interpolation of multiple input elements. Python3 provides several standard string interpolation mechanisms: string.Template(), f-strings and str.format(), but because they all return strings, they are not suitable for structured with non string data interpolation.
Usage example:
from dinterpol import Template
data = {
"product": "pie",
"quantity": 33,
"price": 14,
"details": { "size": 10, "flavour": "orange"}
}
# simple key interpolation for string generation
Template("We have {quantity} pie(s)").render(data)
'We have 33 pie(s)'
# python expression for string generation, expression result concatnated with string
Template("Total price is {quantity * price}").render(data)
'Total price is 462'
# python expression for dict generation, type inferred directly from expression's eval()
Template({ "total": "{quantity * price}"}).render(data)
{'total': 426}
# Use attribute style references for key access
Template("{details.size}").render(data)
10
# You can disable the attribute style mapping by passing attribute_convert=False
# to the template constructor.
Template({"today is": "{now.day}"}, False).render({"now": datetime.now()})
Code of Conduct
Everyone interacting in the dinterpol project's codebase, issue trackers, chat rooms, and mailing lists is expected to follow the PyPA Code of Conduct.
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
Built Distribution
File details
Details for the file dinterpol-0.3.5.tar.gz
.
File metadata
- Download URL: dinterpol-0.3.5.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fca18a75fb0eaa5a82f38ee964fb92f71efab65a4795da56d41083b6af590c4 |
|
MD5 | 1e76ae112223e93d1f3cc97f8da90c68 |
|
BLAKE2b-256 | 6bb5c05253316deb2b310df2efaba27644ec9fc30e6f7f395b17dd1bb677f02b |
File details
Details for the file dinterpol-0.3.5-py3-none-any.whl
.
File metadata
- Download URL: dinterpol-0.3.5-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8176be0ab5d5135babb4b9d43f3b9dcc22184f6b32b30d039ecdde6dc0c39802 |
|
MD5 | fa301bb2f96749ba461d31144b6346ea |
|
BLAKE2b-256 | 1fbf1f190885f839a3dd9a033fa679cd81b271b3a1103bcf7a4b99afa5f93215 |