Skip to main content

Tests

Varsubst is a rewrite of envsubst.

Varsubst render templates from a string with a given resolver.

Currently varsubst support shell-like variables.

Entry-point has currently been removed. It may be added in the future.

Resolvers provided are :

  • EnvResolver : provide value based on environnement variables.
  • DictResolver : provide value based on a given python dictionary.

Supported template variables

Varsubst support shell-like variables which are defined as follows:

  • $MY_SIMPLE_VAR or ${MY_SIMPLE_VAR}: will resolve the variable MY_SIMPLE_VAR
  • ${USER-default} : will resolve the variable USER. If variable is unset then default string is returned.
  • ${USER-$DEFAULT_USER} : will resolve the variable USER. If variable is unset, resolve the variable DEFAULT_USER.
  • ${USER:-default} : will resolve the variable USER. If variable is unset or empty then default string is returned.
  • ${USER-$DEFAULT_USER} : will resolve the variable USER. If variable is unset or empty, resolve the variable DEFAULT_USER.

Usage

from varsubst import varsubst
from varsubst.resolvers import DictResolver
from varsubst.interpolators.jinja_interpolator import JinjaInterpolator

print(varsubst('$USER')) # result : 'tiboun'

print(varsubst('$UNDEFINED')) # result : KeyUnresolvedException('UNDEFINED')

print(varsubst('$UNDEFINED', fail_on_unresolved=False)) # result : ''

print(varsubst('$UNDEFINED', fail_on_unresolved=False)) # result : ''

print(varsubst('$USER', resolver=DictResolver({'USER': 'tiboun'})))

print(varsubst('{{ USER }}', interpolator=JinjaInterpolator()))

Extras

You may install varsubst[jinja2] as well if you intend to interpolate template with Jinja. If you plan to use jinja2 only, you may install it yourself in your project instead of using this one.

Metadata

Release files for varsubst 2.0.0

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

Source distribution (sdist)

Source distribution for varsubst 2.0.0
File Size Uploaded
varsubst-2.0.0.tar.gz 5.7 kB Details

Built distribution (wheel)

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

Total release size: 16.7 kB

Release files / varsubst-2.0.0.tar.gz

Download URL varsubst-2.0.0.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
54ed52fbc99ac085edd43c2d5e31e3bbd5f81fef39d4fd3b8bc180c65a908ec1
BLAKE2b-256 checksum
How to use checksums
6e5a1a195032b804fc31724c92f40b699366627403816dc92327762d7fc698ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0

Release files / varsubst-2.0.0-py3-none-any.whl

Download URL varsubst-2.0.0-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eab0164e903180504143882c89f02576cceb097c29a341d92352171312c854ee
BLAKE2b-256 checksum
How to use checksums
4d14d0e330807284bbb151cd5d6ecda611aed99d2e894876ae384dc9b7ff13bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

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