Skip to main content

jinjasubst

What does it do?

Renders the stdin as a Jinja2 template, with the current environment variables as arguments.

Installation

pip install jinjasubst

or:

pipx install jinjasubst

Quirks

The jinja2 environment is initialized with a FileSystemLoader. The searchpath of this loader is the parent directory of the input file. When the input file is - (stdin), the current working directory is used instead.

Functions and filters

Files and directories:

  • read - read a file
  • listdir - list entries in a directory

Encoding and escaping:

  • toshell - escape using shlex.quote
  • yaml, toyaml - encode to yaml
  • fromyaml - decode from yaml
  • base64, tobase64 - encode to base64
  • frombase64 - decode from base64
  • hex, tohex - encode to hex
  • fromhex - decode from hex

Process execution, enabled with -s (all accept stdin when used as filters):

  • shell - execute shell command
  • shell_check - execute shell command and check exit code
  • exec - execute program with arguments
  • exec_check - execute program with arguments and check exit code

Usage examples

# Format a template file
jinjasubst < kubernetes.yml | kubectl apply -f -

# Format from file path
jinjasubst -i kubernetes.yml -o rendered.yml

# Using shortened versions
jsubst -i kubernetes.yml > rendered.yml
jenvsubst -i kubernetes.yml > rendered.yml
j2subst -i kubernetes.yml > rendered.yml
j2envsubst -i kubernetes.yml > rendered.yml

# Using the shell global
jinjasubst -s <<'EOF'
Hello {{ USER }}, the date is {{ shell("date +%s") }}
EOF

# Using the shell filter
jinjasubst -s <<'EOF'
Hello {{ USER }}, your reversed name is {{ USER | shell("rev") }}
EOF

Usage in development

# Inline example
python3 -m src.jinjasubst.cli -s <<'EOF'
Hello {{ USER }}, it is {{ shell("date") | tojson }}
Hello {{ USER }}, let's run some docker {{ exec_check("docker", "image", "ls") }}
EOF

# Run from file
python3 -m src.jinjasubst.cli -s < ./examples/shell.j2

Metadata

Release files for jinjasubst 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinjasubst 0.4.1
File Size Uploaded Provenance Actions
jinjasubst-0.4.1.tar.gz 5.1 kB Without provenance Details for jinjasubst-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jinjasubst 0.4.1
File Interpreter ABI Platform Actions
jinjasubst-0.4.1-py3-none-any.whl Python 3 none any Details for jinjasubst-0.4.1-py3-none-any.whl

Total release size: 10.5 kB

Release files / jinjasubst-0.4.1.tar.gz

Download URL jinjasubst-0.4.1.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3e3df31482ad6b00e41459fd511a3e504d3c18071f893d0c91daad1f6d1210cf
BLAKE2b-256 checksum
How to use checksums
8c317a96b98aa669a5a69edeca1d588e8ed31c0a0b957a09e330fa7b9f80eee1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / jinjasubst-0.4.1-py3-none-any.whl

Download URL jinjasubst-0.4.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4bf8c64675cb3182b773aeffbcd33f887dfd8e3ebecade23992c7d58c590799
BLAKE2b-256 checksum
How to use checksums
dcfc2bd0bef174f0d9be892b896f0a0fb3ab4a31aa6efc07c28c50c84e781b10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for jinjasubst 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page