Repository navigation
libtmux 0.70.0 moves static type checking from mypy to Astral's ty (all = "error") paired with Ruff ANN annotations and @overload return types on show_option() and QueryList. It also adds opt-in command, channel, and listing timeouts raising TmuxCommandTimeout, defines single-owner failure routing and structured logging with symmetric environment masking, and adds Client.request_clipboard() on tmux 3.6a+.
Highlights
- Strict
tytype checking, RuffANN, and@overloadoption and query types. Static type checking acrosssrc/,tests/,docs/, and CI now runs onty(ty>=0.0.112,all = "error") and Ruff'sANNrules with zero inline# type: ignoresuppressions.OptionsMixin.show_option()adds@overloadsignatures for known built-in option keys so scalar, indexed-array, and mapping return types narrow without casts (while dynamic and@user option names keep the general option union),QueryList.get()andQueryList.filter()preserve element anddefaulttypes across lookup operators,.cmd()narrows positional arguments toStrPath | int, andTestServer,temp_session(), andtemp_window()carry explicit parameter types (withtemp_window()dropping its unused*argsparameter to matchSession.new_window(); #682, #619). - Command, channel, and listing timeouts.
Serveraccepts a keyword-onlytimeout(exposed atServer.timeout), andServer.cmd(),Session.cmd(),Window.cmd(),Pane.cmd(),tmux_cmd,fetch_objs(),fetch_obj(), and ordinaryServer.wait_for()signal waits accept a per-calltimeout(defaultNone). Expiry kills and reaps the spawned tmux client without draining inherited pipes and raisesTmuxCommandTimeout(both aLibTmuxExceptionviaTmuxTransportErrorand Python'sTimeoutError). Lenient listing accessors andServer.raise_if_dead()propagateTmuxCommandTimeoutwhileServer.is_alive()returnsFalse, and interactive terminal and unbounded channel or lock waits stay exempt (#807; see Pane interaction). - Single-owner failure routing, structured logging, and environment masking. Raised or translated failures stay in the exception channel without emitting a duplicate
ERRORrecord, whereasServer.sessions,Server.attached_sessions, andServer.clientsemit oneERRORrecord when converting a tmux failure to an empty result. CommandDEBUGrecords come fromlibtmux.common(replacinglibtmux.neo's separate query records), escape control characters onto one line, and mask environment values to***across-e,set-environment,show-environmenttmux_stdout, clustered flags, aliases, and;/{ ... }chains. Missing, non-executable, and malformed tmux binaries raiseTmuxCommandNotFound, andServer.raise_if_dead()redirectsstdoutandstderrtoDEVNULL(#748, #641; see Logging). - Client clipboard requests on tmux 3.6a+.
Client.request_clipboard()asks a selected terminal for its OSC 52 clipboard (refresh-client -l) after checking the connected server's version (#889; see Clients).
Upgrading
Read typed options and query collections without casts under ty or mypy:
from libtmux import Server, Window
with Server(socket_name="ci-types", kill_on_exit=True) as server:
session = server.new_session(session_name="build")
base_index: int | None = session.show_option("base-index", global_=True)
mouse: bool | None = session.show_option("mouse", global_=True)
session.new_window(window_name="compile", attach=False)
compile_window: Window | None = session.windows.get(
window_name="compile",
default=None,
)
assert isinstance(base_index, int)
assert isinstance(mouse, bool)
assert compile_window is not None and compile_window.window_name == "compile"Bound commands, listings, and channel waits explicitly when a server or producer may stall:
import logging
from libtmux import Server, exc
logger = logging.getLogger(__name__)
with Server(socket_name="ci-timeout", kill_on_exit=True, timeout=2.0) as server:
server.new_session(session_name="build")
try:
server.wait_for("build-ready", timeout=0.1)
except exc.TmuxCommandTimeout as error:
logger.warning(
"channel %s timed out after %.1fs",
error.argv[-1],
error.timeout,
)Log raised failures at your own exception boundary, catch TmuxCommandNotFound for unusable tmux binaries, and configure command DEBUG filters on libtmux.common:
import logging
from libtmux import Server, exc
command_logger = logging.getLogger("libtmux.common")
previous_level = command_logger.level
command_logger.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)
try:
with Server(socket_name="ci-logging", kill_on_exit=True) as server:
session = server.new_session(session_name="build")
try:
session.kill_window("missing-window")
except exc.TmuxCommandNotFound:
logger.error("tmux executable is missing or not runnable")
except exc.LibTmuxException:
logger.exception("tmux command failed")
finally:
command_logger.setLevel(previous_level)Pass options after window_name by keyword in temp_window():
from libtmux import Server
from libtmux.test.temporary import temp_window
with Server(socket_name="ci-temp", kill_on_exit=True) as server:
session = server.new_session(session_name="build")
with temp_window(session, "work", attach=False) as window:
assert window.window_name == "work"See the migration notes and the changelog for the full list.
What's Changed
- ci(tests): Exercise tmux 3.7c in place of 3.7b by @tony in #746
- Just(chore): Clean ignored build output by @tony in #783
- dev(chore): Remove unused Node version pin by @tony in #834
- Server(fix[raise_if_dead]): Suppress check_call output by @tony in #641
- Temporary(fix[temp_window]): Remove unused *args by @tony in #619
- README(docs): Link the AI policy by @tony in #793
- README(docs): Pin a minor series without naming one by @tony in #824
- docs(feat[brand]): Add Python logo and brand kit by @tony in #760
- docs(feat[brand]): Show a query on the sharing card by @tony in #816
- Docs(fix[api]): Refresh native tmux API citations by @tony in #774
- Server(docs[overview]): Group members by purpose by @tony in #785
- Server(docs): Complete the capability directory by @tony in #813
- docs(fix): Correct library setup and terminal examples by @tony in #797
- Client(feat): Request a terminal clipboard by @tony in #889
- logging(feat): Document logging and define failure ownership by @tony in #748
- Command(feat[timeout]): Bound commands, waits, and listings by @tony in #807
- dev(ty): Replace
mypywith stricttyand RuffANNby @tony in #682
Full Changelog: v0.69.0...v0.70.0