Skip to content

EnvVarContext

The EnvVarContext captures an environment variable. It can be created using the capsula.EnvVarContext.__init__ method.

capsula.EnvVarContext.__init__

__init__(name: str)
PARAMETER DESCRIPTION
name

Name of the environment variable

TYPE: str

Source code in capsula/_context/_envvar.py
def __init__(self, name: Annotated[str, Doc("Name of the environment variable")]) -> None:
    self.name = name

Configuration example

Via capsula.toml

[pre-run]
contexts = [
  { type = "EnvVarContext", name = "HOME" },
]

Via @capsula.context decorator

import capsula

@capsula.run()
@capsula.context(capsula.EnvVarContext("HOME"), mode="pre")
def func(): ...

Output example

The following is an example of the output of the EnvVarContext, reported by the JsonDumpReporter:

"env": {
  "HOME": "/home/nomura"
}