atmos.env
The atmos.env function runs atmos env through the current Atmos executable. Use it to read the variables
from the env section of atmos.yaml as JSON, a dotenv file, shell exports, or GitHub Actions output.
Usage
atmos.env(
*positionals,
flags = {},
args = [],
working_directory = ...,
env = ...,
output = "stream",
check = True,
)
Subcommands
The env command has no subcommands. The bare call atmos.env() runs atmos env and prints the variables in
bash format. Choose another format with the format flag. See the atmos env command reference
for the complete list of flags.
Arguments
*positionals(Optional) Strings placed on the command line right after
env. The command takes no positional arguments, so a call usually passes none.flags(Optional) A dictionary of command-line options; see flag translation. The
formatkey becomes--format(shorthandf) and acceptsbash,json,dotenv, orgithub. Theexportkey controls theexportprefix inbashformat, andoutput-file(shorthando) writes the result to a file.args- (Optional) A list or tuple of strings appended after the flags.
working_directory,env,output,check(Optional) See
atmos.runfor process options and defaults.
Options other than the positionals are keyword-only.
Returns
A result with stdout, stderr, and exit_code. See atmos.run for output and error behavior.
Examples
Read the variables as a dictionary
result = atmos.env(flags = {"format": "json"}, output = "capture")
variables = json.decode(result.stdout)
for key in sorted(variables.keys()):
print(key)
Write a dotenv file
atmos.env(flags = {"format": "dotenv", "output-file": ".env"})
This runs atmos env --format=dotenv --output-file=.env.
Print shell assignments without the export prefix
assignments = atmos.env(flags = {"export": False}, output = "capture")
print(assignments.stdout)
The False value becomes --export=false.
Related
atmos.runruns any Atmos command from an argument list.atmos envdocuments the command and its flags.- Atmos Automation Language and the script step