# libtmux.Server.search_sessions

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

```
libtmux.Server.search_sessions(
    self, filter: str | None = None, # noqa: A002
) -> QueryList[Session]
```

Sessions, optionally filtered by tmux before rows are returned.

Like :attr:`Server.sessions` but adds an optional ``filter`` kwarg
passed to [`$ tmux list-sessions -f <filter>`](/en/tmux/latest/manual/list-sessions/).

## Examples

```python
>>> server.new_session(session_name='gap7_alpha')
Session($... gap7_alpha)
>>> server.new_session(session_name='other_beta')
Session($... other_beta)
>>> matches = server.search_sessions(filter='#{m:gap7_*,#{session_name}}')
>>> [s.session_name for s in matches]
['gap7_alpha']
```

## Parameters

- `filter` (`str | None`): tmux format expression (``-f`` flag). tmux omits sessions whose
expanded expression is false before libtmux builds objects.
tmux silently expands a malformed filter (unclosed
``#{...}``, unknown format token) to empty, which the
filter treats as false — every row is suppressed and no
stderr is emitted. A bad filter is
indistinguishable from "filter matched nothing"; verify
filter syntax against the FORMATS section of ``tmux(1)``. Warning: (added 0.57)
- `# noqa: A002`

## Returns

:class:`~libtmux._internal.query_list.QueryList` of :class:`Session`

## In other ports

### Filter the sessions with a tmux expression

- Lua: [`libtmux.Server:query`](/en/lua/latest/reference/libtmux-server-query/) (method)
- Go: [`tmux.Server.SearchSessions`](/en/go/latest/reference/tmux-server-searchsessions/) (method)
- C#: [`LibTmux.Server.SearchSessionsAsync`](/en/csharp/latest/reference/libtmux-server-searchsessionsasync/) (method)
