libtmux

0.55.0 · active · verified Thu Apr 09

libtmux is a typed Python library providing an ORM (Object-Relational Mapper) wrapper for tmux, the terminal multiplexer. It allows programmatic control over tmux servers, sessions, windows, and panes. The current version is 0.55.0, and it maintains an active release cadence with frequent updates and bug fixes.

Warnings

Install

Imports

Quickstart

Demonstrates connecting to the tmux server, finding or creating a session, accessing its attached window and pane, and sending commands to the pane. The example includes optional session cleanup.

from libtmux import Server

# Connect to the tmux server
server = Server()

# Find or create a session named 'my_session'
session = server.find_where({"session_name": "my_session"})
if session is None:
    session = server.new_session(session_name="my_session")

# Get the attached window and pane
window = session.attached_window
pane = window.attached_pane

# Send keys to the pane
pane.send_keys("echo Hello, libtmux!", enter=True)

# Print current session name
print(f"Active session: {session.name}")

# Kill the session (optional, for cleanup)
# session.kill_session()

view raw JSON →