| 1 |
Metadata-Version: 2.4 |
| 2 |
Name: libtmux |
| 3 |
Version: 0.61.0 |
| 4 |
Summary: Typed library that provides an ORM wrapper for tmux, a terminal multiplexer. |
| 5 |
Project-URL: Bug Tracker, https://github.com/tmux-python/libtmux/issues |
| 6 |
Project-URL: Documentation, https://libtmux.git-pull.com |
| 7 |
Project-URL: Repository, https://github.com/tmux-python/libtmux |
| 8 |
Project-URL: Changes, https://github.com/tmux-python/libtmux/blob/master/CHANGES |
| 9 |
Author-email: Tony Narlock <[email protected]> |
| 10 |
License: MIT |
| 11 |
License-File: LICENSE |
| 12 |
Keywords: ncurses,session manager,terminal,tmux |
| 13 |
Classifier: Development Status :: 5 - Production/Stable |
| 14 |
Classifier: Environment :: Web Environment |
| 15 |
Classifier: Framework :: Pytest |
| 16 |
Classifier: Intended Audience :: Developers |
| 17 |
Classifier: License :: OSI Approved :: MIT License |
| 18 |
Classifier: Operating System :: MacOS :: MacOS X |
| 19 |
Classifier: Operating System :: POSIX |
| 20 |
Classifier: Programming Language :: Python |
| 21 |
Classifier: Programming Language :: Python :: 3.10 |
| 22 |
Classifier: Programming Language :: Python :: 3.11 |
| 23 |
Classifier: Programming Language :: Python :: 3.12 |
| 24 |
Classifier: Programming Language :: Python :: 3.13 |
| 25 |
Classifier: Programming Language :: Python :: 3.14 |
| 26 |
Classifier: Programming Language :: Python :: Implementation :: PyPy |
| 27 |
Classifier: Topic :: Software Development :: Libraries :: Python Modules |
| 28 |
Classifier: Topic :: System :: Shells |
| 29 |
Classifier: Topic :: Utilities |
| 30 |
Classifier: Typing :: Typed |
| 31 |
Requires-Python: <4.0,>=3.10 |
| 32 |
Description-Content-Type: text/markdown |
| 33 |
|
| 34 |
<div align="center"> |
| 35 |
<h1>⚙️ libtmux</h1> |
| 36 |
<p><strong>Drive tmux from Python: typed, object-oriented control over servers, sessions, windows, and panes.</strong></p> |
| 37 |
<p> |
| 38 |
<a href="https://libtmux.git-pull.com/"><img src="https://raw.githubusercontent.com/tmux-python/libtmux/master/docs/_static/img/libtmux.svg" alt="libtmux logo" height="120"></a> |
| 39 |
</p> |
| 40 |
<p> |
| 41 |
<a href="https://pypi.org/project/libtmux/"><img src="https://img.shields.io/pypi/v/libtmux.svg" alt="PyPI version"></a> |
| 42 |
<a href="https://libtmux.git-pull.com/"><img src="https://github.com/tmux-python/libtmux/workflows/docs/badge.svg" alt="Docs status"></a> |
| 43 |
<a href="https://github.com/tmux-python/libtmux/actions"><img src="https://github.com/tmux-python/libtmux/workflows/tests/badge.svg" alt="Tests status"></a> |
| 44 |
<a href="https://codecov.io/gh/tmux-python/libtmux"><img src="https://codecov.io/gh/tmux-python/libtmux/branch/master/graph/badge.svg" alt="Coverage"></a> |
| 45 |
<a href="https://github.com/tmux-python/libtmux/blob/master/LICENSE"><img src="https://img.shields.io/github/license/tmux-python/libtmux.svg" alt="License"></a> |
| 46 |
</p> |
| 47 |
</div> |
| 48 |
|
| 49 |
## 🐍 What is libtmux? |
| 50 |
|
| 51 |
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. |
| 52 |
|
| 53 |
### ✨ Features |
| 54 |
|
| 55 |
- Typed, object-oriented control of tmux state |
| 56 |
- Query and [traverse](https://libtmux.git-pull.com/topics/traversal/) live sessions, windows, and panes |
| 57 |
- Raw escape hatch via `.cmd(...)` on any object |
| 58 |
- Works with multiple tmux sockets and servers |
| 59 |
- [Context managers](https://libtmux.git-pull.com/topics/context_managers/) for automatic cleanup |
| 60 |
- [pytest plugin](https://libtmux.git-pull.com/api/pytest-plugin/) for isolated tmux fixtures |
| 61 |
- Proven in production via tmuxp and other tooling |
| 62 |
|
| 63 |
## Requirements & support |
| 64 |
|
| 65 |
- tmux: >= 3.2a |
| 66 |
- Python: >= 3.10 (CPython and PyPy) |
| 67 |
|
| 68 |
Maintenance-only backports (no new fixes): |
| 69 |
|
| 70 |
- Python 2.x: [`v0.8.x`](https://github.com/tmux-python/libtmux/tree/v0.8.x) |
| 71 |
- tmux 1.8-3.1c: [`v0.48.x`](https://github.com/tmux-python/libtmux/tree/v0.48.x) |
| 72 |
|
| 73 |
## 📦 Installation |
| 74 |
|
| 75 |
Stable release: |
| 76 |
|
| 77 |
```console |
| 78 |
$ pip install libtmux |
| 79 |
``` |
| 80 |
|
| 81 |
With pipx: |
| 82 |
|
| 83 |
```console |
| 84 |
$ pipx install libtmux |
| 85 |
``` |
| 86 |
|
| 87 |
With uv / uvx: |
| 88 |
|
| 89 |
```console |
| 90 |
$ uv add libtmux |
| 91 |
``` |
| 92 |
|
| 93 |
```console |
| 94 |
$ uvx --from "libtmux" python |
| 95 |
``` |
| 96 |
|
| 97 |
From the main branch (bleeding edge): |
| 98 |
|
| 99 |
```console |
| 100 |
$ pip install 'git+https://github.com/tmux-python/libtmux.git' |
| 101 |
``` |
| 102 |
|
| 103 |
Tip: libtmux is pre-1.0. Pin a range in projects to avoid surprises: |
| 104 |
|
| 105 |
requirements.txt: |
| 106 |
|
| 107 |
```ini |
| 108 |
libtmux==0.50.* |
| 109 |
``` |
| 110 |
|
| 111 |
pyproject.toml: |
| 112 |
|
| 113 |
```toml |
| 114 |
libtmux = "0.50.*" |
| 115 |
``` |
| 116 |
|
| 117 |
## 🚀 Quickstart |
| 118 |
|
| 119 |
### Open a tmux session |
| 120 |
|
| 121 |
First, start a tmux session to connect to: |
| 122 |
|
| 123 |
```console |
| 124 |
$ tmux new-session -s foo -n bar |
| 125 |
``` |
| 126 |
|
| 127 |
### Pilot your tmux session via Python |
| 128 |
|
| 129 |
Use [ptpython], [ipython], etc. for a nice REPL with autocompletions: |
| 130 |
|
| 131 |
```console |
| 132 |
$ pip install --user ptpython |
| 133 |
``` |
| 134 |
|
| 135 |
```console |
| 136 |
$ ptpython |
| 137 |
``` |
| 138 |
|
| 139 |
Connect to a live tmux session: |
| 140 |
|
| 141 |
```python |
| 142 |
>>> import libtmux |
| 143 |
>>> svr = libtmux.Server() |
| 144 |
>>> svr |
| 145 |
Server(socket_path=/tmp/tmux-.../default) |
| 146 |
``` |
| 147 |
|
| 148 |
**Tip:** You can also use [tmuxp]'s [`tmuxp shell`] to drop straight into your |
| 149 |
current tmux server / session / window / pane. |
| 150 |
|
| 151 |
[ptpython]: https://github.com/prompt-toolkit/ptpython |
| 152 |
[ipython]: https://ipython.org/ |
| 153 |
[`tmuxp shell`]: https://tmuxp.git-pull.com/cli/shell/ |
| 154 |
|
| 155 |
### Run any tmux command |
| 156 |
|
| 157 |
Every object has a `.cmd()` escape hatch that honors socket name and path: |
| 158 |
|
| 159 |
```python |
| 160 |
>>> server = Server(socket_name='libtmux_doctest') |
| 161 |
>>> server.cmd('display-message', 'hello world') |
| 162 |
<libtmux...> |
| 163 |
``` |
| 164 |
|
| 165 |
Create a new session: |
| 166 |
|
| 167 |
```python |
| 168 |
>>> server.cmd('new-session', '-d', '-P', '-F#{session_id}').stdout[0] |
| 169 |
'$...' |
| 170 |
``` |
| 171 |
|
| 172 |
### List and filter sessions |
| 173 |
|
| 174 |
[**Learn more about Filtering**](https://libtmux.git-pull.com/topics/filtering/) |
| 175 |
|
| 176 |
```python |
| 177 |
>>> server.sessions |
| 178 |
[Session($... ...), ...] |
| 179 |
``` |
| 180 |
|
| 181 |
Filter by attribute: |
| 182 |
|
| 183 |
```python |
| 184 |
>>> server.sessions.filter(history_limit='2000') |
| 185 |
[Session($... ...), ...] |
| 186 |
``` |
| 187 |
|
| 188 |
Direct lookup: |
| 189 |
|
| 190 |
```python |
| 191 |
>>> server.sessions.get(session_id=session.session_id) |
| 192 |
Session($... ...) |
| 193 |
``` |
| 194 |
|
| 195 |
### Control sessions and windows |
| 196 |
|
| 197 |
[**Learn more about Workspace Setup**](https://libtmux.git-pull.com/topics/workspace_setup/) |
| 198 |
|
| 199 |
```python |
| 200 |
>>> session.rename_session('my-session') |
| 201 |
Session($... my-session) |
| 202 |
``` |
| 203 |
|
| 204 |
Create new window in the background (don't switch to it): |
| 205 |
|
| 206 |
```python |
| 207 |
>>> bg_window = session.new_window(attach=False, window_name="bg-work") |
| 208 |
>>> bg_window |
| 209 |
Window(@... ...:bg-work, Session($... ...)) |
| 210 |
|
| 211 |
>>> session.windows.filter(window_name__startswith="bg") |
| 212 |
[Window(@... ...:bg-work, Session($... ...))] |
| 213 |
|
| 214 |
>>> session.windows.get(window_name__startswith="bg") |
| 215 |
Window(@... ...:bg-work, Session($... ...)) |
| 216 |
|
| 217 |
>>> bg_window.kill() |
| 218 |
``` |
| 219 |
|
| 220 |
### Split windows and send keys |
| 221 |
|
| 222 |
[**Learn more about Pane Interaction**](https://libtmux.git-pull.com/topics/pane_interaction/) |
| 223 |
|
| 224 |
```python |
| 225 |
>>> pane = window.split(attach=False) |
| 226 |
>>> pane |
| 227 |
Pane(%... Window(@... ...:..., Session($... ...))) |
| 228 |
``` |
| 229 |
|
| 230 |
Type inside the pane (send keystrokes): |
| 231 |
|
| 232 |
```python |
| 233 |
>>> pane.send_keys('echo hello') |
| 234 |
>>> pane.send_keys('echo hey', enter=False) |
| 235 |
>>> pane.enter() |
| 236 |
Pane(%... ...) |
| 237 |
``` |
| 238 |
|
| 239 |
### Capture pane output |
| 240 |
|
| 241 |
```python |
| 242 |
>>> pane.clear() |
| 243 |
Pane(%... ...) |
| 244 |
>>> pane.send_keys("echo 'hello world'", enter=True) |
| 245 |
>>> pane.cmd('capture-pane', '-p').stdout # doctest: +SKIP |
| 246 |
["$ echo 'hello world'", 'hello world', '$'] |
| 247 |
``` |
| 248 |
|
| 249 |
### Traverse the hierarchy |
| 250 |
|
| 251 |
[**Learn more about Traversal**](https://libtmux.git-pull.com/topics/traversal/) |
| 252 |
|
| 253 |
Navigate from pane up to window to session: |
| 254 |
|
| 255 |
```python |
| 256 |
>>> pane.window |
| 257 |
Window(@... ...:..., Session($... ...)) |
| 258 |
>>> pane.window.session |
| 259 |
Session($... ...) |
| 260 |
``` |
| 261 |
|
| 262 |
## Core concepts |
| 263 |
|
| 264 |
| libtmux object | tmux concept | Notes | |
| 265 |
|----------------|-----------------------------|--------------------------------| |
| 266 |
| [`Server`](https://libtmux.git-pull.com/api/libtmux.server/) | tmux server / socket | Entry point; owns sessions | |
| 267 |
| [`Session`](https://libtmux.git-pull.com/api/libtmux.session/) | tmux session (`$0`, `$1`,...) | Owns windows | |
| 268 |
| [`Window`](https://libtmux.git-pull.com/api/libtmux.window/) | tmux window (`@1`, `@2`,...) | Owns panes | |
| 269 |
| [`Pane`](https://libtmux.git-pull.com/api/libtmux.pane/) | tmux pane (`%1`, `%2`,...) | Where commands run | |
| 270 |
|
| 271 |
Also available: [`Options`](https://libtmux.git-pull.com/api/libtmux.options/) and [`Hooks`](https://libtmux.git-pull.com/api/libtmux.hooks/) abstractions for tmux configuration. |
| 272 |
|
| 273 |
Collections are live and queryable: |
| 274 |
|
| 275 |
```python |
| 276 |
server = libtmux.Server() |
| 277 |
session = server.sessions.get(session_name="demo") |
| 278 |
api_windows = session.windows.filter(window_name__startswith="api") |
| 279 |
pane = session.active_window.active_pane |
| 280 |
pane.send_keys("echo 'hello from libtmux'", enter=True) |
| 281 |
``` |
| 282 |
|
| 283 |
## tmux vs libtmux vs tmuxp |
| 284 |
|
| 285 |
| Tool | Layer | Typical use case | |
| 286 |
|---------|----------------------------|----------------------------------------------------| |
| 287 |
| tmux | CLI / terminal multiplexer | Everyday terminal usage, manual control | |
| 288 |
| libtmux | Python API over tmux | Programmatic control, automation, testing | |
| 289 |
| tmuxp | App on top of libtmux | Declarative tmux workspaces from YAML / TOML | |
| 290 |
|
| 291 |
## Testing & fixtures |
| 292 |
|
| 293 |
[**Learn more about the pytest plugin**](https://libtmux.git-pull.com/api/pytest-plugin/) |
| 294 |
|
| 295 |
Writing a tool that interacts with tmux? Use our fixtures to keep your tests clean and isolated. |
| 296 |
|
| 297 |
```python |
| 298 |
def test_my_tmux_tool(session): |
| 299 |
# session is a real tmux session in an isolated server |
| 300 |
window = session.new_window(window_name="test") |
| 301 |
pane = window.active_pane |
| 302 |
pane.send_keys("echo 'hello from test'", enter=True) |
| 303 |
|
| 304 |
assert window.window_name == "test" |
| 305 |
# Fixtures handle cleanup automatically |
| 306 |
``` |
| 307 |
|
| 308 |
- Fresh tmux server/session/window/pane fixtures per test |
| 309 |
- Temporary HOME and tmux config fixtures keep indices stable |
| 310 |
- `TestServer` helper spins up multiple isolated tmux servers |
| 311 |
|
| 312 |
## When you might not need libtmux |
| 313 |
|
| 314 |
- Layouts are static and live entirely in tmux config files |
| 315 |
- You do not need to introspect or control running tmux from other tools |
| 316 |
- Python is unavailable where tmux is running |
| 317 |
|
| 318 |
## Project links |
| 319 |
|
| 320 |
**Topics:** |
| 321 |
[Traversal](https://libtmux.git-pull.com/topics/traversal/) · |
| 322 |
[Filtering](https://libtmux.git-pull.com/topics/filtering/) · |
| 323 |
[Pane Interaction](https://libtmux.git-pull.com/topics/pane_interaction/) · |
| 324 |
[Workspace Setup](https://libtmux.git-pull.com/topics/workspace_setup/) · |
| 325 |
[Automation Patterns](https://libtmux.git-pull.com/topics/automation_patterns/) · |
| 326 |
[Context Managers](https://libtmux.git-pull.com/topics/context_managers/) · |
| 327 |
[Options & Hooks](https://libtmux.git-pull.com/topics/options_and_hooks/) |
| 328 |
|
| 329 |
**Reference:** |
| 330 |
[Docs][docs] · |
| 331 |
[API][api] · |
| 332 |
[pytest plugin](https://libtmux.git-pull.com/api/pytest-plugin/) · |
| 333 |
[Architecture][architecture] · |
| 334 |
[Changelog][history] · |
| 335 |
[Migration][migration] |
| 336 |
|
| 337 |
**Project:** |
| 338 |
[Issues][issues] · |
| 339 |
[Coverage][coverage] · |
| 340 |
[Releases][releases] · |
| 341 |
[License][license] · |
| 342 |
[Support][support] |
| 343 |
|
| 344 |
**[The Tao of tmux][tao]** — deep-dive book on tmux fundamentals |
| 345 |
|
| 346 |
## Contributing & support |
| 347 |
|
| 348 |
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]. |
| 349 |
|
| 350 |
[docs]: https://libtmux.git-pull.com |
| 351 |
[api]: https://libtmux.git-pull.com/api/ |
| 352 |
[architecture]: https://libtmux.git-pull.com/topics/architecture/ |
| 353 |
[history]: https://libtmux.git-pull.com/history/ |
| 354 |
[migration]: https://libtmux.git-pull.com/migration/ |
| 355 |
[issues]: https://github.com/tmux-python/libtmux/issues |
| 356 |
[coverage]: https://codecov.io/gh/tmux-python/libtmux |
| 357 |
[releases]: https://pypi.org/project/libtmux/ |
| 358 |
[license]: https://github.com/tmux-python/libtmux/blob/master/LICENSE |
| 359 |
[support]: https://tony.sh/support.html |
| 360 |
[tao]: https://leanpub.com/the-tao-of-tmux |
| 361 |
[tmuxp]: https://tmuxp.git-pull.com |
| 362 |
[tmux]: https://github.com/tmux/tmux |