Skip to main content

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 ssh command (zero runtime dependencies)
  • Use as a context manager (with) to clean up ControlMaster sockets
  • connect() validates SSH connectivity upfront and raises ConnectionError on failure
  • attach_session uses ssh -t for 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

  1. Fork and clone: Fork the repo, then clone your fork locally
  2. Create a branch: git checkout -b fix/issue-name or feat/feature-name
  3. Make changes: Write code, add tests, update docs as needed
  4. Run tests: Ensure uv run pytest --cov-fail-under=100 passes
  5. Commit: Write clear, concise commit messages
  6. Push: git push origin your-branch
  7. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tmux_manager-1.1.0.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tmux_manager-1.1.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

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

Hashes for tmux_manager-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9bce08585735ac8e7793665cc571e66bf5dfb299b9c27b3fc41d64cb587d0350
MD5 7051581882cb2467035987385f7ea615
BLAKE2b-256 f4bae1d580d893f84fd029af1ed4f6e96e833638aec11a795974290a0c728d37

See more details on using hashes here.

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

Hashes for tmux_manager-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ec86c2cad61621ab647f20664a9e31efad7c8edf97c006bd6c4a0da0e187f95
MD5 705150bafcc087893dbd0ebb5cdd8259
BLAKE2b-256 4df565c0bed59f457ecc7e88d7cf5ce5162e9bb08b275eda40d95789e13fa7e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page