# libtmux._internal.env.socket_path_from_env

- **Module:** libtmux._internal.env
- **Package:** libtmux
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/_internal/env.py#L68
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-_internal-env-socket_path_from_env/

```
libtmux._internal.env.socket_path_from_env(
    env: t.Mapping[str, str] | None = None,
) -> str
```

Return the tmux socket path recorded in ``$TMUX``.

``$TMUX`` is ``"<socket_path>,<server_pid>,<session_id>"``. The pid and
session id are integers, so any comma in the value belongs to the socket
path -- split from the *right*.

The pid and session id are deliberately discarded: both are frozen at pane
spawn, and the session id goes stale as soon as the pane's window is moved
between sessions.

## Examples

```python
>>> from libtmux._internal.env import socket_path_from_env
>>> socket_path_from_env({"TMUX": "/tmp/tmux-1000/default,84215,0"})
'/tmp/tmux-1000/default'
```

A comma in the socket path is safe, because the split runs from the right:

```python
>>> socket_path_from_env({"TMUX": "/tmp/od,d/sock,84215,3"})
'/tmp/od,d/sock'
```

Outside tmux there is nothing to read:

```python
>>> socket_path_from_env({})
Traceback (most recent call last):
...
libtmux.exc.NotInsideTmux: 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`.

## Returns

str
    Path of the tmux server's socket.

## Raises

- [`NotInsideTmux`](/en/py/stable/reference/libtmux-exc-notinsidetmux/): When ``$TMUX`` is unset, empty, or not shaped like tmux's triple.
