Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

data interpolation templating engine

Project description


PyPI Version Code style: black

dinterpol is a python library for data interpolation that supports both scalar and structured types generation.


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

# You can disable the attribute style mapping by passing attribute_convert=False
# to the template constructor.
Template({"today is": "{}"}, False).render({"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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for dinterpol, version 0.3.5
Filename, size File type Python version Upload date Hashes
Filename, size dinterpol-0.3.5-py3-none-any.whl (10.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size dinterpol-0.3.5.tar.gz (6.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page