Skip to main content

a jinja2 extension to access to system environment variables

Project description

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 {% raw %}{{ 'ENV_VAR'|getenv }}{% endraw %} 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: {% raw %}{{ 'ENV_VAR'|getenv('default_value') }}{% endraw %}.

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: "
                           "{% raw %}{{ 'HOME'|getenv }}{% endraw %}")
result = template.render()

# [...]

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

jinja2_getenv_extension-1.0.1.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

jinja2_getenv_extension-1.0.1-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

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