Drive tmux from Python: typed, object-oriented control over servers, sessions, windows, and panes.
🐍 What is libtmux?
libtmux is a typed Python API over tmux, the terminal multiplexer. Stop shelling out and parsing tmux ls. Instead, interact with real Python objects: Server, Session, Window, and Pane. The same API powers tmuxp, so it stays battle-tested in real-world workflows.
✨ Features
Typed, object-oriented control of tmux state
Query and traverse live sessions, windows, and panes
Code running inside a pane — a script in a split, a tmux hook, an agent — can ask where it is. tmux writes TMUX and TMUX_PANE into every pane it spawns, and Server, Session, Window, and Pane each read them back:
In a real pane tmux has already set those two variables, so from_env() takes no arguments and there is nothing to arrange — this README is not running in a pane, so the example sets them first. Outside tmux there is no pane to return, and from_env() raises NotInsideTmux.
Writing a tool that interacts with tmux? Use our fixtures to keep your tests clean and isolated.
def test_my_tmux_tool(session):
# session is a real tmux session in an isolated server
window = session.new_window(window_name="test")
pane = window.active_pane
pane.send_keys("echo 'hello from test'", enter=True)
assert window.window_name == "test"
# Fixtures handle cleanup automatically
Fresh server and session fixtures per test, each on an isolated
tmux socket; derive windows and panes from session
Temporary HOME and tmux config fixtures keep indices stable
TestServer helper spins up multiple isolated tmux servers
When you might not need libtmux
Layouts are static and live entirely in tmux config files
You do not need to introspect or control running tmux from other tools
Please use the following BibTeX template to cite libtmux in scientific discourse:
@misc{libtmux,
author = {Tony Narlock},
year = {2016},
note = {https://libtmux.git-pull.com},
title = {libtmux: python wrapper for tmux}
}
Contributing & support
Contributions are welcome. Please open an issue or PR if you find a bug or want to improve the API or docs. If libtmux helps you ship, consider sponsoring development via support.
Works well with
Use together with libtmux: extensions, drivers, servers and companion tools.
tmuxpPythie’s Index: 79Session manager for tmux, which allows users to save and load tmux sessions through simple configuration files.111.5K downloads/mo