# libtmux.Server

- **Module:** libtmux
- **Package:** libtmux
- **Language:** Python
- **Kind:** class
- **Source:** https://github.com/tmux-python/libtmux/blob/38e368c11117fb4aeb2f082d552cd4f210eae06a/src/libtmux/server.py#L85
- **Bases:** [`EnvironmentMixin`](/en/py/stable/reference/libtmux-common-environmentmixin/), [`OptionsMixin`](/en/py/stable/reference/libtmux-options-optionsmixin/), [`HooksMixin`](/en/py/stable/reference/libtmux-hooks-hooksmixin/)
- **Page:** https://libtmux.org/en/py/stable/reference/libtmux-server/

:term:`tmux(1)` :term:`Server` [server_manual]_.

- :attr:`Server.sessions` [:class:`Session`, ...]

  - :attr:`Session.windows` [:class:`Window`, ...]

    - :attr:`Window.panes` [:class:`Pane`, ...]

      - :class:`Pane`

When instantiated stores information on live, running tmux server.

## Examples

```python
>>> server
Server(socket_name=libtmux_test...)
```

```python
>>> server.sessions
[Session($1 ...)]
```

```python
>>> server.sessions[0].windows
[Window(@1 1:..., Session($1 ...))]
```

```python
>>> server.sessions[0].active_window
Window(@1 1:..., Session($1 ...))
```

```python
>>> server.sessions[0].active_pane
Pane(%1 Window(@1 1:..., Session($1 ...)))
```

The server can be used as a context manager to ensure proper cleanup:

```python
>>> with Server() as server:
...     session = server.new_session()
...     # Do work with the session
...     # Server will be killed automatically when exiting the context
```

## References

- [server_manual] CLIENTS AND SESSIONS. openbsd manpage for TMUX(1) "The tmux server manages clients, sessions, windows and panes. Clients are attached to sessions to interact with them, either when they are created with the new-session command, or later with the attach-session command. Each session has one or more windows linked into it. Windows may be linked to multiple sessions and are made up of one or more panes, each of which contains a pseudo terminal." https://man.openbsd.org/tmux.1#CLIENTS_AND_SESSIONS. Accessed April 1st, 2018.

## Members

### Collections and queries

- [`sessions`](/en/py/stable/reference/libtmux-server-sessions/) (property): Sessions contained in server.
- [`windows`](/en/py/stable/reference/libtmux-server-windows/) (property): Windows contained in server's sessions.
- [`panes`](/en/py/stable/reference/libtmux-server-panes/) (property): Panes contained in tmux server (across all windows in all sessions).
- [`clients`](/en/py/stable/reference/libtmux-server-clients/) (property): Clients attached to this tmux server.
- [`list_buffers`](/en/py/stable/reference/libtmux-server-list_buffers/) (method): List paste buffers via ``$ tmux list-buffers``.
- [`list_commands`](/en/py/stable/reference/libtmux-server-list_commands/) (method): List tmux commands via ``$ tmux list-commands``.
- [`list_keys`](/en/py/stable/reference/libtmux-server-list_keys/) (method): List key bindings via ``$ tmux list-keys``.
- [`list_clients`](/en/py/stable/reference/libtmux-server-list_clients/) (method): List connected clients via ``$ tmux list-clients``.
- [`search_panes`](/en/py/stable/reference/libtmux-server-search_panes/) (method): All panes across the server, optionally filtered by tmux.
- [`search_sessions`](/en/py/stable/reference/libtmux-server-search_sessions/) (method): Sessions, optionally filtered by tmux before rows are returned.
- [`search_windows`](/en/py/stable/reference/libtmux-server-search_windows/) (method): All windows across sessions, optionally filtered by tmux.

### Common operations

