Manage tmux sessions on local and remote machines
Project description
tmux-manager
Manage tmux sessions on local and remote machines from Python.
from tmux_manager import TmuxManager
# Local
mgr = TmuxManager()
mgr.new_session("work")
print(mgr.list_sessions()) # ["work"]
mgr.attach_session("work")
# Remote — validates connectivity, warms up ControlMaster
with TmuxManager(host="devbox", user="alice") as mgr:
mgr.connect() # raises ConnectionError if unreachable
mgr.new_session("work")
print(mgr.list_sessions())
Install
uv add tmux-manager
or with pip:
pip install tmux-manager
API
TmuxManager(host=None, user=None)
| Method | Description |
|---|---|
connect() |
Validate SSH connectivity; warms up ControlMaster (Linux/macOS). Raises ConnectionError on failure. Returns self for chaining |
close() |
Tear down SSH multiplexing and clean up temp dir. Called automatically by __exit__ and __del__ |
is_available() |
True if tmux is installed on the target |
command_available(cmd) |
True if cmd is on PATH on the target |
list_sessions() |
Return list of session names |
has_session(name) |
True if session name exists |
new_session(name) |
Create a new detached session |
kill_session(name) |
Kill the named session |
attach_session(name) |
Attach (requires a live PTY) |
SSH aliases
Remote operations use the system ssh command, which reads ~/.ssh/config
automatically. Any alias you have defined works without extra configuration:
# ~/.ssh/config
Host devbox
HostName 192.168.1.10
User alice
IdentityFile ~/.ssh/id_ed25519
Port 2222
# Just use the alias name — hostname, user, port and key are resolved automatically
mgr = TmuxManager("devbox")
print(mgr.list_sessions())
Connection multiplexing
On Linux/macOS, SSH ControlMaster multiplexing is used automatically.
The first SSH call authenticates (e.g. password prompt), and subsequent
calls reuse the connection — no extra password prompts. Call connect()
to warm up the master connection upfront:
mgr = TmuxManager("devbox", "alice").connect()
mgr.list_sessions() # reuses connection — no password prompt
mgr.is_available() # reuses connection — no password prompt
On Windows, ControlMaster is not supported by Win32-OpenSSH.
Each operation spawns an independent ssh process, so password auth
will prompt once per call. Use SSH key-based authentication to avoid
repeated prompts:
# ~/.ssh/config
Host devbox
IdentityFile ~/.ssh/id_ed25519
Notes
- All remote operations delegate to the system
sshcommand (zero runtime dependencies) - Use as a context manager (
with) to clean up ControlMaster sockets connect()validates SSH connectivity upfront and raisesConnectionErroron failureattach_sessionusesssh -tfor interactive PTY attachment
Development
Local Setup
Clone the repo and install in editable mode:
git clone https://github.com/mahsoommoosa42/tmux-manager.git
cd tmux-manager
uv sync --extra dev
Run tests:
uv run pytest --cov=tmux_manager --cov-report=term-missing
All tests must pass at 100% branch coverage before submitting a PR.
Project Structure
See CLAUDE.md for detailed architecture, module documentation, testing patterns, and design decisions.
Contributing
Opening a Pull Request
- Fork and clone: Fork the repo, then clone your fork locally
- Create a branch:
git checkout -b fix/issue-nameorfeat/feature-name - Make changes: Write code, add tests, update docs as needed
- Run tests: Ensure
uv run pytest --cov-fail-under=100passes - Commit: Write clear, concise commit messages
- Push:
git push origin your-branch - Open PR: Open a pull request on GitHub with a description of your changes
Guidelines
- All new code must have 100% branch test coverage
- Follow existing code style (see CLAUDE.md for patterns)
- Update README.md if adding new features
- No external runtime dependencies (zero-dep library)
License
GNU General Public License v3.
Project details
Release history Release notifications | RSS feed
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_manager-1.1.0.tar.gz.
File metadata
- Download URL: tmux_manager-1.1.0.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bce08585735ac8e7793665cc571e66bf5dfb299b9c27b3fc41d64cb587d0350
|
|
| MD5 |
7051581882cb2467035987385f7ea615
|
|
| BLAKE2b-256 |
f4bae1d580d893f84fd029af1ed4f6e96e833638aec11a795974290a0c728d37
|
File details
Details for the file tmux_manager-1.1.0-py3-none-any.whl.
File metadata
- Download URL: tmux_manager-1.1.0-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ec86c2cad61621ab647f20664a9e31efad7c8edf97c006bd6c4a0da0e187f95
|
|
| MD5 |
705150bafcc087893dbd0ebb5cdd8259
|
|
| BLAKE2b-256 |
4df565c0bed59f457ecc7e88d7cf5ce5162e9bb08b275eda40d95789e13fa7e9
|