STR - Secret Template Renderer
Render Jinja2 templates with secrets injected from password managers and other providers. Supports encrypting values inline, generating ephemeral credential files, and loading custom plugins.
Installation
pipx install secret_template_renderer
Or with the optional encryption support (AES-256-GCM):
pipx install "secret_template_renderer[crypto]"
Quick start
# aws-creds.tmpl
[default]
aws_access_key_id={{ get_secret('bitwarden', 'aws-prod', 'field.access_key_id') }}
aws_secret_access_key={{ get_secret('bitwarden', 'aws-prod', 'field.secret_access_key') }}
str generate -f aws-creds.tmpl -o ~/.aws/credentials
Commands
generate — render a template
str generate -f <template> [-i <string>] [-o <output>] [-p <password>] [--allow-shell]
| Flag | Description |
|---|---|
-f, --file |
Path to the Jinja2 template file |
-i, --input |
Template content as a string (overrides -f) |
-o, --output |
Output file path (default: stdout) |
-p, --password |
Password for decrypt()/encrypt() — prefer STR_BASIC_PASSWORD env var; -p is visible in ps aux |
--allow-shell |
Enable the shell() template function (see Security) |
Template content can also be piped via stdin:
cat template.tmpl | str generate
session — ephemeral credential files
Renders a template to a temp file and prints shell code that exports its path as an environment variable and deletes the file on shell exit. No secrets persist after the session ends.
# fish
eval (str session -f aws-creds.tmpl --env AWS_SHARED_CREDENTIALS_FILE)
# bash / zsh
eval "$(str session -f aws-creds.tmpl --env AWS_SHARED_CREDENTIALS_FILE)"
What gets printed (fish):
set -x AWS_SHARED_CREDENTIALS_FILE /tmp/temv-a3f9c2
function __temv_cleanup_temv_a3f9c2 --on-event fish_exit
rm -f /tmp/temv-a3f9c2
set -e AWS_SHARED_CREDENTIALS_FILE
end
What gets printed (bash/zsh):
export AWS_SHARED_CREDENTIALS_FILE=/tmp/temv-a3f9c2
trap 'rm -f /tmp/temv-a3f9c2; unset AWS_SHARED_CREDENTIALS_FILE' EXIT
| Flag | Description |
|---|---|
-f, --file |
Path to the Jinja2 template file |
-i, --input |
Template content as a string (overrides -f) |
--env |
Environment variable name to point at the rendered temp file (required) |
--shell |
Shell syntax to emit: bash, zsh, or fish (default: auto-detect from $SHELL) |
-p, --password |
Password for decrypt() — prefer STR_BASIC_PASSWORD env var |
The temp file is created with 0600 permissions under /tmp with a temv- prefix.
encrypt / decrypt — manage inline secrets
str encrypt [-i <plaintext>] [-f <file>] [-o <output>] [-p <password>]
str decrypt [-i <ciphertext>] [-f <file>] [-o <output>] [-p <password>]
Encrypted values use AES-256-GCM (authenticated encryption) and are prefixed with v2:. Old AES-256-CBC values (no prefix) are still decryptable for backward compatibility.
The password is read from, in order:
STR_BASIC_PASSWORDenvironment variable-p/--passwordflag (avoid — visible inps auxand shell history)- Interactive prompt (up to 3 attempts)
The old TEMV_BASIC_PASSWORD and TEMV_PLUGIN_DIR names still work but log a deprecation warning.
age provider (key pairs, passphrase, SSH keys)
Select it with -e age. It uses the age and age-keygen binaries, which must be on PATH. Values are single-line age:<base64>; armored age files are accepted by decrypt too. In templates pass the provider as the second argument: {{ decrypt("age:YWdl...", "age") }}.
age-keygen -o ~/.config/str/key.txt
export STR_AGE_IDENTITY=~/.config/str/key.txt
str encrypt -e age -i "my secret" # recipient defaults to the key derived from the identity
str decrypt -e age -i "age:<base64>"
| Flag | Env var | Purpose |
|---|---|---|
-e, --encryption |
basic (default) or age |
|
--identity FILE |
STR_AGE_IDENTITY |
age/SSH private key file (decrypt) |
-r, --recipient KEYS |
STR_AGE_RECIPIENT |
Public key(s), comma-separated (encrypt) |
--identity-secret SPEC |
STR_AGE_IDENTITY_SECRET |
Fetch the private key via a secrets provider, provider:key[:path]; kept in memory, never written to disk |
--ssh-agent [FILTER] |
STR_AGE_SSH_AGENT |
Encrypt to the ed25519/rsa public keys held by the SSH agent; optional text filters by key comment |
--passphrase |
STR_AGE_PASSPHRASE |
Passphrase mode (also -p); prompts if none given. Needs the optional pyrage extra: pip install 'secret_template_renderer[age]' |
decrypt reads the value's header to choose passphrase or key mode.
An SSH agent (1Password, Bitwarden, ssh-agent) never hands out private keys, so age can encrypt to the agent's public keys but cannot decrypt through the agent:
str encrypt -e age --ssh-agent "my-key-comment" -i "my secret"
str decrypt -e age --identity-secret "1password:Private/my ssh key/private key" -i "age:..."
str decrypt -e age --identity-secret "bitwarden:my ssh key:sshKey.privateKey" -i "age:..."
Tested with Ed25519 keys in the Bitwarden and 1Password SSH agents. If age rejects a 1Password key, append ?ssh-format=openssh to the op:// reference (not needed for the Ed25519 key tested; RSA untested). provider:key[:path] splits on colons, so vault/item names must not contain :.
Template functions
get_secret(provider, item, path="")
Fetch a secret from a configured provider.
{{ get_secret('bitwarden', 'my-item', 'login.password') }}
{{ get_secret('1password', 'vault/item/field') }}
{{ get_secret('pass', 'email/personal') }}
Bitwarden path format: login.<field>, field.<custom_field_name> or sshKey.privateKey / sshKey.publicKey (SSH key items)
import_env(path)
Read a .env file and embed its contents. The path must be within the current working directory.
{{ import_env('.default.env') }}
decrypt(ciphertext, module="basic") / encrypt(plaintext, module="basic")
Decrypt or encrypt a value inline. The password comes from STR_BASIC_PASSWORD or the -p flag passed to generate.
DATABASE_PASSWORD={{ decrypt("v2:...") }}
random(length, type, ...)
Generate a random string.
{{ random(32) }}
{{ random(16, type="password") }}
{{ random(24, has_special_chars=True, must_has_special_chars=True) }}
| Parameter | Default | Description |
|---|---|---|
length |
16 |
Length of the output (1–4096) |
type |
"string" |
"string" or "password" (includes special chars) |
lower_case |
True |
Include lowercase letters |
numbers |
True |
Include digits |
has_special_chars |
False |
Include punctuation |
must_has_special_chars |
False |
Guarantee at least one special char (requires has_special_chars=True) |
exclude_characters |
"" |
Characters to exclude from the pool |
shell(command) ⚠️
Execute a shell command and return its stdout. Only available when --allow-shell is passed to generate or session. See Security.
{{ shell('aws sts get-caller-identity --query Account --output text') }}
Security
shell() is opt-in
shell() executes arbitrary OS commands and is not registered by default. Only enable it with --allow-shell when you fully trust the template source. Never use it with templates from untrusted repositories or generated configs.
import_env() is sandboxed
import_env() only reads files within the current working directory. Paths outside CWD (including .. traversals and absolute paths) are rejected.
Encryption
Values encrypted with str encrypt use AES-256-GCM with a PBKDF2-SHA256 key (600,000 iterations). GCM provides authenticated encryption — any tampering causes decryption to fail rather than returning corrupted data.
Custom plugins
Place plugin .py files in any of these locations:
| Location | Scope |
|---|---|
.temv/plugins/<type>/ |
Project-local |
$STR_PLUGIN_DIR/<type>/ |
User-global (env var) |
<type> is either secrets or encryptions.
Secret plugin
from collections.abc import Callable
def get_custom_secret(item_name: str, path: str) -> str | None:
# return None on any failure — never return ""
...
def register(providers: dict[str, Callable[[str, str], str | None]]):
providers["my_provider"] = get_custom_secret
Call it in templates as {{ get_secret('my_provider', 'item', 'path') }}.
Encryption plugin
from collections.abc import Callable
def encrypt(value: str, password: str | None) -> str | None:
...
def decrypt(value: str, password: str | None) -> str | None:
...
def register(providers: dict[str, dict[str, Callable]]):
providers["my_enc"] = {"encrypt": encrypt, "decrypt": decrypt}
Call it in templates as {{ decrypt("...", module="my_enc") }}.
License
MIT
Metadata
Release files for secret_template_renderer 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| secret_template_renderer-0.4.2.tar.gz | 21.7 kB | Without provenance | Details for secret_template_renderer-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| secret_template_renderer-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for secret_template_renderer-0.4.2-py3-none-any.whl |
Total release size: 40.3 kB
Release files / secret_template_renderer-0.4.2.tar.gz
| Download URL | secret_template_renderer-0.4.2.tar.gz |
|---|---|
| Size | 21.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b707d785d362f2affdb6c31e2b2b1f196400894f476495be1fcc2ffc3ee3671
|
|
BLAKE2b-256 checksum How to use checksums |
1c4b1b41ea5e1e2f6c64afbbb67f4241ddbb1903d056ff54a964d14a9c82246b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / secret_template_renderer-0.4.2-py3-none-any.whl
| Download URL | secret_template_renderer-0.4.2-py3-none-any.whl |
|---|---|
| Size | 18.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b7de25a6ceda6a26da3d792675e7c4408d7ee0593dde1d2a1f85c75b1bb6e41
|
|
BLAKE2b-256 checksum How to use checksums |
7b03adb20f03a19db7bed4a5a121e90716a5b1eaee510448278b71ac0b08e63f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for secret_template_renderer 0.4.2
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.