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$ $product$(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 426'

# 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.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: dinterpol-0.3.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

File hashes

Hashes for dinterpol-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ae8622dd958b01360254bcc8bd5a4ba8327688a90a7b241e5871a5291568868c
MD5 f30fa205e63abc755ae4e7daba693069
BLAKE2b-256 fb8ece776fa39ec2923663af58fd8efb6d07f3dc9129b3afc27a26acec92a30d

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: dinterpol-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.2

File hashes

Hashes for dinterpol-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 463fa065e99ca3fbf1b2efe4e1f915ae11690373b36e50dd6d46f5f656d1b659
MD5 33629aa911604bc538994e6789a8519e
BLAKE2b-256 0eaf7db626413f05eb04bd07362373e928afec33cae0d28fd662da59438afed3

See more details on using hashes here.

Provenance

Supported by

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