# libtmux.Pane.from_env

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** method
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/pane.py#L211
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-pane-from_env/

```
libtmux.Pane.from_env(
    cls, env: t.Mapping[str, str] | None = None
) -> Pane
```

Return the pane this process is running inside of.

Reads ``$TMUX`` for the server's socket and ``$TMUX_PANE`` for the pane
id, then asks tmux for the rest. The stale session id inside ``$TMUX``
is never consulted, so the answer stays correct after the pane's window
has been moved or linked elsewhere.

## Examples

```python
>>> socket_path = server.cmd(
...     "display-message", "-p", "-t", pane.pane_id, "#{socket_path}"
... ).stdout[0]
>>> env = {"TMUX": f"{socket_path},1,0", "TMUX_PANE": pane.pane_id}
```

```python
>>> Pane.from_env(env)
Pane(%1 Window(@1 1:..., Session($1 ...)))
```

```python
>>> Pane.from_env(env).pane_id == pane.pane_id
True
```

Outside a pane there is nothing to resolve:

```python
>>> from libtmux import exc
>>> try:
...     Pane.from_env({})
... except exc.NotInsideTmux as e:
...     print(e)
Not inside a tmux pane: $TMUX is unset or empty
```

## Parameters

- `env` (`t.Mapping[str, str] | None`): Environment to read. Defaults to :data:`os.environ`, which is what
a process running inside a pane wants; pass an explicit mapping to
resolve on behalf of another pane.

## Returns

:class:`Pane`

## Raises

- [`NotInsideTmux`](/en/py/stable/reference/libtmux-exc-notinsidetmux/): When ``$TMUX`` or ``$TMUX_PANE`` is unset or malformed.
- [`TmuxObjectDoesNotExist`](/en/py/stable/reference/libtmux-exc-tmuxobjectdoesnotexist/): When the pane named by ``$TMUX_PANE`` is gone.
- [`LibTmuxException`](/en/py/stable/reference/libtmux-exc-libtmuxexception/): When the server named by ``$TMUX`` is unreachable.
