Welcome to jinja2-shell documentation!

Installation & Usage

jinja2-shell

CI Status Documentation Status Test coverage percentage

Poetry black pre-commit

PyPI Version Supported Python versions License

Jinja2 Extension for running shell commands. Makes use of subprocess.run(shell=False).

Installation

Install this via pip (or your favourite package manager):

pip install jinja2-shell

Usage

The extension class is jinja2_shell.ShellExtension.

If the second argument is True (default), the output is stripped of trailing whitespace and newlines. (a\n\b \n -> a\nb)

As a statement:

{% shell "echo Hello World" %}
{% shell "echo Hello World", False %}
{% shell "echo 'Hello World', False %}
{% shell "echo \"Hello World\"", False %}
Hello World
Hello World (Ubuntu), Hello World\n (Windows)
Hello World (Ubuntu), Hello World\n (Windows)
Hello World (Ubuntu), Hello World\n (Windows)

As a expression:

{{ "echo Hello World" | shell }}
{{ "echo Hello World" | shell(False) }}
{{ "echo 'Hello World'" | shell(False) }}
{{ "echo \"Hello World\"" | shell(False) }
Hello World
Hello World (Ubuntu), Hello World\n (Windows)
Hello World (Ubuntu), Hello World\n (Windows)
Hello World (Ubuntu), Hello World\n (Windows)

Contributors ✨

Thanks goes to these wonderful people (emoji key):

34j
34j

💻 🤔 📖

This project follows the all-contributors specification. Contributions of any kind welcome!