Skip to main content

Simple parameter substitution using environment variables

Project description

EnvTpl
======

_Simple parameter substitution using environment variables_

Installation
------------

pip install envtpl

Usage
-----

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

# file1.py
my_first_string = '{{ FOO }}'
my_second_string = '{{ BAR|def }}'

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

FOO=abc envtpl < file1.py.tpl

the following will be written to stdout:

# file1.py
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 ./envtpl.py < file1.py.tpl

you get

# file1.py
my_first_string = 'abc'
my_second_string = '123'

You can also give envtpl a filename

$ ls
file1.py.tpl

$ envtpl -f file1.py.tpl
$ ls
file1.py

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 file1.py.tpl --keep-template

You can also explicitly specify the output file

envtpl -f file1.py.tpl --output-file file2.py

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 < file_with_missing_vars.py.tpl

What's the point?
-----------------

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

#!/bin/bash
# start.sh

envtpl -f /etc/redis.conf.tpl

redis-server

To me, that's a bit cleaner than http://blog.james-carr.org/2013/09/04/parameterized-docker-containers/

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

envtpl-0.1.2.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file envtpl-0.1.2.tar.gz.

File metadata

  • Download URL: envtpl-0.1.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for envtpl-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0a991fb621e1b91a82e8a84b87544193a13411360c22a8b9d3e03a5132cb529c
MD5 d9660a84eecd15de0b3630a6361c8229
BLAKE2b-256 02b2ca3d3d210a0559df0b6ef3003ab5d365403877010e4d18a625782b7a3f9a

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