Lightweight tmux automation wrapper and renderer.
Project description
tmux-wrapper
tmux-wrapper is a small Python module and CLI for driving a tmux session like
a human: type text, press key chords, inspect what changed, and scroll through
history.
It is designed for agent workflows, test automation, and other cases where you want a simple tmux control surface instead of shelling out to a large stack of custom tmux commands.
Features
type(text)sends literal text to the active pane.press(chords)sends key chords such asEnter,Ctrl+C, orCtrl+B Z.snapshot()captures the full current screen and resets the diff baseline.view()is the recommended inspection API. It returns a contextual, line-oriented delta against the previous capture.glance()returns incremental additions plus collapsed...[N unchanged lines]markers for unchanged regions.scroll_up(lines=3)andscroll_down(lines=3)emulate mouse-wheel style scrolling via tmux copy mode.tmux-cprovides the same workflow from the command line.
Requirements
- Python 3.9+
tmuxinstalled and available onPATH
Installation
Install from PyPI:
pip install tmux-wrapper
After installation, the CLI command tmux-c is available:
tmux-c 1 glance
Quick Start
Python API
from tmux_wrapper import Keys, TMUXWrapper
tmux = TMUXWrapper(session="demo")
# Establish a baseline for future view()/glance() calls.
tmux.snapshot()
tmux.type("echo hello")
tmux.press([(Keys.Enter,)])
print(tmux.view())
# For a compact "only what was newly added" report:
print(tmux.glance())
tmux.scroll_up(5)
print(tmux.view())
tmux.scroll_down(999)
tmux.delete()
CLI
tmux-c demo snapshot
tmux-c demo type "ls /data"
tmux-c demo press Enter
tmux-c demo view
tmux-c demo glance
tmux-c demo scroll_up 5
tmux-c demo view
tmux-c demo scroll_down 999
How Inspection Works
view() is the default inspection method.
snapshot()captures the full screen and stores it as the new baseline.view()compares the current screen against the previous capture.glance()uses the same diff basis, but returns only added lines plus...[N unchanged lines]markers for unchanged regions.- Added lines are marked with
!!. - Removed lines are hidden.
?helper lines fromdifflib.ndiffare also hidden.- If there are no new additions,
glance()returns[Nothing Changed].
Example:
!!new output line
existing prompt context
For compact incremental output, glance() returns abbreviated output such as:
...[12 unchanged lines]
!!new output line
...[3 unchanged lines]
Press Syntax
In Python, press() accepts a list of chords:
tmux.press([(Keys.Enter,)])
tmux.press([(Keys.Ctrl, Keys.C)])
tmux.press([(Keys.Ctrl, Keys.B), (Keys.Z,)])
tmux.press([(Keys.Ctrl, Keys.B), (Keys.Left,)])
In the CLI, each chord is passed as an argument:
tmux-c demo press Enter
tmux-c demo press Ctrl+C
tmux-c demo press Ctrl+B Z
tmux-c demo press Ctrl+B Left
Scrolling
scroll_up() and scroll_down() are line-based helpers built on tmux copy
mode.
scroll_up(lines)enters copy mode and scrolls up bylines.scroll_down(lines)scrolls down bylines.- When
scroll_down()reaches the bottom, it exits copy mode automatically.
This matches the intended "mouse wheel with set -g mouse on" feel more closely
than page-based movement.
Session Behavior
TMUXWrapper(session="name")creates the session if it does not already exist.- If the wrapper created the session, object cleanup will delete it by default.
- Calling
delete()always deletes the session immediately. - CLI snapshot/view/glance state is persisted per session so repeated
tmux-c ...calls can diff across separate invocations.
Development
Install development dependencies with uv:
uv sync --dev
Run tests:
env -u VIRTUAL_ENV uv run pytest -q
Notes
- The package focuses on a practical tmux-driving workflow, not a full tmux abstraction layer.
- The renderer captures the full tmux window, not just a single pane.
- The cursor is rendered visibly in full-screen snapshots.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tmux_wrapper-0.1.0.tar.gz.
File metadata
- Download URL: tmux_wrapper-0.1.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df1ce0d946df31c0adbf97ece89aea71b1051caf0302b58ed8c472706c081080
|
|
| MD5 |
68da629a940568f7c37cc4c52c5e0283
|
|
| BLAKE2b-256 |
9698846517e97458e8c15ee246cfe12f207095918dbd0801914057a6a73fe841
|
Provenance
The following attestation bundles were made for tmux_wrapper-0.1.0.tar.gz:
Publisher:
python-publish.yml on Randomizez/TmuxWrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tmux_wrapper-0.1.0.tar.gz -
Subject digest:
df1ce0d946df31c0adbf97ece89aea71b1051caf0302b58ed8c472706c081080 - Sigstore transparency entry: 1144201569
- Sigstore integration time:
-
Permalink:
Randomizez/TmuxWrapper@83dbd613370f70140f932e046e75778e80fda942 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Randomizez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@83dbd613370f70140f932e046e75778e80fda942 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tmux_wrapper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tmux_wrapper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6c5a08ef66a72fdd559b63927f66e6be7abf7f6fe69b7e6e1e37a67a9e50168
|
|
| MD5 |
7b0aab567a30ac0cd7bbd2695fa108ed
|
|
| BLAKE2b-256 |
d9e8e89d45a0bc6043beb2feda32fb40ac907323186254e7e6fa978a20faf5b6
|
Provenance
The following attestation bundles were made for tmux_wrapper-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on Randomizez/TmuxWrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tmux_wrapper-0.1.0-py3-none-any.whl -
Subject digest:
b6c5a08ef66a72fdd559b63927f66e6be7abf7f6fe69b7e6e1e37a67a9e50168 - Sigstore transparency entry: 1144201632
- Sigstore integration time:
-
Permalink:
Randomizez/TmuxWrapper@83dbd613370f70140f932e046e75778e80fda942 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Randomizez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@83dbd613370f70140f932e046e75778e80fda942 -
Trigger Event:
push
-
Statement type: