Skip to main content

Configuration builder which combines features of Jinja and YAML

Project description

configtpl

This library builds configuration in two stages:

  1. Renders the provided configuration as Jinja templates
  2. Parses the rendered data as YAML file

Features

  • Uses Jinja2 and Yaml capabilities to build a dynamic configuration
  • Multiple configuration files might be passed. The library merges all of them into single config.
  • Basic confuration includes Jinja functions and filters for general-purpose tasks:
    • Reading the environment variables
    • Execution of system commands
    • Hashing

Examples

You can check the functional tests folder for more examples.

A very simple example of usage is provided below:

# my_first_config.cfg

{% set my_val = "abc" %}
app:
  param_env: "{{ env('MY_ENV_VAR', 'default') }}"
  param1: "{{ my_val }}"
# my_second_config.cfg

app:
  param2: def
  param3: "{{ app.param1 }}123"
hash: "{{ app.param1 | md5 }}"
# app.py

import json
from configtpl.config_builder import ConfigBuilder

builder = ConfigBuilder()
cfg = builder.build_from_files("my_first_config.cfg:my_second_config.cfg")
print(json.dumps(cfg, indent=2))
# Execution

MY_ENV_VAR=testing python ./app.py

# output
{
  "app": {
    "param_env": "testing",
    "param1": "abc",
    "param2": "def",
    "param3": "abc123"
  },
  "hash": "900150983cd24fb0d6963f7d28e17f72"
}

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

configtpl-1.0.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

configtpl-1.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file configtpl-1.0.0.tar.gz.

File metadata

  • Download URL: configtpl-1.0.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for configtpl-1.0.0.tar.gz
Algorithm Hash digest
SHA256 619b638085dc11a6dfb463fa911d9677184ebf9bfe0e3c839c1544a362ce0349
MD5 260f8fef71d65ea8950f8fa19522f2db
BLAKE2b-256 df917577b95e648a77af09ad720aa6e4193b5ebe61542570a09fa07906c40f67

See more details on using hashes here.

File details

Details for the file configtpl-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: configtpl-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for configtpl-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29e3991695cd015322b696ab8cba2c8de0a94bc61673ba26f59618a92a419d17
MD5 1c629c92fe120587333455e2450203f1
BLAKE2b-256 2754a79d229bd78a5a10f727b8213e231c01e77a6d28fff5dba81c2d5e73cb6c

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