Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on:
pull_request:
push:
branches:
- main

permissions:
contents: read

jobs:
test:
name: ${{ matrix.os }} / Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python-version: "3.11"
- os: ubuntu-latest
python-version: "3.12"
- os: ubuntu-latest
python-version: "3.13"
- os: windows-latest
python-version: "3.11"
- os: windows-latest
python-version: "3.12"
- os: windows-latest
python-version: "3.13"

steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install uv
run: python -m pip install uv

- name: Install dependencies
run: uv sync --dev

- name: Run tests
run: uv run pytest
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
The package version is derived from the git tag via `hatch-vcs`; each release
below corresponds to a tag of the same name.

## [Unreleased]

### Added

- **Windows support:** Native Windows terminal support using `msvcrt` and `ctypes`.
The CLI now works in Windows Terminal, PowerShell, and CMD without WSL or Docker.
Console input handling uses platform-specific implementations (`termios`/`tty` on
Unix, `msvcrt` with Windows Console API on Windows), providing full TTY functionality
including `colab console` interactive shells. Tested on Windows 11 with Python 3.13. (#XX)
- **Windows Quick Start:** Added `QUICK_START_WINDOWS.md` with Windows-specific
installation and usage examples.

### Changed

- **console.py:** Refactored terminal handling to be cross-platform with conditional
imports and a `WindowsConsoleMode` context manager for raw terminal mode on Windows.
- **README.md:** Updated platform support notice to include Windows.

## [0.6.0] - 2026-06-16

### Changed
Expand Down
241 changes: 241 additions & 0 deletions QUICK_START_WINDOWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
# Quick Start: Google Colab CLI on Windows

## Native Windows Support ✅

The Google Colab CLI now **works natively on Windows** — no WSL or Docker required.

Native Windows support is tested and supported on **Python 3.11+**. The CI matrix
currently covers Windows on Python 3.11 and 3.13. Python 3.10 and older are not
supported for native Windows console mode; `colab console` exits with a fallback
message before changing console settings.

If native Windows console support is unavailable, for example because Python is
older than 3.11 or stdin/stdout is not attached to a real console, `colab console`
prints a clear fallback message that links back to this guide. In that case:

1. Upgrade to Python 3.11 or newer.
2. Run from Windows Terminal, PowerShell, or CMD rather than a detached/no-console process.
3. Retry the command, or use WSL as a fallback if your environment cannot expose a Windows console.

## Installation

### Option 1: pip (Recommended for Windows)

```powershell
pip install google-colab-cli
```

### Option 2: uv

```powershell
uv tool install google-colab-cli
```

> **Note:** If `uv tool install` opens GUI windows instead of running in terminal, use `pip install` instead.

### Verify Installation

```powershell
colab version
```

If you see the version number, you're ready! 🎉

## Quick Examples

### Example 1: Hello World

```powershell
colab new
echo "print('Hello from Colab!')" | colab exec
colab stop
```

### Example 2: GPU Training

```powershell
colab new -s training --gpu T4
colab install -s training torch torchvision
colab exec -s training -f train.py
colab download -s training /content/model.pth .\model.pth
colab stop -s training
```

### Example 3: One-Shot GPU Job

```powershell
colab run --gpu T4 experiment.py
```

### Example 4: Run a Notebook Directly

```powershell
colab run --gpu T4 --keep .\Viral_Shorts_Generator.ipynb
```

While developing from this repository, use `uv run colab` so PowerShell runs the local patched CLI:

```powershell
cd "C:\Users\Pc\OneDrive\Desktop\Colab Cli\google-colab-cli"
uv run colab run --gpu T4 --keep "..\long-video-to-shorts-maker\Viral_Shorts_Generator.ipynb"
```

Notebook code cells run in order, output streams back to the terminal, and an output notebook is saved beside the input as `<name>_output.ipynb`.

### Example 5: Interactive REPL

```powershell
colab new --gpu L4
colab repl
```

```python
>>> import torch
>>> torch.cuda.is_available()
True
>>> torch.cuda.get_device_name(0)
'NVIDIA L4'
```

### Example 6: Interactive Console

```powershell
colab new
colab console
```

Full TTY shell with tmux — works natively in Windows Terminal, PowerShell, or CMD.

### Manual Console Restore Check

To verify Ctrl-C or an exception does not leave your terminal in raw mode:

```powershell
colab new -s console-check
colab console -s console-check
```

Press `Ctrl-C` while the console is active, then run:

```powershell
Write-Host "typed input should echo normally"
colab stop -s console-check
```

If typed characters echo normally and Enter submits commands as usual, the
Windows console mode was restored correctly.

## Available Hardware

### Free GPUs
- **T4** - Development and small models

### Premium GPUs (Colab subscription)
- **L4** - Cost-effective inference
- **G4** - Balanced performance
- **A100** - High-performance training
- **H100** - State-of-the-art

### TPUs (Colab subscription)
- **v5e1**, **v6e1**

```powershell
colab new --gpu A100
colab new --tpu v5e1
```

## File Operations

```powershell
colab ls /content
colab upload .\data.csv /content/data.csv
colab download /content/results.csv .\results.csv
colab edit /content/script.py
colab rm /content/old_file.txt
```

## Session Management

```powershell
colab sessions # List all active sessions
colab status -s training # Check session status
colab restart-kernel -s training # Restart kernel
colab url --open # Open in browser
colab stop -s training # Terminate session
```

## Google Drive & Authentication

```powershell
colab drivemount # Mount Google Drive
colab auth # Authenticate for GCP services
```

## Export Logs

```powershell
colab log -o history.ipynb # Jupyter notebook
colab log -o history.md # Markdown
colab log -o history.jsonl # JSON Lines
```

## Tips

1. **Single session**: When only one session is active, omit `-s name`:
```powershell
colab exec -f script.py
```

2. **Pipe input**: Works in PowerShell and CMD:
```powershell
type script.py | colab exec
echo "import sys; print(sys.version)" | colab exec
```

3. **Automatic keep-alive**: Sessions stay active in the background automatically. Long `run` and `exec` commands also pulse keep-alive while the foreground command is still running.

4. **Update CLI**:
```powershell
colab update --install
```

## Troubleshooting

### Command not found

Ensure Python Scripts directory is in PATH:
```powershell
# Add to PATH (PowerShell as Admin)
$env:Path += ";$env:LOCALAPPDATA\Programs\Python\Python312\Scripts"
```

Or use module invocation:
```powershell
python -m colab_cli.cli version
```

### GUI window opens instead of terminal

This happens with `uv tool install`. Solution:
1. Uninstall: `uv tool uninstall google-colab-cli`
2. Reinstall: `pip install google-colab-cli`

### Console appears stuck or does not close

Run `colab console` from Windows Terminal, PowerShell, or CMD with Python 3.11 or
newer. The console uses non-blocking keyboard polling and websocket heartbeats,
so Ctrl-C or a broken connection should restore the terminal automatically. If
your terminal still does not echo input after exit, close that terminal tab,
open a new one, and run the manual restore check above before filing a bug with
your Windows version, terminal app, Python version, and the exact command used.

## Next Steps

- [Main README](README.md) - Full documentation
- [Demo Walkthroughs](docs/demos.md) - Real-world examples
- [Session Management](docs/01_session_management.md) - Architecture deep-dive

---

Native Windows support tested on Windows 11 with Python 3.11 and 3.13,
PowerShell, CMD, and Windows Terminal. 🚀
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Designed to support seamless developer productivity, headless automation, and AI
[Demo](https://github.com/user-attachments/assets/656226a9-af13-4fdb-8eda-d7de747336a2)

> [!NOTE]
> **Platform support:** the Colab CLI currently supports **Linux and macOS** only. Windows is not supported at this time.
> **Platform support:** the Colab CLI supports **Linux, macOS, and Windows**. Native Windows terminal support is tested on Python 3.11+ — no WSL required. See [Windows Quick Start](QUICK_START_WINDOWS.md) if Windows console support is unavailable.

> [!TIP]
> Looking for in-notebook, interactive agent-assisted coding instead of a terminal workflow? See the [Colab MCP Server](https://github.com/googlecolab/colab-mcp).
Expand All @@ -18,7 +18,7 @@ Designed to support seamless developer productivity, headless automation, and AI

* **Instant VM Provisioning:** Spin up CPU, GPU (T4, L4, G4, H100, A100), or TPU (v5e1, v6e1) runtimes in seconds.
* **Robust Code Execution:** Run local Python scripts, Jupyter Notebooks (`.ipynb`), or piped `stdin` code; launch interactive REPLs or raw TTY console shells.
* **Ephemeral Job Runner (`colab run`):** Provision a fresh VM, execute a local script with forwarded arguments, retrieve output files, and automatically tear down the runtime in a single command.
* **Ephemeral Job Runner (`colab run`):** Provision a fresh VM, execute a local script or notebook, retrieve output files, and automatically tear down the runtime in a single command.
* **Automatic Keep-Alive:** Built-in background daemon automatically prevents idle VM termination, keeping resource allocations active without requiring open browser tabs.
* **Seamless Workspace Automation:** Mount Google Drive, authenticate Google Cloud Platform (GCP) credentials, and install dependencies with high-performance `uv` package management.
* **State & Log Archival:** Inspect local session states or export interactive history logs to standard Jupyter Notebooks, Markdown, or structured JSONL.
Expand All @@ -37,6 +37,9 @@ uv tool install google-colab-cli
pip install google-colab-cli
```

> [!TIP]
> **Windows users:** If you encounter issues with `uv tool install` opening GUI windows, use `pip install` instead or create a wrapper batch file. See [Windows Quick Start](QUICK_START_WINDOWS.md) for details.

---

## Quick Start
Expand Down Expand Up @@ -78,7 +81,7 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
### Execution
| Command | Description |
| --- | --- |
| `colab run [--gpu GPU] [--tpu TPU] [--keep] SCRIPT [ARGS...]` | Run a local script on a fresh VM, forwarding arguments, then release it |
| `colab run [--gpu GPU] [--tpu TPU] [--keep] FILE [ARGS...]` | Run a local `.py` script or `.ipynb` notebook on a fresh VM, then release it |
| `colab exec [-s NAME] [-f FILE] [--output-image PATH]` | Execute Python code from stdin, a local `.py` file, or a `.ipynb` notebook |
| `colab repl [-s NAME] [--output-image PATH]` | Start an interactive Python REPL on the VM (exits cleanly on piped EOF) |
| `colab console [-s NAME]` | Connect to a raw interactive TTY shell (tmux) on the remote VM |
Expand Down Expand Up @@ -148,11 +151,14 @@ colab stop -s analysis

### Ephemeral Accelerator Jobs

Use `colab run` to run a local script on dedicated hardware without manual session lifecycle management. The CLI handles provisioning, script execution, and immediate VM teardown automatically:
Use `colab run` to run a local script or notebook on dedicated hardware without manual session lifecycle management. The CLI handles provisioning, execution, foreground keep-alive, and immediate VM teardown automatically:

```bash
# Run train.py on a T4 GPU and release the VM on completion
colab run --gpu T4 train.py

# Run a notebook cell-by-cell and write report_output.ipynb
colab run --gpu T4 --keep report.ipynb
```

### Shebang Execution Support
Expand Down
4 changes: 3 additions & 1 deletion docs/02_execution_and_interactive.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ log:
2026-05-07: Fixed `print_kitty` (used by `colab exec --output-image` and any image-producing exec) to no-op when `sys.stdout.isatty()` is false. The Kitty Graphics Protocol escape sequence is meaningless when stdout is a file or pipe and was visually corrupting captured output (a multi-KB base64 PNG blob would land in log files, grep targets, or showboat captures). Image bytes are still saved to disk via `handle_image`'s file-write path; only the inline-render attempt is suppressed.

2026-06-04: Bumped the default `--timeout` for `colab exec` from 10s to 30s (and the matching `colab run` default) so brief silent tasks are less likely to hit a premature `TimeoutError`. Explicit `--timeout` overrides are unaffected.

2026-07-27: Changed the default execution timeout for `colab exec` and `colab run` to unlimited (`None`). Long-running cells such as downloads, video rendering, model loading, and transcription should not be killed merely because they are quiet. Users can still pass `--timeout SECONDS` when they want a hard per-request limit.
---

# Design: Execution and Interactive Interaction (`repl`, `exec`, `console`)
Expand All @@ -28,7 +30,7 @@ Execution involves sending Python code (or shell commands) to the Jupyter kernel
- If file path is local: Read content, send as code.
- If file path is remote: Execute `!python <path>`.
- **Multi-Modal Output**: Handle `display_data` messages (e.g., `image/png`, `text/html`). For the CLI, we'll save images to temporary files and print their paths, or if the terminal supports it (e.g., iTerm2), inline them.
- **Timeout Configuration**: Exposes a `--timeout` flag (default 30s) to allow long-running silent tasks (like model compilation or data downloading) to execute without being prematurely killed.
- **Timeout Configuration**: Exposes a `--timeout` flag (default unlimited) for callers that want a hard per-request limit. By default, long-running silent tasks such as model compilation, data downloading, transcription, or video rendering are allowed to keep running.

### 3. Console (`colab console`)
- **Implementation**: Connects directly to the backend terminal endpoint (`/colab/tty`) via WebSockets using `websocket-client`.
Expand Down
Loading
Loading