Name | libtmux JSON |
Version |
0.40.1
JSON |
| download |
home_page | None |
Summary | Typed library that provides an ORM wrapper for tmux, a terminal multiplexer. |
upload_time | 2024-12-24 16:59:53 |
maintainer | None |
docs_url | None |
author | None |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
ncurses
session manager
terminal
tmux
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# libtmux
`libtmux` is a [typed](https://docs.python.org/3/library/typing.html) Python library that provides a wrapper for interacting programmatically with tmux, a terminal multiplexer. You can use it to manage tmux servers,
sessions, windows, and panes. Additionally, `libtmux` powers [tmuxp], a tmux workspace manager.
[![Python Package](https://img.shields.io/pypi/v/libtmux.svg)](https://pypi.org/project/libtmux/)
[![Docs](https://github.com/tmux-python/libtmux/workflows/docs/badge.svg)](https://libtmux.git-pull.com/)
[![Build Status](https://github.com/tmux-python/libtmux/workflows/tests/badge.svg)](https://github.com/tmux-python/tmux-python/actions?query=workflow%3A%22tests%22)
[![Code Coverage](https://codecov.io/gh/tmux-python/libtmux/branch/master/graph/badge.svg)](https://codecov.io/gh/tmux-python/libtmux)
[![License](https://img.shields.io/github/license/tmux-python/libtmux.svg)](https://github.com/tmux-python/libtmux/blob/master/LICENSE)
libtmux builds upon tmux's
[target](http://man.openbsd.org/OpenBSD-5.9/man1/tmux.1#COMMANDS) and
[formats](http://man.openbsd.org/OpenBSD-5.9/man1/tmux.1#FORMATS) to
create an object mapping to traverse, inspect and interact with live
tmux sessions.
View the [documentation](https://libtmux.git-pull.com/),
[API](https://libtmux.git-pull.com/api.html) information and
[architectural details](https://libtmux.git-pull.com/about.html).
# Install
```console
$ pip install --user libtmux
```
# Open a tmux session
Session name `foo`, window name `bar`
```console
$ tmux new-session -s foo -n bar
```
# Pilot your tmux session via python
```console
$ python
```
Use [ptpython], [ipython], etc. for a nice shell with autocompletions:
```console
$ pip install --user ptpython
```
```console
$ ptpython
```
Connect to a live tmux session:
```python
>>> import libtmux
>>> svr = libtmux.Server()
>>> svr
Server(socket_path=/tmp/tmux-.../default)
```
Tip: You can also use [tmuxp]'s [`tmuxp shell`] to drop straight into your
current tmux server / session / window pane.
[tmuxp]: https://tmuxp.git-pull.com/
[`tmuxp shell`]: https://tmuxp.git-pull.com/cli/shell.html
[ptpython]: https://github.com/prompt-toolkit/ptpython
[ipython]: https://ipython.org/
Run any tmux command, respective of context:
Honors tmux socket name and path:
```python
>>> server = Server(socket_name='libtmux_doctest')
>>> server.cmd('display-message', 'hello world')
<libtmux...>
```
New session:
```python
>>> server.cmd('new-session', '-d', '-P', '-F#{session_id}').stdout[0]
'$2'
```
```python
>>> session.cmd('new-window', '-P').stdout[0]
'libtmux...:2.0'
```
From raw command output, to a rich `Window` object (in practice and as shown
later, you'd use `Session.new_window()`):
```python
>>> Window.from_window_id(window_id=session.cmd('new-window', '-P', '-F#{window_id}').stdout[0], server=session.server)
Window(@2 2:..., Session($1 libtmux_...))
```
Create a pane from a window:
```python
>>> window.cmd('split-window', '-P', '-F#{pane_id}').stdout[0]
'%2'
```
Raw output directly to a `Pane`:
```python
>>> Pane.from_pane_id(pane_id=window.cmd('split-window', '-P', '-F#{pane_id}').stdout[0], server=window.server)
Pane(%... Window(@1 1:..., Session($1 libtmux_...)))
```
List sessions:
```python
>>> server.sessions
[Session($1 ...), Session($0 ...)]
```
Filter sessions by attribute:
```python
>>> server.sessions.filter(history_limit='2000')
[Session($1 ...), Session($0 ...)]
```
Direct lookup:
```python
>>> server.sessions.get(session_id="$1")
Session($1 ...)
```
Filter sessions:
```python
>>> server.sessions[0].rename_session('foo')
Session($1 foo)
>>> server.sessions.filter(session_name="foo")
[Session($1 foo)]
>>> server.sessions.get(session_name="foo")
Session($1 foo)
```
Control your session:
```python
>>> session
Session($1 ...)
>>> session.rename_session('my-session')
Session($1 my-session)
```
Create new window in the background (don't switch to it):
```python
>>> bg_window = session.new_window(attach=False, window_name="ha in the bg")
>>> bg_window
Window(@... 2:ha in the bg, Session($1 ...))
# Session can search the window
>>> session.windows.filter(window_name__startswith="ha")
[Window(@... 2:ha in the bg, Session($1 ...))]
# Directly
>>> session.windows.get(window_name__startswith="ha")
Window(@... 2:ha in the bg, Session($1 ...))
# Clean up
>>> bg_window.kill()
```
Close window:
```python
>>> w = session.active_window
>>> w.kill()
```
Grab remaining tmux window:
```python
>>> window = session.active_window
>>> window.split(attach=False)
Pane(%2 Window(@1 1:... Session($1 ...)))
```
Rename window:
```python
>>> window.rename_window('libtmuxower')
Window(@1 1:libtmuxower, Session($1 ...))
```
Split window (create a new pane):
```python
>>> pane = window.split()
>>> pane = window.split(attach=False)
>>> pane.select()
Pane(%3 Window(@1 1:..., Session($1 ...)))
>>> window = session.new_window(attach=False, window_name="test")
>>> window
Window(@2 2:test, Session($1 ...))
>>> pane = window.split(attach=False)
>>> pane
Pane(%5 Window(@2 2:test, Session($1 ...)))
```
Type inside the pane (send key strokes):
```python
>>> pane.send_keys('echo hey send now')
>>> pane.send_keys('echo hey', enter=False)
>>> pane.enter()
Pane(%1 ...)
```
Grab the output of pane:
```python
>>> pane.clear() # clear the pane
Pane(%1 ...)
>>> pane.send_keys("cowsay 'hello'", enter=True)
>>> print('\n'.join(pane.cmd('capture-pane', '-p').stdout)) # doctest: +SKIP
$ cowsay 'hello'
_______
< hello >
-------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
...
```
Traverse and navigate:
```python
>>> pane.window
Window(@1 1:..., Session($1 ...))
>>> pane.window.session
Session($1 ...)
```
# Python support
Unsupported / no security releases or bug fixes:
- Python 2.x: The backports branch is
[`v0.8.x`](https://github.com/tmux-python/libtmux/tree/v0.8.x).
# Donations
Your donations fund development of new features, testing and support.
Your money will go directly to maintenance and development of the
project. If you are an individual, feel free to give whatever feels
right for the value you get out of the project.
See donation options at <https://git-pull.com/support.html>.
# Project details
- tmux support: 1.8+
- python support: >= 3.9, pypy, pypy3
- Source: <https://github.com/tmux-python/libtmux>
- Docs: <https://libtmux.git-pull.com>
- API: <https://libtmux.git-pull.com/api.html>
- Changelog: <https://libtmux.git-pull.com/history.html>
- Issues: <https://github.com/tmux-python/libtmux/issues>
- Test Coverage: <https://codecov.io/gh/tmux-python/libtmux>
- pypi: <https://pypi.python.org/pypi/libtmux>
- Open Hub: <https://www.openhub.net/p/libtmux-python>
- Repology: <https://repology.org/project/python:libtmux/versions>
- License: [MIT](http://opensource.org/licenses/MIT).
Raw data
{
"_id": null,
"home_page": null,
"name": "libtmux",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "ncurses, session manager, terminal, tmux",
"author": null,
"author_email": "Tony Narlock <tony@git-pull.com>",
"download_url": "https://files.pythonhosted.org/packages/20/53/d30bf462b0a005e4541b1c217e15107970063aad99145a259d75b23d35bd/libtmux-0.40.1.tar.gz",
"platform": null,
"description": "# libtmux\n\n`libtmux` is a [typed](https://docs.python.org/3/library/typing.html) Python library that provides a wrapper for interacting programmatically with tmux, a terminal multiplexer. You can use it to manage tmux servers,\nsessions, windows, and panes. Additionally, `libtmux` powers [tmuxp], a tmux workspace manager.\n\n[![Python Package](https://img.shields.io/pypi/v/libtmux.svg)](https://pypi.org/project/libtmux/)\n[![Docs](https://github.com/tmux-python/libtmux/workflows/docs/badge.svg)](https://libtmux.git-pull.com/)\n[![Build Status](https://github.com/tmux-python/libtmux/workflows/tests/badge.svg)](https://github.com/tmux-python/tmux-python/actions?query=workflow%3A%22tests%22)\n[![Code Coverage](https://codecov.io/gh/tmux-python/libtmux/branch/master/graph/badge.svg)](https://codecov.io/gh/tmux-python/libtmux)\n[![License](https://img.shields.io/github/license/tmux-python/libtmux.svg)](https://github.com/tmux-python/libtmux/blob/master/LICENSE)\n\nlibtmux builds upon tmux's\n[target](http://man.openbsd.org/OpenBSD-5.9/man1/tmux.1#COMMANDS) and\n[formats](http://man.openbsd.org/OpenBSD-5.9/man1/tmux.1#FORMATS) to\ncreate an object mapping to traverse, inspect and interact with live\ntmux sessions.\n\nView the [documentation](https://libtmux.git-pull.com/),\n[API](https://libtmux.git-pull.com/api.html) information and\n[architectural details](https://libtmux.git-pull.com/about.html).\n\n# Install\n\n```console\n$ pip install --user libtmux\n```\n\n# Open a tmux session\n\nSession name `foo`, window name `bar`\n\n```console\n$ tmux new-session -s foo -n bar\n```\n\n# Pilot your tmux session via python\n\n```console\n$ python\n```\n\nUse [ptpython], [ipython], etc. for a nice shell with autocompletions:\n\n```console\n$ pip install --user ptpython\n```\n\n```console\n$ ptpython\n```\n\nConnect to a live tmux session:\n\n```python\n>>> import libtmux\n>>> svr = libtmux.Server()\n>>> svr\nServer(socket_path=/tmp/tmux-.../default)\n```\n\nTip: You can also use [tmuxp]'s [`tmuxp shell`] to drop straight into your\ncurrent tmux server / session / window pane.\n\n[tmuxp]: https://tmuxp.git-pull.com/\n[`tmuxp shell`]: https://tmuxp.git-pull.com/cli/shell.html\n[ptpython]: https://github.com/prompt-toolkit/ptpython\n[ipython]: https://ipython.org/\n\nRun any tmux command, respective of context:\n\nHonors tmux socket name and path:\n\n```python\n>>> server = Server(socket_name='libtmux_doctest')\n>>> server.cmd('display-message', 'hello world')\n<libtmux...>\n```\n\nNew session:\n\n```python\n>>> server.cmd('new-session', '-d', '-P', '-F#{session_id}').stdout[0]\n'$2'\n```\n\n```python\n>>> session.cmd('new-window', '-P').stdout[0]\n'libtmux...:2.0'\n```\n\nFrom raw command output, to a rich `Window` object (in practice and as shown\nlater, you'd use `Session.new_window()`):\n\n```python\n>>> Window.from_window_id(window_id=session.cmd('new-window', '-P', '-F#{window_id}').stdout[0], server=session.server)\nWindow(@2 2:..., Session($1 libtmux_...))\n```\n\nCreate a pane from a window:\n\n```python\n>>> window.cmd('split-window', '-P', '-F#{pane_id}').stdout[0]\n'%2'\n```\n\nRaw output directly to a `Pane`:\n\n```python\n>>> Pane.from_pane_id(pane_id=window.cmd('split-window', '-P', '-F#{pane_id}').stdout[0], server=window.server)\nPane(%... Window(@1 1:..., Session($1 libtmux_...)))\n```\n\nList sessions:\n\n```python\n>>> server.sessions\n[Session($1 ...), Session($0 ...)]\n```\n\nFilter sessions by attribute:\n\n```python\n>>> server.sessions.filter(history_limit='2000')\n[Session($1 ...), Session($0 ...)]\n```\n\nDirect lookup:\n\n```python\n>>> server.sessions.get(session_id=\"$1\")\nSession($1 ...)\n```\n\nFilter sessions:\n\n```python\n>>> server.sessions[0].rename_session('foo')\nSession($1 foo)\n>>> server.sessions.filter(session_name=\"foo\")\n[Session($1 foo)]\n>>> server.sessions.get(session_name=\"foo\")\nSession($1 foo)\n```\n\nControl your session:\n\n```python\n>>> session\nSession($1 ...)\n\n>>> session.rename_session('my-session')\nSession($1 my-session)\n```\n\nCreate new window in the background (don't switch to it):\n\n```python\n>>> bg_window = session.new_window(attach=False, window_name=\"ha in the bg\")\n>>> bg_window\nWindow(@... 2:ha in the bg, Session($1 ...))\n\n# Session can search the window\n>>> session.windows.filter(window_name__startswith=\"ha\")\n[Window(@... 2:ha in the bg, Session($1 ...))]\n\n# Directly\n>>> session.windows.get(window_name__startswith=\"ha\")\nWindow(@... 2:ha in the bg, Session($1 ...))\n\n# Clean up\n>>> bg_window.kill()\n```\n\nClose window:\n\n```python\n>>> w = session.active_window\n>>> w.kill()\n```\n\nGrab remaining tmux window:\n\n```python\n>>> window = session.active_window\n>>> window.split(attach=False)\nPane(%2 Window(@1 1:... Session($1 ...)))\n```\n\nRename window:\n\n```python\n>>> window.rename_window('libtmuxower')\nWindow(@1 1:libtmuxower, Session($1 ...))\n```\n\nSplit window (create a new pane):\n\n```python\n>>> pane = window.split()\n>>> pane = window.split(attach=False)\n>>> pane.select()\nPane(%3 Window(@1 1:..., Session($1 ...)))\n>>> window = session.new_window(attach=False, window_name=\"test\")\n>>> window\nWindow(@2 2:test, Session($1 ...))\n>>> pane = window.split(attach=False)\n>>> pane\nPane(%5 Window(@2 2:test, Session($1 ...)))\n```\n\nType inside the pane (send key strokes):\n\n```python\n>>> pane.send_keys('echo hey send now')\n\n>>> pane.send_keys('echo hey', enter=False)\n>>> pane.enter()\nPane(%1 ...)\n```\n\nGrab the output of pane:\n\n```python\n>>> pane.clear() # clear the pane\nPane(%1 ...)\n>>> pane.send_keys(\"cowsay 'hello'\", enter=True)\n>>> print('\\n'.join(pane.cmd('capture-pane', '-p').stdout)) # doctest: +SKIP\n$ cowsay 'hello'\n _______\n< hello >\n -------\n \\ ^__^\n \\ (oo)\\_______\n (__)\\ )\\/\\\n ||----w |\n || ||\n...\n```\n\nTraverse and navigate:\n\n```python\n>>> pane.window\nWindow(@1 1:..., Session($1 ...))\n>>> pane.window.session\nSession($1 ...)\n```\n\n# Python support\n\nUnsupported / no security releases or bug fixes:\n\n- Python 2.x: The backports branch is\n [`v0.8.x`](https://github.com/tmux-python/libtmux/tree/v0.8.x).\n\n# Donations\n\nYour donations fund development of new features, testing and support.\nYour money will go directly to maintenance and development of the\nproject. If you are an individual, feel free to give whatever feels\nright for the value you get out of the project.\n\nSee donation options at <https://git-pull.com/support.html>.\n\n# Project details\n\n- tmux support: 1.8+\n- python support: >= 3.9, pypy, pypy3\n- Source: <https://github.com/tmux-python/libtmux>\n- Docs: <https://libtmux.git-pull.com>\n- API: <https://libtmux.git-pull.com/api.html>\n- Changelog: <https://libtmux.git-pull.com/history.html>\n- Issues: <https://github.com/tmux-python/libtmux/issues>\n- Test Coverage: <https://codecov.io/gh/tmux-python/libtmux>\n- pypi: <https://pypi.python.org/pypi/libtmux>\n- Open Hub: <https://www.openhub.net/p/libtmux-python>\n- Repology: <https://repology.org/project/python:libtmux/versions>\n- License: [MIT](http://opensource.org/licenses/MIT).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Typed library that provides an ORM wrapper for tmux, a terminal multiplexer.",
"version": "0.40.1",
"project_urls": {
"Bug Tracker": "https://github.com/tmux-python/libtmux/issues",
"Changes": "https://github.com/tmux-python/libtmux/blob/master/CHANGES",
"Documentation": "https://libtmux.git-pull.com",
"Repository": "https://github.com/tmux-python/libtmux"
},
"split_keywords": [
"ncurses",
" session manager",
" terminal",
" tmux"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9289179a35a1f0964466bdeb8db2b3b071780693490abd10d28e151b51088747",
"md5": "debd9b73ec8c506c5167fc544b9098e0",
"sha256": "aa8bd4a052ed6ce2686f46fa884022d79e900321b17428e87cc5d1b91fcb6081"
},
"downloads": -1,
"filename": "libtmux-0.40.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "debd9b73ec8c506c5167fc544b9098e0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 56185,
"upload_time": "2024-12-24T16:59:51",
"upload_time_iso_8601": "2024-12-24T16:59:51.267758Z",
"url": "https://files.pythonhosted.org/packages/92/89/179a35a1f0964466bdeb8db2b3b071780693490abd10d28e151b51088747/libtmux-0.40.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2053d30bf462b0a005e4541b1c217e15107970063aad99145a259d75b23d35bd",
"md5": "d66d72ebb7f9c69376eb94694053a28c",
"sha256": "98ffe2b4922449e89dcd0072e1852bcd5757944fd34159d70ed3e57df398796d"
},
"downloads": -1,
"filename": "libtmux-0.40.1.tar.gz",
"has_sig": false,
"md5_digest": "d66d72ebb7f9c69376eb94694053a28c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 318731,
"upload_time": "2024-12-24T16:59:53",
"upload_time_iso_8601": "2024-12-24T16:59:53.761292Z",
"url": "https://files.pythonhosted.org/packages/20/53/d30bf462b0a005e4541b1c217e15107970063aad99145a259d75b23d35bd/libtmux-0.40.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-24 16:59:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tmux-python",
"github_project": "libtmux",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "libtmux"
}