# Architecture

Source: https://libtmux.org/en/py/stable/topics/architecture/

> Locate operations, distinguish snapshots from live commands, and find their implementation.

A server handle selects a tmux server. Object IDs select sessions, windows, and
panes within it. For the object hierarchy and stable IDs, start with [Server,
session, window, pane](https://libtmux.org/en/py/stable/concepts/server-session-window-pane/).

<a id="where-behavior-lives-on-the-object-or-through-the-server"></a>

## Calling operations

Session, window, and pane handles carry their ID and server context. Call an
operation on the object you want to change. The examples below send input and
kill that pane.

```python
pane.send_keys("echo hi")
pane.kill()
```

<a id="a-generated-data-table-under-a-hand-written-surface"></a>

## Reading tmux fields

Object IDs become tmux targets (`-t`). Format variables (`#{...}`) provide
the state returned by tmux.

[`libtmux.constants`](<https://libtmux.org/en/py/stable/reference/#libtmux.constants>) defines the format fields and their scope and tmux-version
requirements. [`Obj`](<https://libtmux.org/en/py/stable/reference/libtmux-neo-obj/>) in [`libtmux.neo`](<https://libtmux.org/en/py/stable/reference/#libtmux.neo>) exposes the captured values as dataclass
fields. A field excluded by those requirements is [`None`](<https://docs.python.org/3/library/constants.html#None>).

<a id="module-layout-by-port"></a>

## Source layout

[`Server`](<https://libtmux.org/en/py/stable/reference/libtmux-server/>), [`Session`](<https://libtmux.org/en/py/stable/reference/libtmux-session/>), [`Window`](<https://libtmux.org/en/py/stable/reference/libtmux-window/>), [`Pane`](<https://libtmux.org/en/py/stable/reference/libtmux-pane/>), and [`Client`](<https://libtmux.org/en/py/stable/reference/libtmux-client/>) each have their own module:
[`src/libtmux/server.py`](<https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/server.py>), [`src/libtmux/session.py`](<https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/session.py>), [`src/libtmux/window.py`](<https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/window.py>),
[`src/libtmux/pane.py`](<https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/pane.py>), and [`src/libtmux/client.py`](<https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/client.py>).

[`src/libtmux/common.py`](<https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/common.py>) holds shared behavior. [`src/libtmux/neo.py`](<https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/neo.py>) defines
the dataclass query layer, [`src/libtmux/options.py`](<https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/options.py>) and [`src/libtmux/hooks.py`](<https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/hooks.py>)
provide mixins, and [`src/libtmux/exc.py`](<https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/exc.py>) defines the exception hierarchy.