- [`new_session`](/en/py/stable/reference/libtmux-server-new_session/) (method): Create new session, returns new :class:`Session`.
- [`kill`](/en/py/stable/reference/libtmux-server-kill/) (method): Kill tmux server.
- [`source_file`](/en/py/stable/reference/libtmux-server-source_file/) (method): Source a tmux configuration file via ``$ tmux source-file``.
- [`set_buffer`](/en/py/stable/reference/libtmux-server-set_buffer/) (method): Set a paste buffer via ``$ tmux set-buffer``.
- [`is_alive`](/en/py/stable/reference/libtmux-server-is_alive/) (method): Return True if tmux server alive.
- [`show_buffer`](/en/py/stable/reference/libtmux-server-show_buffer/) (method): Show content of a paste buffer via ``$ tmux show-buffer``.
- [`delete_buffer`](/en/py/stable/reference/libtmux-server-delete_buffer/) (method): Delete a paste buffer via ``$ tmux delete-buffer``.
- [`run_shell`](/en/py/stable/reference/libtmux-server-run_shell/) (method): Execute a shell command via ``$ tmux run-shell``.
- [`has_session`](/en/py/stable/reference/libtmux-server-has_session/) (method): Return True if session exists.
- [`cmd`](/en/py/stable/reference/libtmux-server-cmd/) (method): Execute tmux command respective of socket name and file, return output.
- [`wait_for`](/en/py/stable/reference/libtmux-server-wait_for/) (method): Wait for, signal, or lock a channel via ``$ tmux wait-for``.
- [`load_buffer`](/en/py/stable/reference/libtmux-server-load_buffer/) (method): Load a file into a paste buffer via ``$ tmux load-buffer``.
- [`save_buffer`](/en/py/stable/reference/libtmux-server-save_buffer/) (method): Save a paste buffer to a file via ``$ tmux save-buffer``.
- [`bind_key`](/en/py/stable/reference/libtmux-server-bind_key/) (method): Bind a key to a command via ``$ tmux bind-key``.
- [`unbind_key`](/en/py/stable/reference/libtmux-server-unbind_key/) (method): Unbind a key via ``$ tmux unbind-key``.
- [`if_shell`](/en/py/stable/reference/libtmux-server-if_shell/) (method): Execute a tmux command conditionally via ``$ tmux if-shell``.
- [`show_prompt_history`](/en/py/stable/reference/libtmux-server-show_prompt_history/) (method): Show prompt history via ``$ tmux show-prompt-history``.
- [`clear_prompt_history`](/en/py/stable/reference/libtmux-server-clear_prompt_history/) (method): Clear prompt history via ``$ tmux clear-prompt-history``.
- [`lock_server`](/en/py/stable/reference/libtmux-server-lock_server/) (method): Lock the tmux server via ``$ tmux lock-server``.
- [`raise_if_dead`](/en/py/stable/reference/libtmux-server-raise_if_dead/) (method): Raise if server not connected.
- [`start_server`](/en/py/stable/reference/libtmux-server-start_server/) (method): Start the tmux server via ``$ tmux start-server``.
- [`show_messages`](/en/py/stable/reference/libtmux-server-show_messages/) (method): Show server message log via ``$ tmux show-messages``.
- [`command_prompt`](/en/py/stable/reference/libtmux-server-command_prompt/) (method): Open a command prompt via ``$ tmux command-prompt``.
- [`display_message`](/en/py/stable/reference/libtmux-server-display_message/) (method): Display message at server scope via ``$ tmux display-message``.
- [`detach_client`](/en/py/stable/reference/libtmux-server-detach_client/) (method): Detach a specific client via ``$ tmux detach-client``.
- [`kill_session`](/en/py/stable/reference/libtmux-server-kill_session/) (method): Kill tmux session.
- [`from_env`](/en/py/stable/reference/libtmux-server-from_env/) (method): Return the tmux server this process's pane is attached to.
- [`config_file`](/en/py/stable/reference/libtmux-server-config_file/) (attribute): Passthrough to ``[-f file]``
- [`socket_path`](/en/py/stable/reference/libtmux-server-socket_path/) (attribute): Passthrough to ``[-S socket-path]``
- [`attached_sessions`](/en/py/stable/reference/libtmux-server-attached_sessions/) (property): Return active :class:`Session` instances.
- [`confirm_before`](/en/py/stable/reference/libtmux-server-confirm_before/) (method): Run a command after confirmation via ``$ tmux confirm-before``.
- [`display_menu`](/en/py/stable/reference/libtmux-server-display_menu/) (method): Display a popup menu via ``$ tmux display-menu``.
- [`detach_all_clients`](/en/py/stable/reference/libtmux-server-detach_all_clients/) (method): Detach every client on this server via ``$ tmux detach-client -a``.
- [`lock_client`](/en/py/stable/reference/libtmux-server-lock_client/) (method): Lock a client via ``$ tmux lock-client``.
- [`suspend_client`](/en/py/stable/reference/libtmux-server-suspend_client/) (method): Suspend a client via ``$ tmux suspend-client``.
- [`refresh_client`](/en/py/stable/reference/libtmux-server-refresh_client/) (method): Refresh a client's display via ``$ tmux refresh-client``.
- [`switch_client`](/en/py/stable/reference/libtmux-server-switch_client/) (method): Switch tmux client.
- [`colors`](/en/py/stable/reference/libtmux-server-colors/) (attribute): ``256`` or ``88``
- [`socket_name`](/en/py/stable/reference/libtmux-server-socket_name/) (attribute): Passthrough to ``[-L socket-name]``
- [`server_access`](/en/py/stable/reference/libtmux-server-server_access/) (method): Manage server access control via ``$ tmux server-access``.

### Other members

