Skip to main content

CLI tool for executing Quarto cells through a Jupyter kernel

Project description

qkernel

A CLI tool for executing Quarto (.qmd) code cells through a Jupyter kernel.

Features

  • Execute Quarto cells from the command line with live output
  • Persistent kernel sessions - start a kernel once, run cells across multiple invocations
  • Automatic virtual environment detection - uses .venv in your project automatically
  • Cell selection - run specific cells by index or label
  • Image saving - automatically saves generated images to cache directory
  • Animated progress - shows live spinner and timing for each cell

Installation

With uv (recommended)

uv tool install qkernel

With pip

pip install qkernel

Requirements

  • Python 3.10+
  • ipykernel must be installed in the target Python environment

Usage

Running Cells

# Run all cells in a file
qkernel run notebook.qmd

# Run specific cells by index (0-based)
qkernel run notebook.qmd --cells 0,2,5

# Run specific cells by label
qkernel run notebook.qmd --cells setup,analysis,plot

# Mix indices and labels
qkernel run notebook.qmd --cells 0,setup,2

# Set execution timeout (in seconds)
qkernel run notebook.qmd --timeout 600

Persistent Kernel Sessions

For faster iteration, start a kernel that persists across runs:

# Start a background kernel
qkernel start

# Run cells (uses the persistent kernel)
qkernel run notebook.qmd --cells setup
qkernel run notebook.qmd --cells analysis  # Variables from setup are available

# Check kernel status
qkernel status

# Restart the kernel (clears state)
qkernel restart

# Stop the kernel when done
qkernel stop

Verbose Mode

Enable debug logging with -v:

qkernel -v run notebook.qmd

Python Environment Resolution

qkernel automatically detects which Python to use for the kernel, following this order:

  1. QUARTO_PYTHON - Environment variable (path to Python executable or venv directory)
  2. VIRTUAL_ENV - Activated virtual environment
  3. .venv - Virtual environment in current directory or any parent directory
  4. System Python - Fallback

This means if you have a .venv in your project root, qkernel will use it automatically even when running from a subdirectory.

# Explicit Python
QUARTO_PYTHON=/path/to/python qkernel run notebook.qmd

# Uses activated venv
source .venv/bin/activate
qkernel run notebook.qmd

# Auto-detects .venv in project
cd /project/src/deep/folder
qkernel run ../../../notebook.qmd  # Uses /project/.venv

Output Format

qkernel shows clean, informative output with timing:

Kernel started (/path/to/python)
● ━━ [0] setup ━━━━━━━━━━━━━━━━━━━━━━━━━━ ✓ 23ms
    Loading data...
    Done!
● ━━ [1] analysis ━━━━━━━━━━━━━━━━━━━━━━━ ✓ 1205ms
    Processing 1000 rows
    Results: [1, 2, 3, 4, 5]
● ━━ [2] plot ━━━━━━━━━━━━━━━━━━━━━━━━━━━ ✓ 89ms
    [Image: ~/.cache/qkernel/notebook/plot/output.png]
Kernel stopped

══════════════════════════════════════════════════
Executed 3 cell(s) • 1 image(s) saved
  → /Users/you/.cache/qkernel/notebook/plot/output.png

In interactive terminals, a spinner animates while cells are running.

Image Caching

Images generated by cells are saved to ~/.cache/qkernel/<filename>/<cell_label>/:

~/.cache/qkernel/
└── notebook/
    ├── plot/
    │   └── output.png
    └── visualization/
        ├── output_0.png
        └── output_1.png

The cache is cleared before each run to ensure fresh output.

Cell Labels

qkernel recognizes cell labels from Quarto's YAML-style comments:

```{python}
#| label: setup
import pandas as pd
data = pd.read_csv("data.csv")
```

```{python}
#| label: analysis
results = data.groupby("category").sum()
print(results)
```

Use these labels to run specific cells: qkernel run file.qmd --cells setup,analysis

Development

# Install with dev dependencies
uv pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Run with timeout
pytest tests/ -v --timeout=60

License

MIT

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

qkernel-0.1.1.tar.gz (115.0 kB view details)

Uploaded Source

Built Distribution

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

qkernel-0.1.1-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file qkernel-0.1.1.tar.gz.

File metadata

  • Download URL: qkernel-0.1.1.tar.gz
  • Upload date:
  • Size: 115.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.3

File hashes

Hashes for qkernel-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b228acca487fe5fc7941762fba0ee81789f35d6c054827d62141ee37699d2534
MD5 be6a3bd3d75993d7daf667516aa0f812
BLAKE2b-256 509b12701c6707add9c93db688dd028ac4ec0e5bf2e96fb226d84c7aa94fa55c

See more details on using hashes here.

File details

Details for the file qkernel-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: qkernel-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.3

File hashes

Hashes for qkernel-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c77f51852a0726ecb4cbdbd6766ea6f717769544d11fde7920c5186bfdfe5d8d
MD5 8c28ffc10df11a6171e367897ab45415
BLAKE2b-256 9c05573d722054c941a0b3df8bc30627ef6ad444cd2c282be1c5383ec6d6e0ed

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