Debian Codegraph @

MIGRATION

raw
1 # Migration notes
2
3 Migration and deprecation notes for libtmux are here, see {ref}`changelog` as
4 well.
5
6 ```{admonition} Welcome on board! 👋
7 1. 📌 For safety, **always** pin the package
8 2. 📖 Check the migration notes _(You are here)_
9 3. 📣 If you feel something got deprecated and it interrupted you - past, present, or future - voice your opinion on the [tracker].
10
11 We want to make libtmux fun, reliable, and useful for users.
12
13 API changes can be painful.
14
15 If we can do something to draw the sting, we'll do it. We're taking a balanced approach. That's why these notes are here!
16
17 (Please pin the package. 🙏)
18
19 [tracker]: https://github.com/tmux-python/libtmux/discussions
20 ```
21
22 ## Complete Deprecation Reference
23
24 This table provides a quick reference for all deprecated APIs. See version-specific
25 sections below for detailed migration examples and code samples.
26
27 ### Method Renamings
28
29 | Class | Deprecated | Replacement | Since | Raises |
30 |-------|------------|-------------|-------|--------|
31 | Server | `kill_server()` | `kill()` | 0.30.0 (2024-02-16) | 0.51.0 |
32 | Session | `attach_session()` | `attach()` | 0.30.0 (2024-02-16) | 0.51.0 |
33 | Session | `kill_session()` | `kill()` | 0.30.0 (2024-02-16) | 0.51.0 |
34 | Window | `select_window()` | `select()` | 0.30.0 (2024-02-16) | 0.51.0 |
35 | Window | `kill_window()` | `kill()` | 0.30.0 (2024-02-16) | 0.51.0 |
36 | Window | `split_window()` | `split()` | 0.33.0 (2024-03-17) | 0.51.0 |
37 | Window | `set_window_option()` | `set_option()` | 0.50.0 (2025-11-30) | _(warning)_ |
38 | Window | `show_window_option()` | `show_option()` | 0.50.0 (2025-11-30) | _(warning)_ |
39 | Window | `show_window_options()` | `show_options()` | 0.50.0 (2025-11-30) | _(warning)_ |
40 | Pane | `select_pane()` | `select()` | 0.30.0 (2024-02-16) | 0.51.0 |
41 | Pane | `resize_pane()` | `resize()` | 0.28.0 (2024-02-14) | 0.51.0 |
42 | Pane | `split_window()` | `split()` | 0.33.0 (2024-03-17) | 0.51.0 |
43
44 ### Property Renamings
45
46 | Class | Deprecated | Replacement | Since | Raises |
47 |-------|------------|-------------|-------|--------|
48 | Session | `attached_window` | `active_window` | 0.31.0 (2024-02-17) | 0.51.0 |
49 | Session | `attached_pane` | `active_pane` | 0.31.0 (2024-02-17) | 0.51.0 |
50 | Window | `attached_pane` | `active_pane` | 0.31.0 (2024-02-17) | 0.51.0 |
51
52 ### Parameter Changes
53
54 | Method(s) | Deprecated | Replacement | Since | Raises |
55 |-----------|------------|-------------|-------|--------|
56 | Options/hooks methods | `g` | `global_` | 0.50.0 (2025-11-30) | _(warning)_ |
57 | `split_window()` / `split()` | `percent` | `size` | 0.28.0 (2024-02-14) | 0.51.0 |
58 | `split_window()` / `split()` | `vertical`/`horizontal` | `direction` (PaneDirection) | 0.33.0 (2024-03-17) | 0.51.0 |
59 | `resize_pane()` | `-U`, `-D`, `-L`, `-R` | `adjustment_direction` | 0.28.0 (2024-02-14) | 0.51.0 |
60 | `Server.get_by_id()` | `id` | `session_id` | 0.16.0 (2022-12-10) | 0.51.0 |
61 | `Session.get_by_id()` | `id` | `window_id` | 0.16.0 (2022-12-10) | 0.51.0 |
62 | `Window.get_by_id()` | `id` | `pane_id` | 0.16.0 (2022-12-10) | 0.51.0 |
63
64 ### Query/Filter API Changes
65
66 | Class | Deprecated | Replacement | Since | Raises |
67 |-------|------------|-------------|-------|--------|
68 | Server | `list_sessions()` / `_list_sessions()` | `sessions` property | 0.17.0 (2022-12-26) | 0.51.0 |
69 | Server | `where({...})` | `sessions.filter(**kwargs)` | 0.17.0 (2022-12-26) | 0.51.0 |
70 | Server | `find_where({...})` | `sessions.get(default=None, **kwargs)` | 0.17.0 (2022-12-26) | 0.51.0 |
71 | Server | `_list_panes()` / `_update_panes()` | `panes` property | 0.17.0 (2022-12-26) | 0.51.0 |
72 | Server | `_list_windows()` / `_update_windows()` | `windows` property | 0.17.0 (2022-12-26) | 0.51.0 |
73 | Server | `get_by_id(id)` | `sessions.get(session_id=..., default=None)` | 0.16.0 (2022-12-10) | 0.51.0 |
74 | Session | `list_windows()` / `_list_windows()` | `windows` property | 0.17.0 (2022-12-26) | 0.51.0 |
75 | Session | `where({...})` | `windows.filter(**kwargs)` | 0.17.0 (2022-12-26) | 0.51.0 |
76 | Session | `find_where({...})` | `windows.get(default=None, **kwargs)` | 0.17.0 (2022-12-26) | 0.51.0 |
77 | Session | `get_by_id(id)` | `windows.get(window_id=..., default=None)` | 0.16.0 (2022-12-10) | 0.51.0 |
78 | Window | `list_panes()` / `_list_panes()` | `panes` property | 0.17.0 (2022-12-26) | 0.51.0 |
79 | Window | `where({...})` | `panes.filter(**kwargs)` | 0.17.0 (2022-12-26) | 0.51.0 |
80 | Window | `find_where({...})` | `panes.get(default=None, **kwargs)` | 0.17.0 (2022-12-26) | 0.51.0 |
81 | Window | `get_by_id(id)` | `panes.get(pane_id=..., default=None)` | 0.16.0 (2022-12-10) | 0.51.0 |
82 | All | `children` property | `sessions`/`windows`/`panes` | 0.17.0 (2022-12-26) | 0.51.0 |
83
84 ### Attribute Access Changes
85
86 | Pattern | Deprecated | Replacement | Since | Raises |
87 |---------|------------|-------------|-------|--------|
88 | Dict key access | `obj['key']` | `obj.key` | 0.17.0 (2022-12-26) | 0.51.0 |
89 | Dict get | `obj.get('key')` | `obj.key` | 0.17.0 (2022-12-26) | 0.51.0 |
90 | Dict get w/ default | `obj.get('key', None)` | `getattr(obj, 'key', None)` | 0.17.0 (2022-12-26) | 0.51.0 |
91
92 ### Removed Items
93
94 | Item | Removed In | Migration |
95 |------|------------|-----------|
96 | tmux < 3.2a support | 0.49.0 (2025-11-29) | Upgrade tmux or use libtmux 0.48.x |
97 | `console_to_str()` | 0.42.0 (2025-02-02) | Use `text=True` in subprocess |
98 | `str_from_console()` | 0.42.0 (2025-02-02) | Use `text=True` in subprocess |
99 | `common.which()` | 0.12.0 (2022-07-13) | Use `shutil.which()` |
100
101 ### Default Behavior Changes
102
103 | Method | Old Default | New Default | Since |
104 |--------|-------------|-------------|-------|
105 | `Session.new_window()` | `attach=True` | `attach=False` | 0.28.0 (2024-02-14) |
106 | `Window.split_window()` | `attach=True` | `attach=False` | 0.28.0 (2024-02-14) |
107
108 ---
109
110 ## Upcoming Release
111
112 <!-- KEEP THIS PLACEHOLDER - DO NOT REMOVE OR MODIFY THIS LINE -->
113 _Detailed migration steps for the next version will be posted here._
114 <!-- END PLACEHOLDER - ADD NEW MIGRATION ENTRIES BELOW THIS LINE -->
115
116 ## libtmux 0.57.0: Subcommand-tagged exceptions (#672)
117
118 ### `LibTmuxException` `str()` gains a subcommand prefix
119
120 When {exc}`~libtmux.exc.LibTmuxException` is raised from a libtmux method,
121 ``str(exc)`` now starts with the originating tmux subcommand name followed
122 by ``": "``. ``exc.args[0]`` still
123 carries the original tmux error text, and the new
124 {attr}`~libtmux.exc.LibTmuxException.subcommand` attribute exposes
125 the tmux subcommand name on its own.
126
127 The error-payload *type* changed: ``exc.args[0]`` is now ``str``,
128 joined with ``"\n"`` when tmux emitted multiple stderr lines.
129 Previously it was ``list[str]``.
130
131 **Who is affected:** code that pattern-matches `str(exc)` exactly,
132 anchors a regex with `^` against the previous shape, or indexes
133 `exc.args[0]` element-by-element expecting a list. Substring
134 containment (`"can't find" in str(exc)`) and unanchored
135 `re.search` patterns continue to match unchanged.
136
137 **Before:**
138
139 ```python
140 try:
141 session.last_window()
142 except LibTmuxException as exc:
143 if str(exc) == "can't find window":
144 handle_missing_last_window()
145 ```
146
147 **After (0.57.0+) — dispatch on the typed attribute:**
148
149 ```python
150 try:
151 session.last_window()
152 except LibTmuxException as exc:
153 if exc.subcommand == "last-window":
154 handle_missing_last_window()
155 ```
156
157 **Or — match against the original tmux error text in `exc.args[0]`:**
158
159 ```python
160 try:
161 session.last_window()
162 except LibTmuxException as exc:
163 if exc.args and exc.args[0] == "can't find window":
164 handle_missing_last_window()
165 ```
166
167 ### `Client.session_id` / `window_id` / `pane_id` are snapshots, not identity
168
169 {class}`~libtmux.Client` is new in 0.57.0, so this isn't a behavior
170 change — but new users of {attr}`~libtmux.Server.clients` should know
171 that ``client.session_id``, ``client.window_id``, and
172 ``client.pane_id`` reflect the client's attached view at the moment the
173 {class}`~libtmux.Client` was read. They go stale as soon as the client
174 switches sessions, changes window, or detaches.
175
176 For typed access that reflects the client's *live* attachment, use
177 {attr}`~libtmux.Client.attached_session`,
178 {attr}`~libtmux.Client.attached_window`, and
179 {attr}`~libtmux.Client.attached_pane`:
180
181 ```python
182 # Snapshot (may be stale)
183 client = server.clients.get(client_name=ctl.client_name)
184 session_id = client.session_id # str captured when the object was read
185
186 # Live (re-reads list-clients; returns None if tmux no longer reports the client)
187 attached = client.attached_session # libtmux.Session | None
188 window = client.attached_window # libtmux.Window | None
189 pane = client.attached_pane # libtmux.Pane | None
190 ```
191
192 The ``client.client_name`` field (typically the tty path on Unix) is
193 the client's *stable* identifier and does not have this caveat. The
194 ``attached_*`` properties translate a missing ``list-clients`` row into
195 ``None`` for convenience; direct {meth}`~libtmux.Client.refresh` and
196 {meth}`~libtmux.Client.from_client_name` calls still raise when that
197 client row is gone.
198
199 {attr}`~libtmux.Client.attached_pane` follows the attached session's current
200 window. That can differ from the per-client active pane set by
201 ``select-pane -P``.
202
203 ### `Pane.reset` now uses one tmux command sequence
204
205 {meth}`~libtmux.Pane.reset` now bundles ``send-keys -R`` and
206 ``clear-history`` into one tmux command sequence targeted at the pane.
207 This closes a race where output written between separate commands could
208 land in the scrollback that the second command then cleared.
209
210 **Who is affected:** test fixtures and downstream code that intercepts
211 ``Pane.cmd`` (for example with ``unittest.mock.patch.object(pane,
212 "cmd")``) will no longer observe ``reset()``'s tmux invocation. Patch
213 ``Server.cmd`` instead, or assert on the resulting pane state directly.
214
215 ### `Server.display_message` / `Window.display_message` / `Pane.display_message` warn instead of raise
216
217 The three ``display_message`` wrappers now report tmux stderr via
218 :func:`warnings.warn` rather than raising
219 {exc}`~libtmux.exc.LibTmuxException`. tmux uses stderr for both genuine
220 errors and informational messages, and the right escalation depends on
221 tmux version and requested format; the wrappers default to warning so callers
222 can decide. To escalate to an exception, wrap the call in
223 :func:`warnings.catch_warnings` with ``filterwarnings("error")``:
224
225 ```python
226 import warnings
227
228 with warnings.catch_warnings():
229 warnings.filterwarnings("error", category=UserWarning)
230 result = pane.display_message("#{pane_id}", get_text=True)
231 ```
232
233 ## libtmux 0.50.0: Unified Options and Hooks API (#516)
234
235 ### New unified options API
236
237 All tmux objects (Server, Session, Window, Pane) now share a consistent options
238 interface through {class}`~libtmux.options.OptionsMixin`:
239
240 ```python
241 # Get all options
242 session.show_options()
243
244 # Get a single option
245 session.show_option('base-index')
246
247 # Set an option
248 window.set_option('automatic-rename', True)
249
250 # Unset an option
251 window.unset_option('automatic-rename')
252 ```
253
254 ### New hooks API
255
256 All tmux objects now support hook management through
257 {class}`~libtmux.hooks.HooksMixin`:
258
259 ```python
260 # Set a hook
261 session.set_hook('session-renamed', 'display-message "Renamed!"')
262
263 # Get hook value
264 session.show_hook('session-renamed')
265
266 # Get all hooks
267 session.show_hooks()
268
269 # Remove a hook
270 session.unset_hook('session-renamed')
271 ```
272
273 ### Deprecated Window methods
274
275 The following `Window` methods are deprecated and will be removed in a future
276 release:
277
278 | Deprecated | Replacement |
279 |------------|-------------|
280 | `Window.set_window_option()` | {meth}`Window.set_option() <libtmux.Window.set_option>` |
281 | `Window.show_window_option()` | {meth}`Window.show_option() <libtmux.Window.show_option>` |
282 | `Window.show_window_options()` | {meth}`Window.show_options() <libtmux.Window.show_options>` |
283
284 **Before (deprecated):**
285
286 ```python
287 window.set_window_option('automatic-rename', 'on')
288 window.show_window_option('automatic-rename')
289 window.show_window_options()
290 ```
291
292 **After (0.50.0+):**
293
294 ```python
295 window.set_option('automatic-rename', True)
296 window.show_option('automatic-rename')
297 window.show_options()
298 ```
299
300 ### Deprecated `g` parameter
301
302 The `g` parameter for global options is deprecated in favor of `global_`:
303
304 **Before (deprecated):**
305
306 ```python
307 session.show_option('status', g=True)
308 session.set_option('status', 'off', g=True)
309 ```
310
311 **After (0.50.0+):**
312
313 ```python
314 session.show_option('status', global_=True)
315 session.set_option('status', 'off', global_=True)
316 ```
317
318 Using the old `g` parameter will emit a {class}`DeprecationWarning`.
319
320 ## libtmux 0.46.0 (2025-02-25)
321
322 ### Imports removed from libtmux.test (#580)
323
324 Root-level of imports from `libtmux.test` are no longer possible.
325
326 ```python
327 # Before 0.46.0
328 from libtmux.test import namer
329 ```
330
331 ```python
332 # From 0.46.0 onward
333 from libtmux.test.named import namer
334 ```
335
336 Same thing with constants:
337
338 ```python
339 # Before 0.46.0
340 from libtmux.test import (
341 RETRY_INTERVAL_SECONDS,
342 RETRY_TIMEOUT_SECONDS,
343 TEST_SESSION_PREFIX
344 )
345 ```
346
347 ```python
348 # From 0.46.0 onward
349 from libtmux.test.constants import (
350 RETRY_INTERVAL_SECONDS,
351 RETRY_TIMEOUT_SECONDS,
352 TEST_SESSION_PREFIX
353 )
354 ```
355
356 ## libtmux 0.45.0 (2025-02-23)
357
358 ### Test helpers: Module moves
359
360 Test helper functionality has been split into focused modules (#578):
361
362 - `libtmux.test` module split into:
363 - `libtmux.test.constants`: Test-related constants (`TEST_SESSION_PREFIX`, etc.)
364 - `libtmux.test.environment`: Environment variable mocking
365 - `libtmux.test.random`: Random string generation utilities
366 - `libtmux.test.temporary`: Temporary session/window management
367
368 **Breaking**: Import paths have changed. Update imports:
369
370 ```python
371 # Old (0.44.x and earlier)
372 from libtmux.test import (
373 TEST_SESSION_PREFIX,
374 get_test_session_name,
375 get_test_window_name,
376 namer,
377 temp_session,
378 temp_window,
379 EnvironmentVarGuard,
380 )
381 ```
382
383 ```python
384 # New (0.45.0+)
385 from libtmux.test.constants import TEST_SESSION_PREFIX
386 from libtmux.test.environment import EnvironmentVarGuard
387 from libtmux.test.random import get_test_session_name, get_test_window_name, namer
388 from libtmux.test.temporary import temp_session, temp_window
389 ```
390
391 ## 0.35.0: Commands require explicit targets (2024-03-17)
392
393 ### Commands require explicit targets (#535)
394
395 - {meth}`Server.cmd()`, {meth}`Session.cmd()`, {meth}`Window.cmd()`, {meth}`Pane.cmd()` require passing `target` instead of `['-t', target]`, `['-tTargetName']`, etc. This change is to avoid issues mistakenly interpreting `-t` in other shell values as targets.
396
397 Before:
398
399 ```python
400 session.cmd('send-keys', 'echo hello', '-t', '0')
401 ```
402
403 With 0.35.0 and after:
404
405 ```python
406 session.cmd('send-keys', 'echo hello', target='0')
407 ```
408
409 ## 0.33.0: Deprecations for splitting (2024-03-03)
410
411 ### Deprecations (#532)
412
413 - `Window.split_window()` to {meth}`Window.split()`
414 - `Pane.split_window()` to {meth}`Pane.split()`
415
416 ## 0.31.0: Renaming and command cleanup (2024-02-17)
417
418 ### Cleanups (#527)
419
420 - Commands: Param change
421
422 {meth}`Server.cmd()`, {meth}`Session.cmd()`, {meth}`Window.cmd()`, {meth}`Pane.cmd()`
423
424 - Use `cmd: str` as first positional
425 - Removed unused keyword arguments `**kwargs`
426
427 ### Renamings (#527)
428
429 - `Session.attached_window` renamed to {meth}`Session.active_window`
430 - `Session.attached_window` deprecated
431 - `Session.attached_pane` renamed to {meth}`Session.active_pane`
432 - `Session.attached_pane` deprecated
433 - `Window.attached_pane` renamed to {meth}`Window.active_pane`
434 - `Window.attached_pane` deprecated
435
436 ## 0.28.0: Resizing and detached by default (2024-02-15)
437
438 ### Detach by default
439
440 - {meth}`Session.new_window()` + {meth}`Window.split_window()` no longer attaches by default (#523)
441
442 - 0.28.0 and greater: Defaults to `attach=False`.
443 - 0.27.1 and below: Defaults to `attach=True`.
444
445 For the old behavior in 0.28.0 and beyond, pass `attach=True` explicitly.
446
447 ### Resizing panes
448
449 - `Pane.resize_pane()` renamed to {meth}`Pane.resize()` (via #523)
450
451 This convention will be more consistent with {meth}`Window.resize()`.
452
453 - {meth}`Pane.resize_pane()`'s params changed (#523)
454
455 - No longer accepts `-U`, `-D`, `-L`, `-R` directly, instead accepts
456 {class}`~libtmux.constants.ResizeAdjustmentDirection` (see below).
457
458 - 0.27.1 and below: `pane.resize_pane("-D", 20)`, `pane.resize_pane("-R", 20)`
459
460 - 0.28.0 and beyond:
461
462 ```python
463 from libtmux.constants import ResizeAdjustmentDirection
464 pane.resize_pane(adjustment_direction=ResizeAdjustmentDirection.Down, adjustment=25)
465 pane.resize_pane(
466 adjustment_direction=ResizeAdjustmentDirection.Right, adjustment=25
467 )
468 ```
469
470 ## 0.17.0: Simplified attributes (2022-12-26)
471
472 ### Finding objects / relations
473
474 - 0.16 and below: `session._windows()`, `session.list_windows()`, etc.
475
476 0.17 and after: {attr}`session.windows <libtmux.Session.windows>`
477
478 - 0.16 and below: `session.find_where({'window_name': my_window})`
479
480 0.17 and after: {meth}`session.windows.get(window_name=my_window, default=None) <libtmux.Session.windows>`
481
482 - If not found and not `default`, raises {exc}`~libtmux._internal.query_list.ObjectDoesNotExist`
483 - If multiple objects found, raises {exc}`~libtmux._internal.query_list.MultipleObjectsReturned`
484
485 - 0.16 and below: `session.where({'window_name': my_window})`
486
487 0.17 and after: {meth}`session.windows.filter(window_name=my_window) <libtmux.Session.windows>`
488
489 ### Accessing attributes
490
491 - 0.16 and below: `window['id']`
492
493 0.17 and after: `window.id`
494
495 - 0.16 and below: `window.get('id')`
496
497 0.17 and after: `window.id`
498
499 - 0.16 and below: `window.get('id', None)`
500
501 0.17 and after: `getattr(window, 'id', None)`
502
503 <!---
504 # vim: set filetype=markdown:
505 -->