- [`attach_session`](/en/py/stable/reference/libtmux-server-attach_session/) (method): Attach tmux session.
- [`child_id_attribute`](/en/py/stable/reference/libtmux-server-child_id_attribute/) (attribute): Unique child ID used by :class:`~libtmux.common.TmuxRelationalObject`
- [`default_hook_scope`](/en/py/stable/reference/libtmux-server-default_hook_scope/) (attribute): For hook management.
- [`default_option_scope`](/en/py/stable/reference/libtmux-server-default_option_scope/) (attribute): For option management.
- [`formatter_prefix`](/en/py/stable/reference/libtmux-server-formatter_prefix/) (attribute): Namespace used for :class:`~libtmux.common.TmuxMappingObject`
- [`tmux_bin`](/en/py/stable/reference/libtmux-server-tmux_bin/) (attribute): Custom path to tmux binary. Falls back to ``shutil.which("tmux")``.
- [`children`](/en/py/stable/reference/libtmux-server-children/) (property): Was used by TmuxRelationalObject (but that's longer used in this class).
- [`find_where`](/en/py/stable/reference/libtmux-server-find_where/) (method): Filter through sessions, return first :class:`Session`.
- [`get_by_id`](/en/py/stable/reference/libtmux-server-get_by_id/) (method): Return session by id. Deprecated in favor of :meth:`.sessions.get()`.
- [`kill_server`](/en/py/stable/reference/libtmux-server-kill_server/) (method): Kill tmux server.
- [`list_sessions`](/en/py/stable/reference/libtmux-server-list_sessions/) (method): Return list of :class:`Session` from the ``tmux(1)`` session.
- [`where`](/en/py/stable/reference/libtmux-server-where/) (method): Filter through sessions, return list of :class:`Session`.
- [`__enter__`](/en/py/stable/reference/libtmux-server-__enter__/) (method): Enter the context, returning self.
- [`__eq__`](/en/py/stable/reference/libtmux-server-__eq__/) (method): Equal operator for :class:`Server` object.
- [`__exit__`](/en/py/stable/reference/libtmux-server-__exit__/) (method): Exit the context, killing the server if it exists.
- [`__init__`](/en/py/stable/reference/libtmux-server-__init__/) (method)
- [`__repr__`](/en/py/stable/reference/libtmux-server-__repr__/) (method): Representation of :class:`Server` object.
- [`_list_panes`](/en/py/stable/reference/libtmux-server-_list_panes/) (method): Return list of panes in :py:obj:`dict` form.
- [`_list_sessions`](/en/py/stable/reference/libtmux-server-_list_sessions/) (method): Return list of session object dictionaries.
- [`_list_windows`](/en/py/stable/reference/libtmux-server-_list_windows/) (method): Return list of windows in :py:obj:`dict` form.
- [`_sessions`](/en/py/stable/reference/libtmux-server-_sessions/) (property): Property / alias to return :meth:`~._list_sessions`.
- [`_update_panes`](/en/py/stable/reference/libtmux-server-_update_panes/) (method): Update internal pane data and return ``self`` for chainability.
- [`_update_windows`](/en/py/stable/reference/libtmux-server-_update_windows/) (method): Update internal window data and return ``self`` for chainability.

## Inherited members

- [`show_options`](/en/py/stable/reference/libtmux-server-show_options/) (method), inherited from `libtmux.options.OptionsMixin`: Return all options for the target.
- [`show_hooks`](/en/py/stable/reference/libtmux-server-show_hooks/) (method), inherited from `libtmux.hooks.HooksMixin`: Return a dict of hooks for the target.
- [`show_environment`](/en/py/stable/reference/libtmux-server-show_environment/) (method), inherited from `libtmux.common.EnvironmentMixin`: Show environment ``$ tmux show-environment -t [session]``.
- [`set_option`](/en/py/stable/reference/libtmux-server-set_option/) (method), inherited from `libtmux.options.OptionsMixin`: Set option for tmux target.
- [`set_environment`](/en/py/stable/reference/libtmux-server-set_environment/) (method), inherited from `libtmux.common.EnvironmentMixin`: Set environment ``$ tmux set-environment <name> <value>``.
- [`unset_environment`](/en/py/stable/reference/libtmux-server-unset_environment/) (method), inherited from `libtmux.common.EnvironmentMixin`: Unset environment variable ``$ tmux set-environment -u <name>``.
- [`unset_option`](/en/py/stable/reference/libtmux-server-unset_option/) (method), inherited from `libtmux.options.OptionsMixin`: Unset option for tmux target.
- [`show_option`](/en/py/stable/reference/libtmux-server-show_option/) (method), inherited from `libtmux.options.OptionsMixin`: Return option value for the target.
- [`set_hook`](/en/py/stable/reference/libtmux-server-set_hook/) (method), inherited from `libtmux.hooks.HooksMixin`: Set hook for tmux target.
- [`unset_hook`](/en/py/stable/reference/libtmux-server-unset_hook/) (method), inherited from `libtmux.hooks.HooksMixin`: Unset hook for tmux target.
- [`remove_environment`](/en/py/stable/reference/libtmux-server-remove_environment/) (method), inherited from `libtmux.common.EnvironmentMixin`: Remove environment variable ``$ tmux set-environment -r <name>``.
- [`set_hooks`](/en/py/stable/reference/libtmux-server-set_hooks/) (method), inherited from `libtmux.hooks.HooksMixin`: Set multiple indexed hooks at once.
- [`show_hook`](/en/py/stable/reference/libtmux-server-show_hook/) (method), inherited from `libtmux.hooks.HooksMixin`: Return value for a hook.
- [`getenv`](/en/py/stable/reference/libtmux-server-getenv/) (method), inherited from `libtmux.common.EnvironmentMixin`: Show environment variable ``$ tmux show-environment -t [session] <name>``.
- [`hooks`](/en/py/stable/reference/libtmux-server-hooks/) (attribute), inherited from `libtmux.hooks.HooksMixin`
- [`run_hook`](/en/py/stable/reference/libtmux-server-run_hook/) (method), inherited from `libtmux.hooks.HooksMixin`: Run a hook immediately. Useful for testing.
- [`_add_option`](/en/py/stable/reference/libtmux-server-_add_option/) (attribute), inherited from `libtmux.common.EnvironmentMixin`
- [`_show_hook`](/en/py/stable/reference/libtmux-server-_show_hook/) (method), inherited from `libtmux.hooks.HooksMixin`: Return value for the hook.
- [`_show_option`](/en/py/stable/reference/libtmux-server-_show_option/) (method), inherited from `libtmux.options.OptionsMixin`: Return option value for the target.
- [`_show_option_raw`](/en/py/stable/reference/libtmux-server-_show_option_raw/) (method), inherited from `libtmux.options.OptionsMixin`: Return raw option output for target.
- [`_show_options`](/en/py/stable/reference/libtmux-server-_show_options/) (method), inherited from `libtmux.options.OptionsMixin`: Return a dict of options for the target.
- [`_show_options_dict`](/en/py/stable/reference/libtmux-server-_show_options_dict/) (method), inherited from `libtmux.options.OptionsMixin`: Return dict of options for the target.
- [`_show_options_raw`](/en/py/stable/reference/libtmux-server-_show_options_raw/) (method), inherited from `libtmux.options.OptionsMixin`: Return a dict of options for the target.
- [`_tmux_bin`](/en/py/stable/reference/libtmux-server-_tmux_bin/) (property), inherited from `libtmux.hooks.HooksMixin`: Resolve tmux_bin from self (Server) or self.server (Session/Window/Pane).

## In other ports

### A tmux server

- PowerShell: [`LibTmux\New-TmuxServer`](/en/powershell/latest/reference/libtmux-new-tmuxserver/) (cmdlet). This cmdlet constructs a shared .NET `LibTmux.Server` handle without contacting tmux.
- Julia: [`LibTmux.Server`](/en/julia/latest/reference/libtmux-server/) (struct). `Server` describes an endpoint without contacting tmux. Read its hierarchy with `snapshot`.
- Ruby: [`LibTmux::Server`](/en/ruby/latest/reference/libtmux-server/) (class)
- Lua: [`libtmux.Server`](/en/lua/latest/reference/libtmux-server/) (class)
- TypeScript: [`server.Server`](/en/ts/latest/reference/server-server/) (class)
- Rust: [`server.Server`](/en/rs/latest/reference/server-server/) (struct)
- Go: [`tmux.Server`](/en/go/latest/reference/tmux-server/) (struct)
- Java: [`io.github.libtmux.Server.Server`](/en/java/latest/reference/io-github-libtmux-server-server/) (class)
- C#: [`LibTmux.Server`](/en/csharp/latest/reference/libtmux-server/) (class)
- C++: [`libtmux::Server`](/en/cxx/latest/reference/libtmux-server/) (class)
- Swift: [`Server`](/en/swift/latest/reference/server/) (struct)
- Kotlin: [`io.github.libtmux.kotlin.Server`](/en/kotlin/latest/reference/io-github-libtmux-kotlin-server/) (class)
- Scala: [`io.github.libtmux.scaladsl.Server`](/en/scala/latest/reference/io-github-libtmux-scaladsl-server/) (typealias)
- F#: [`LibTmux.FSharp.Server`](/en/fsharp/latest/reference/libtmux-fsharp-server/) (module). This F# module provides functions over the shared .NET `LibTmux.Server` type.
