#! /usr/bin/env -S pip-run Jinja2==3.*
from jinja2 import Environment
env = Environment(autoescape=True)
template = env.from_string("Hello, {{ name }}!")
print(template.render(name="world"))
There is a downside. Because pip-run recreates the virtualenv every time, the script takes a second to start up. pipx will cache virtualenvs once the single-file script feature is released. I haven't used fades yet.
Edit: fades caches virtualenvs.
#! /usr/bin/env fades
from jinja2 import Environment # fades Jinja2==3.*
env = Environment(autoescape=True)
template = env.from_string("Hello, {{ name }}!")
print(template.render(name="world"))
For example,
There is a downside. Because pip-run recreates the virtualenv every time, the script takes a second to start up. pipx will cache virtualenvs once the single-file script feature is released. I haven't used fades yet.Edit: fades caches virtualenvs.