# 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

```python
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](/cli/commands/env)
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](/functions/automation/atmos.run#flag-translation). The `format` key becomes `--format`
  (shorthand `f` ) and accepts `bash`, `json`, `dotenv`, or `github`. The `export` key controls the
  `export` prefix in `bash` format, and `output-file` (shorthand `o` ) 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.run`](/functions/automation/atmos.run#arguments) for process options and defaults.

Options other than the positionals are keyword-only.

## Returns

A result with `stdout`, `stderr`, and `exit_code`. See [`atmos.run`](/functions/automation/atmos.run#returns) for output and error behavior.

## Examples

### Read the variables as a dictionary

```python
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

```python
atmos.env(flags = {"format": "dotenv", "output-file": ".env"})
```

This runs `atmos env --format=dotenv --output-file=.env`.

### Print shell assignments without the export prefix

```python
assignments = atmos.env(flags = {"export": False}, output = "capture")
print(assignments.stdout)
```

The `False` value becomes `--export=false`.

## Related

- [`atmos.run`](/functions/automation/atmos.run) runs any Atmos command from an argument list.
- [`atmos env`](/cli/commands/env) documents the command and its flags.
- [Atmos Automation Language](/automation/language) and the [script step](/steps/type/script#calling-atmos-commands)
