To initialize the environment stack in Python, use the init function:
>>> envstack.init()
>>> os.getenv("HELLO")
'world'To initialize the "dev" stack:
>>> envstack.init("dev")
>>> os.getenv("ENV")
'dev'To revert the original environment:
>>> envstack.revert()
>>> os.getenv("HELLO")
>>> Creating and resolving environments:
>>> from envstack.env import Env, resolve_environ
>>> env = Env({"BAR": "${FOO}", "FOO": "foo"})
>>> resolve_environ(env)
{'BAR': 'foo', 'FOO': 'foo'}Authoring environments using Python:
>>> env = Env({"FOO": "bar", "BAR": "${FOO}"})
>>> env.write("out.env")Get the resolved values back:
$ ./out.env -r
BAR=bar
FOO=barCreate an encrypted environment:
>>> from envstack.env import Env, encrypt_environ
>>> env = Env({"SECRET": "super_secret", "PASSWORD": "my_password"})
>>> encrypted = encrypt_environ(env)Loading and resolving predefined environments from stack files:
>>> from envstack.env import load_environ, resolve_environ
>>> env = load_environ(name)
>>> resolved = resolve_environ(env)The following environment variables are used to help manage functionality:
| Name | Description |
|---|---|
| ALLOW_COMMANDS | Allow embedded commands |
| COMMAND_TIMEOUT | Embedded command timeout in seconds |
| DEFAULT_NAMESPACE | Name of the default environment stack (default) |
| ENVPATH | Colon-separated paths to search for environment files |
| IGNORE_MISSING | Ignore missing stack files when resolving environments |
| INTERACTIVE | Force shells to run in interactive mode |
| STACK | Stores the name of the current environment stack |