Skip to main content

Simple parameter substitution using environment variables

Project description


_Simple parameter substitution using environment variables_


pip install envtpl


This is a Python script that does basic parameter substitution from the command line. For example, if you have a file called that looks like

my_first_string = '{{ FOO }}'
my_second_string = '{{ BAR|def }}'

If you pipe that file through, with FOO defined in the shell

FOO=abc envtpl <

the following will be written to stdout:

my_first_string = 'abc'
my_second_string = 'def'

Here, BAR=def was made default, by putting "def" after the pipe symbol (|). If you define BAR at the command line

FOO=abc BAR=123 ./ <

you get

my_first_string = 'abc'
my_second_string = '123'

You can also give envtpl a filename

$ ls

$ envtpl -f
$ ls

The input file will be parsed and stripped of the .tpl extension. You can keep the original template by passing in the --keep-template flag

envtpl -f --keep-template

You can also explicitly specify the output file

envtpl -f --output-file

If an environment variable is missing, the default behaviour is for envtpl to die with exit code 1. You can change that behaviour to insert empty strings instead by passing the --allow-missing flag

envtpl --allow-missing <

What's the point?

I use this script a lot in Docker images, typically in a file called A redis startup script could look something like this:


envtpl -f /etc/redis.conf.tpl


To me, that's a bit cleaner than

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for envtpl, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size envtpl-0.1.1.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page