colabapi 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
colabapi/ui.py ADDED
@@ -0,0 +1,102 @@
1
+ """Tiny interactive terminal helpers (no extra dependencies).
2
+
3
+ The arrow-key `select` menu is used wherever colabapi asks the user to pick a
4
+ session (shell / stop / monitor). It uses raw terminal mode via termios, which is
5
+ fine because the underlying `colab` CLI is Linux/macOS only. When stdin is not a
6
+ TTY (e.g. run from a service) it degrades to returning the first option, so
7
+ non-interactive callers still work.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import sys
13
+ from typing import Callable, Optional, Sequence, TypeVar
14
+
15
+ T = TypeVar("T")
16
+
17
+ _ESC = "\x1b"
18
+
19
+
20
+ def _read_key() -> str:
21
+ """Read one logical keypress in raw mode and normalise it to a name."""
22
+ ch = sys.stdin.read(1)
23
+ if ch == _ESC:
24
+ nxt = sys.stdin.read(2) # arrow keys arrive as ESC [ A/B/C/D
25
+ return {"[A": "up", "[B": "down"}.get(nxt, "esc")
26
+ if ch in ("\r", "\n"):
27
+ return "enter"
28
+ if ch == "\x03": # Ctrl-C
29
+ raise KeyboardInterrupt
30
+ if ch in ("k", "K"):
31
+ return "up"
32
+ if ch in ("j", "J"):
33
+ return "down"
34
+ if ch in ("q", "Q"):
35
+ return "quit"
36
+ return ch
37
+
38
+
39
+ def select(options: Sequence[T],
40
+ title: str = "Select",
41
+ to_label: Callable[[T], str] = str,
42
+ footer: str = "↑/↓ move · Enter select · q cancel") -> Optional[T]:
43
+ """Interactive single-choice menu. Returns the chosen item, or None if cancelled.
44
+
45
+ With zero options returns None; with exactly one option (or no TTY) returns it
46
+ immediately without prompting.
47
+ """
48
+ n = len(options)
49
+ if n == 0:
50
+ return None
51
+ if n == 1 or not sys.stdin.isatty() or not sys.stdout.isatty():
52
+ return options[0]
53
+
54
+ idx = 0
55
+ out = sys.stdout
56
+ lines = 0
57
+
58
+ def draw() -> None:
59
+ nonlocal lines
60
+ buf = [f"\x1b[1;36m{title}\x1b[0m"]
61
+ for i, opt in enumerate(options):
62
+ label = to_label(opt)
63
+ if i == idx:
64
+ buf.append(f"\x1b[1;32m❯ {label}\x1b[0m")
65
+ else:
66
+ buf.append(f" {label}")
67
+ buf.append(f"\x1b[2m{footer}\x1b[0m")
68
+ out.write("\r\n".join(buf))
69
+ out.flush()
70
+ lines = len(buf)
71
+
72
+ import termios
73
+ import tty
74
+
75
+ fd = sys.stdin.fileno()
76
+ old = termios.tcgetattr(fd)
77
+ chosen: Optional[T] = None
78
+ try:
79
+ tty.setraw(fd)
80
+ draw()
81
+ while True:
82
+ key = _read_key()
83
+ if key == "up":
84
+ idx = (idx - 1) % n
85
+ elif key == "down":
86
+ idx = (idx + 1) % n
87
+ elif key == "enter":
88
+ chosen = options[idx]
89
+ break
90
+ elif key in ("quit", "esc"):
91
+ chosen = None
92
+ break
93
+ else:
94
+ continue
95
+ # Move cursor to the top of the block and repaint.
96
+ out.write(f"\r\x1b[{lines - 1}A\x1b[J")
97
+ draw()
98
+ finally:
99
+ termios.tcsetattr(fd, termios.TCSADRAIN, old)
100
+ out.write("\r\n")
101
+ out.flush()
102
+ return chosen
@@ -0,0 +1,232 @@
1
+ Metadata-Version: 2.4
2
+ Name: colabapi
3
+ Version: 0.1.0
4
+ Summary: Run and keep a Google Colab runtime alive, then reach its terminal from your own server or laptop. A CLI for headless, persistent Colab sessions.
5
+ Author: lil-limbo
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/lil-limbo/colabapi
8
+ Project-URL: Repository, https://github.com/lil-limbo/colabapi
9
+ Project-URL: Issues, https://github.com/lil-limbo/colabapi/issues
10
+ Keywords: google colab,colab,colab terminal,colab ssh,colab cli,persistent colab,colab keep alive,headless colab,colab runtime,jupyter,gpu,remote terminal,vps
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: System :: Distributed Computing
23
+ Classifier: Topic :: Utilities
24
+ Requires-Python: >=3.9
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: click>=8.1
28
+ Requires-Dist: rich>=13.0
29
+ Requires-Dist: google-colab-cli>=0.6.0
30
+ Dynamic: license-file
31
+
32
+ # colabapi: a terminal for a persistent Google Colab runtime
33
+
34
+ **Run Google Colab from your own terminal, keep the runtime alive after you close the browser, and reach its shell from any VPS or laptop.** `colabapi` is a small, open source command line tool that turns a Google Colab GPU/TPU session into something you can drive headlessly. Perfect for demos, MVPs, and long running jobs that must survive after the Colab web tab is gone.
35
+
36
+ > **In one line:** `colabapi` gives you a persistent Colab terminal on your own server, using Google's official, ban safe sign in and tunnel, and it never sees your Google password.
37
+
38
+ <!-- Keywords: google colab terminal, colab cli, colab ssh, persistent colab, keep colab alive, headless colab, run colab from terminal, colab gpu terminal, colab from vps, colab session keep alive -->
39
+
40
+ ---
41
+
42
+ ## Why colabapi?
43
+
44
+ Google Colab is fantastic free (and paid) GPU/TPU compute, but it only lives inside a browser tab. Close the tab or lose your connection and the session can go with it. That makes it awkward to:
45
+
46
+ - **demo an MVP** that needs a GPU without renting a server,
47
+ - **reach the runtime from a VPS** or a headless box,
48
+ - **register it as a background service** that stays up, or
49
+ - **watch CPU / GPU / RAM** from a normal terminal.
50
+
51
+ `colabapi` solves this by wrapping **Google's official [`google-colab-cli`](https://github.com/googlecolab/google-colab-cli)** with a friendly single command, a systemd service, a runtime picker, a live resource monitor, and a session time display. You sign in through Google's own browser flow; `colabapi` connects over Google's sanctioned tunnel.
52
+
53
+ ## Features
54
+
55
+ - 🔐 **Browser sign in, no password handling.** Authentication happens in Google's own login flow (including 2FA / device checks). `colabapi` never asks for, stores, or transmits your Google credentials.
56
+ - 💻 **Real terminal into the runtime.** `colabapi shell` drops you into a live PTY on the Colab VM. `colabapi repl` gives you a Python REPL.
57
+ - 🎛 **Runtime picker.** List CPU / T4 / L4 / G4 / A100 / H100 / TPU options; paid tier runtimes are clearly flagged as unavailable on a free account.
58
+ - 📈 **Live CPU / GPU / RAM monitor.** `colabapi monitor` streams runtime stats to your terminal (psutil + `nvidia-smi`).
59
+ - ⏱ **Session time display.** See uptime and an estimate of how long before Colab's max lifetime cap.
60
+ - ♻️ **Keepalive that resists the idle timeout.** Google's official daemon does the primary keepalive; `colabapi` adds a supervisory health check.
61
+ - 🧩 **Runs as a Linux service.** `colabapi service install` registers a systemd user service so your session survives logout.
62
+ - 🔎 **Inspectable & MIT licensed.** Read every line. Nothing phones home.
63
+
64
+ ## How it works
65
+
66
+ ```
67
+ you > colabapi (this tool) > colab (Google's official CLI) > Google's tunnel > your Colab runtime (GPU/TPU VM)
68
+
69
+ colabapi adds: runtime picker, monitor, session timer, systemd service
70
+ colabapi never handles your Google password
71
+ ```
72
+
73
+ `colabapi` is an **orchestration and UX layer**. The heavy lifting (OAuth sign in, allocating the runtime, and the encrypted terminal tunnel) is delegated to Google's first party CLI, which is the safe, supported way to do this.
74
+
75
+ ## Install
76
+
77
+ **One command installs the whole system.** Google's official Colab CLI is pulled in automatically as a dependency, so you never install it separately.
78
+
79
+ ### With pipx (recommended)
80
+
81
+ ```bash
82
+ pipx install colabapi
83
+ ```
84
+
85
+ ### With pip
86
+
87
+ ```bash
88
+ pip install --user colabapi
89
+ ```
90
+
91
+ > **On Kali / Debian / Ubuntu** you may hit `error: externally-managed-environment` (PEP 668). This is the OS protecting its system Python, not a colabapi problem. Use `pipx` (above), a virtualenv, or override it:
92
+ >
93
+ > ```bash
94
+ > pip install --user colabapi --break-system-packages
95
+ > ```
96
+
97
+ ### One line install script
98
+
99
+ ```bash
100
+ curl -fsSL https://raw.githubusercontent.com/lil-limbo/colabapi/main/scripts/install.sh | bash
101
+ ```
102
+
103
+ ### From source
104
+
105
+ ```bash
106
+ git clone https://github.com/lil-limbo/colabapi.git
107
+ cd colabapi
108
+ pip install -e .
109
+ ```
110
+
111
+ > **On Kali / Debian / Ubuntu**, `pip install -e .` may fail with `externally-managed-environment` (PEP 668). Pick one:
112
+ >
113
+ > ```bash
114
+ > # Option A: override the guard (quickest)
115
+ > pip install -e . --break-system-packages
116
+ >
117
+ > # Option B: use an isolated virtualenv (cleanest)
118
+ > python3 -m venv .venv && source .venv/bin/activate && pip install -e .
119
+ > ```
120
+
121
+ **Requirement:** Python 3.9+. That's it. Everything else installs with the package.
122
+
123
+ Verify everything is wired up:
124
+
125
+ ```bash
126
+ colabapi doctor
127
+ ```
128
+
129
+ ## Quickstart
130
+
131
+ ```bash
132
+ # 1. Sign in (opens Google's own login in your browser, no password asked)
133
+ colabapi login
134
+
135
+ # 2. Pick a runtime, then name the session when asked
136
+ colabapi run # interactive picker + name prompt
137
+ colabapi run --runtime t4 # or go straight to a T4 GPU
138
+
139
+ # 3. Use it (omit the name to pick from an arrow-key list)
140
+ colabapi shell # terminal on the session, live monitor on top
141
+ colabapi monitor # live CPU / GPU / RAM
142
+ colabapi sessions # list your sessions
143
+ colabapi status # reachability + estimated time remaining
144
+ colabapi stop # stop a session (or: colabapi stop <name>)
145
+
146
+ # 4. Keep it alive after you log out of your server
147
+ colabapi service install
148
+ systemctl --user start colabapi
149
+ ```
150
+
151
+ Press **Ctrl+C** to leave the monitor; type **`exit`** or press **Ctrl+D** to leave the shell. The Colab runtime keeps running until you stop it or Colab's timers end it.
152
+
153
+ ## Command reference
154
+
155
+ | Command | What it does |
156
+ |---|---|
157
+ | `colabapi login` | Sign in via Google's browser flow (no password handled). |
158
+ | `colabapi runtimes` | List runtime types and which need a paid plan. |
159
+ | `colabapi run [--runtime KEY]` | Allocate a runtime and name the session (delegates to `colab new -s NAME`). |
160
+ | `colabapi sessions` | List the sessions colabapi manages. |
161
+ | `colabapi shell [NAME]` | Terminal on a session with a live monitor on top; arrow-key picker if NAME omitted. |
162
+ | `colabapi repl [NAME]` | Interactive Python REPL on a session (`colab repl`). |
163
+ | `colabapi monitor [NAME]` | Live CPU / GPU / RAM monitor for a session. |
164
+ | `colabapi status [NAME]` | Session reachability and estimated time left. |
165
+ | `colabapi stop [NAME]` | Stop a session (`colab stop`); arrow-key picker if NAME omitted. |
166
+ | `colabapi daemon [NAME]` | Supervisory keepalive (used by the service). |
167
+ | `colabapi service install\|uninstall\|status` | Manage the systemd user service. |
168
+ | `colabapi doctor` | Check your environment and the `colab` CLI interface. |
169
+ | `colabapi raw -- <args>` | Passthrough to the official `colab` CLI. |
170
+
171
+ ## Running as a Linux service
172
+
173
+ `colabapi` installs as a **systemd user service** (no root required):
174
+
175
+ ```bash
176
+ colabapi service install # writes ~/.config/systemd/user/colabapi.service and enables lingering
177
+ systemctl --user start colabapi
178
+ systemctl --user status colabapi
179
+ ```
180
+
181
+ Lingering (`loginctl enable-linger`) lets the service keep running after you disconnect from the VPS, which is exactly what you want for an always on demo.
182
+
183
+ ## Privacy
184
+
185
+ **We do not capture your login data. We do not collect anything.**
186
+
187
+ - `colabapi` has **no code path that asks for, reads, stores, or transmits your Google password.** Sign in is delegated entirely to Google's official CLI and happens in your own browser under Google's real login flow.
188
+ - `colabapi` operates **no servers**. There is nothing for your data to be sent to. The only network connections are between *your* machine, Google, and (via the official CLI) *your* Colab runtime.
189
+ - The only things written to disk are **plain preferences and session bookkeeping** (which runtime you picked and when), under `~/.config/colabapi` and `~/.local/state/colabapi`.
190
+ - The project is **MIT licensed and fully open source.** [Read the code](https://github.com/lil-limbo/colabapi/tree/main/colabapi). If you don't trust a claim here, verify it in the source. That's the point.
191
+
192
+ ## Safety & Colab's limits (please read)
193
+
194
+ `colabapi` deliberately uses **Google's official CLI** instead of the older "SSH into Colab via ngrok/cloudflared" trick, because Colab's own FAQ lists *remote control such as SSH shells* as an activity that can get a runtime (or an account) terminated. Using the sanctioned path is far safer for your Google account.
195
+
196
+ Two limits **nobody** can bypass, and `colabapi` doesn't pretend to:
197
+
198
+ - **Idle timeout (~90 min):** avoided by the keepalive while a session is active.
199
+ - **Absolute max lifetime (~12 h free, up to 24 h paid):** a hard cap. `colabapi` shows an *estimate* of time left, but Google enforces the ceiling.
200
+
201
+ Be a good citizen: don't hold GPU runtimes idle just to reserve them. Aggressive keepalive can get an account flagged.
202
+
203
+ ## FAQ
204
+
205
+ **Does colabapi see or store my Google password?**
206
+ No. Sign in is handled by Google's official CLI in your browser. `colabapi` has no password code path at all.
207
+
208
+ **How do I keep a Google Colab session alive after closing the browser?**
209
+ Allocate a runtime with `colabapi run`, then install the service (`colabapi service install`). Google's keepalive holds off the idle timeout; the systemd service keeps `colabapi` supervising it after you log out.
210
+
211
+ **Can I get a terminal / shell into Google Colab?**
212
+ Yes. `colabapi shell` opens a live PTY on the runtime via Google's `colab console`. `colabapi repl` gives a Python REPL.
213
+
214
+ **Can I use a free Colab account?**
215
+ Yes. CPU and T4 GPU runtimes are available on the free tier. Paid runtimes (L4, A100, H100, TPU) are shown but flagged; Colab itself refuses them on free accounts.
216
+
217
+ **How is this different from Google's official `colab` CLI?**
218
+ `colabapi` *uses* the official CLI under the hood and adds a single `colabapi` command, a runtime picker with paid tier flags, a live resource monitor, a session timer, and a ready made systemd service. If you only need raw commands, use `colab` directly; if you want the persistent service demo workflow, use `colabapi`.
219
+
220
+ **Does it work on a VPS / headless server?**
221
+ Yes, that's the main use case. Sign in once in a browser, then run everything from the server, optionally as a systemd service.
222
+
223
+ **Is this affiliated with Google?**
224
+ No. `colabapi` is an independent, open source wrapper. "Google Colab" is a trademark of Google LLC.
225
+
226
+ ## Contributing
227
+
228
+ Issues and pull requests welcome. If Google changes the official CLI's flags, the runtime→flag mapping lives in a single file (`colabapi/runtime.py`) and `colabapi doctor` will flag drift.
229
+
230
+ ## License
231
+
232
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,17 @@
1
+ colabapi/__init__.py,sha256=xlliW1D0rdUbCaQml94K_VEVb4aMQV6PfWpHB8dbpz4,263
2
+ colabapi/cli.py,sha256=MgpH_zs7aLjpVZjoxZLI9Ic_8z7cs1HuU9XPjygKFlg,17657
3
+ colabapi/colabcli.py,sha256=AT51fxGzc8TTiu3xK8qp9R4jIjnF4r_pJy3_Zg3JS8E,9410
4
+ colabapi/config.py,sha256=AXNKEXDk6VuWWEboRPNrNysaMnNGv-xBP7VBFtUrHwU,5011
5
+ colabapi/keepalive.py,sha256=wE2m1x3Eruf8d0rpKqZg9Tr2dET7ZofLvcZlLQZV5GU,2483
6
+ colabapi/monitor.py,sha256=Z-hhJohafL8F6p7vuhNkR1jiOMV-HHIV-V8oCE99cb8,4819
7
+ colabapi/runtime.py,sha256=vSsfzIcKqPuu05T4ZY6TTVkikUzvBqfr2sgR_sHkN10,3004
8
+ colabapi/service.py,sha256=_7-Z031HX-dmg2EZ-J9ZDklK22se0KJM6JkkdNU0UlA,2196
9
+ colabapi/shellview.py,sha256=zH3-BGIjuwphl1GSxY40j8j-HZN45kyApGJ-tNFBFPQ,4428
10
+ colabapi/timing.py,sha256=6TlQTfY6cId-UJL55wU_-Ht7_90RasKJlyYZ-uVsvr4,1714
11
+ colabapi/ui.py,sha256=NDtVyf1oBH-eHK8sDf5mPdUnC9lPilkm_VJSmi9n084,3001
12
+ colabapi-0.1.0.dist-info/licenses/LICENSE,sha256=yI25WSp2hzlwIoiklr-Re5bhLrp42lAKTHhCH4yPi_w,1066
13
+ colabapi-0.1.0.dist-info/METADATA,sha256=JOipv-TNYqru66RrV-gfPfN64sYA3n5jXxV5mbr8pQI,11850
14
+ colabapi-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
15
+ colabapi-0.1.0.dist-info/entry_points.txt,sha256=mirIudRE-VzrLVP7uL_Indt0qoL3z9X-iVTHi0I6qJk,47
16
+ colabapi-0.1.0.dist-info/top_level.txt,sha256=oS9cg0HsjOh_gD_TBWEF7EYRoeqPRhM0On6ZKqONeA0,9
17
+ colabapi-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ colabapi = colabapi.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 lil-limbo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ colabapi