# libtmux.Session.search_windows

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

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

Windows in this session, optionally filtered by tmux.

Like :attr:`Session.windows` but with a ``filter`` kwarg passed to
[`$ tmux list-windows -t <session> -f <filter>`](/en/tmux/latest/manual/list-windows/).

## Examples

```python
>>> _ = session.new_window(window_name='gap7s_target')
>>> _ = session.new_window(window_name='other_window')
>>> matches = session.search_windows(filter='#{m:gap7s_*,#{window_name}}')
>>> [w.window_name for w in matches]
['gap7s_target']
```

## Parameters

- `filter` (`str | None`): tmux format expression (``-f`` flag).
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`

## In other ports

### Filter a session's windows with a tmux expression

- Rust: [`session.Session.search_windows`](/en/rs/latest/reference/session-session-search_windows/) (method)
- Go: [`tmux.Session.SearchWindows`](/en/go/latest/reference/tmux-session-searchwindows/) (method)
- C#: [`LibTmux.Session.SearchWindowsAsync`](/en/csharp/latest/reference/libtmux-session-searchwindowsasync/) (method)
