metwork-framework / jinja2_getenv_extension

a jinja2 extension to access to system environment variables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jinja2_getenv_extension

Status (master branch)

GitHub CI Maintenance

What is it ?

This is a jinja2 extension to access to system environment variables. It is usefull if you have dynamically generated variable names.

Syntax

The syntax is {{ 'ENV_VAR'|getenv }} to access to the ENV_VAR environment variable. Don't forget the quotes around ENV_VAR !

If you want to provide a default value to avoid an exception if the corresponding environment variable does not exist, you can use the following syntax: {{ 'ENV_VAR'|getenv('default_value') }}.

Examples

from jinja2 import Template, Environment

# We load the extension in a jinja2 Environment
env = Environment(extensions=["jinja2_getenv_extension.GetenvExtension"])

# For the example, we use a template from a simple string
template = env.from_string("the value of HOME environment variable is: "
                           "{{ 'HOME'|getenv }}")
result = template.render()

# [...]

Contributing guide

See CONTRIBUTING.md file.

Code of Conduct

See CODE_OF_CONDUCT.md file.

Sponsors

(If you are officially paid to work on MetWork Framework, please contact us to add your company logo here!)

logo

About

a jinja2 extension to access to system environment variables

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 90.6%Language:Makefile 9.4%