Skip to main content

data interpolation templating engine

Project description

dinterpol

PyPI Version Code style: black

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

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.

Source Distribution

dinterpol-0.3.6.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dinterpol-0.3.6-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file dinterpol-0.3.6.tar.gz.

File metadata

  • Download URL: dinterpol-0.3.6.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for dinterpol-0.3.6.tar.gz
Algorithm Hash digest
SHA256 c44c74d729f9879c5cb7c4bc113c376961e8c64bc02a215e2c91438713206026
MD5 3cfb2e55ca3ff867d9edda034ca5f9fc
BLAKE2b-256 a2854ddd743ae1d0329edc53acf0932c4f863de5f05cb0c5ec29524fe10dcad0

See more details on using hashes here.

File details

Details for the file dinterpol-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: dinterpol-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for dinterpol-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dc93aa75d5339fa8d8c9b59daea7ca952371ea83937b944dd344f73442f88c4a
MD5 34e337fbe99d7d57db6f2666e0d98ee6
BLAKE2b-256 110d6cf6fcb2737ab4b7b9814fbf72616b34bfcf65c342fc4afc5ab70db62949

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page