# libtmux.Session.set_environment

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/common.py#L64
- **Inherited from:** libtmux.common.EnvironmentMixin
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-session-set_environment/

```
libtmux.Session.set_environment(
    self,
    name: str,
    value: str,
    expand_format: bool | None = None,
    hidden: bool | None = None,
) -> None
```

Set environment [`$ tmux set-environment <name> <value>`](/en/tmux/latest/manual/set-environment/).

## Parameters

- `name` (`str`): The environment variable name, e.g. 'PATH'.
- `value` (`str`): Environment value.
- `expand_format` (`bool | None`): Expand tmux format strings in the value (``-F`` flag). (added 0.56)
- `hidden` (`bool | None`): Mark the variable as hidden (``-h`` flag). (added 0.56)

## Raises

- [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError): If tmux returns an error.

## In other ports

### Set a variable in a session's environment

- Ruby: [`LibTmux::Session#set_environment`](/en/ruby/latest/reference/libtmux-session-set_environment/) (method)
- Lua: [`libtmux.Session:set_environment`](/en/lua/latest/reference/libtmux-session-set_environment/) (method)
- TypeScript: [`session.Session.setEnvironment`](/en/ts/latest/reference/session-session-setenvironment/) (method)
- Rust: [`session.Session.set_environment`](/en/rs/latest/reference/session-session-set_environment/) (method)
- Go: [`tmux.Session.SetEnvironment`](/en/go/latest/reference/tmux-session-setenvironment/) (method)
- Swift: [`Server.setEnvironment(_:to:in:)`](/en/swift/latest/reference/server-setenvironment(_-to-in-)/) (method)
