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.8.tar.gz (82.6 kB view details)

Uploaded Source

Built Distribution

pytemplatize-0.0.8-py3-none-any.whl (84.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytemplatize-0.0.8.tar.gz
  • Upload date:
  • Size: 82.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for pytemplatize-0.0.8.tar.gz
Algorithm Hash digest
SHA256 e0cfe5815cd9b4abd3c71882b1950b31433aeb2da988ca367279205dc2322ac9
MD5 3ec6bb9978ab08e22e4a3fb04f02ff81
BLAKE2b-256 db15017a77084178b1261f9d5d28fda3b73365c057d9f96deaccbbbc2f92b3f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytemplatize-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 84.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for pytemplatize-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 b49bc2600128aba714bd548a11d0b2ac7820c219657b5b74418fe81554316059
MD5 523c60a3ebae1aa0d2defffbc288bd8d
BLAKE2b-256 2e34625677ab748e758ea77fddc2f05a109d9987984e7f0e83fa499c0e77b4cb

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