Skip to main content

Sprinkling imperative logic into your template generation process.

Project description

Templatizer

Templatizer allows for sprinkling in some imperative logic to your declarative configuration files.

Why Imperative?

While a fully declarative configuration file is often nice to be able to describe the intended state of the world in a single place, these can also become quite verbose over time.

For Kubernetes, for example, you might be configuring a number of monitoring jobs. These will have different storage, CPU, and memory requirements. They also have unique configuration requirements for each one. I might be holding it wrong, but I find this very hard to make work in Helm and Kustomize without repeating myself over and over again.

What I want is something that runs before Helm, Kustomize, and whatever other tools you're using. I want something to generate files with the ability to do imperative logic first.

Example

import templatizer

class Simple(templatizer.Templatable):
    prop = 12345

class Imperative(templatizer.Templatable):
    tick = 0

    def prop(self):
        return 12345 + self.tick

simple = Simple()
assert simple.propval('prop') == 12345

imperative = Imperative()
assert imperative.propval('prop') == 12345
imperative.tick = 1
assert imperative.propval('prop') == 12346

The templatizer.run function takes a list of Templatable objects, generates them into strings, and adds separators in between. By default the --- separator is used, which is useful for generating YAML documents. This can be changed to suit your use case.

Kubernetes

The templatizer.k8s module includes generated definitions from the Kubernetes OpenAPI Spec.

This allows for generating Kubernetes manifests with imperative hooks. Examples of this are provided in the examples/ directory.

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

pytemplatize-0.0.1.tar.gz (73.4 kB view details)

Uploaded Source

Built Distribution

pytemplatize-0.0.1-py3-none-any.whl (75.1 kB view details)

Uploaded Python 3

File details

Details for the file pytemplatize-0.0.1.tar.gz.

File metadata

  • Download URL: pytemplatize-0.0.1.tar.gz
  • Upload date:
  • Size: 73.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pytemplatize-0.0.1.tar.gz
Algorithm Hash digest
SHA256 dc6f4f351b97d6f4eaacea83aa772399848a1f44cf16b16390081c01d5e36668
MD5 d03e73b6290395f0d3c87b78cb78b3d0
BLAKE2b-256 7be6a922c741f9f2705d71d2c821939c5db4fb3039ba8d0214c46aedfb13dbcb

See more details on using hashes here.

File details

Details for the file pytemplatize-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pytemplatize-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 75.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for pytemplatize-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e045f8d9fffaa2ec6d664c420894286c428186258b8f2ee2345dab92b8f632fa
MD5 0ba9ecd2b10dbb5eaa9d2163e97039be
BLAKE2b-256 22822c71fe3fa9406e4e43366f0853b3eef99b050337316c6d00d10da7866cd0

See more details on using hashes here.

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