> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK: environment variables

> Read, add, replace and remove the environment variables of a Square Cloud application with client.apps.envs in the Python SDK (squarecloud-api).

Environment variables live on `client.apps.envs`. Every method takes the app id first and returns the app's variables as a plain `dict[str, str]`.

Examples use the `client` from [Creating the client](/en/sdks/py/client#creating-the-client). `app_id` is the id of one of your apps: [`client.account.me()`](/en/sdks/py/client#account) lists them.

<Note>
  Static apps have no environment variables: every method answers 400 `STATIC_APP_ENV_NOT_SUPPORTED`. A change takes effect on the next [restart](/en/sdks/py/managing_application#start-stop-and-restart).
</Note>

## Reading the variables

```python theme={"system"}
envs = client.apps.envs.get(app_id)

print(envs.get("NODE_ENV"))
```

## Adding or updating variables

`envs.set(app_id, envs)` adds the given keys and overwrites the ones that already exist. Other variables are kept. It returns every variable after the change.

```python theme={"system"}
envs = client.apps.envs.set(app_id, {
    "NODE_ENV": "production",
    "LOG_LEVEL": "info",
})
```

## Replacing every variable

`envs.replace(app_id, envs)` replaces **all** variables with the given set. Keys not in the dict are removed. `{}` clears them all.

```python theme={"system"}
client.apps.envs.replace(app_id, {"NODE_ENV": "production"})
```

## Removing variables

`envs.delete(app_id, keys)` removes the given keys and returns the remaining variables. `keys` is a list (any iterable of strings) or a single key.

```python theme={"system"}
remaining = client.apps.envs.delete(app_id, ["LOG_LEVEL"])

# A single key also works
remaining = client.apps.envs.delete(app_id, "LOG_LEVEL")
```

## Limits and errors

| Status | Code | When |
| - | - | - |
| 400 | `STATIC_APP_ENV_NOT_SUPPORTED` | The app is static |
| 400 | `INVALID_ENV_CONTENT` | The variables are not a valid object (or, for `delete`, an empty list) |
| 400 | `TOO_MANY_ENV_VARS` | The result would have more than 256 variables |
| 400 | `ENV_NAME_TOO_LONG` | A key is over 1024 characters |
| 400 | `ENV_CONTENT_TOO_LONG` | A value is over 4096 characters |
| 400 | `READ_FAILED` | The cluster could not read the variables |

## Next steps

<CardGroup cols={2}>
  <Card title="Deploys" icon="github" href="/en/sdks/py/deploys">
    Deploy on every push, with a webhook or the GitHub App.
  </Card>

  <Card title="Environment variables API reference" icon="code" href="/en/api-reference/endpoint/apps/envs/get">
    The REST endpoints behind these methods.
  </Card>

  <Card title="Variables from the CLI" icon="terminal" href="/en/cli-reference/environment-variables">
    The same actions from the terminal.
  </Card>

  <Card title="Read variables in your code" icon="gear" href="/en/platform/environment-variables">
    Set variables from the dashboard, CLI or API and read them at runtime.
  </Card>
</CardGroup>
