$npx -y skills add AlexAI-MCP/hermes-CCC --skill jupyter-live-kernelJupyter notebook and kernel operations — start kernels, execute cells programmatically, export, and data analysis patterns.
| 1 | # Jupyter Live Kernel |
| 2 | |
| 3 | Run notebooks, execute cells programmatically, and manage Jupyter kernels. |
| 4 | |
| 5 | ## Setup |
| 6 | |
| 7 | ```bash |
| 8 | pip install jupyter jupyterlab nbformat nbconvert ipykernel |
| 9 | python -m ipykernel install --user --name myenv --display-name "My Env" |
| 10 | ``` |
| 11 | |
| 12 | --- |
| 13 | |
| 14 | ## Start Jupyter |
| 15 | |
| 16 | ```bash |
| 17 | # JupyterLab (recommended) |
| 18 | jupyter lab --no-browser --port 8888 |
| 19 | |
| 20 | # Classic notebook |
| 21 | jupyter notebook --no-browser --port 8888 |
| 22 | |
| 23 | # Allow remote access (careful with security) |
| 24 | jupyter lab --ip 0.0.0.0 --no-browser |
| 25 | |
| 26 | # Start with specific directory |
| 27 | jupyter lab /path/to/project |
| 28 | ``` |
| 29 | |
| 30 | --- |
| 31 | |
| 32 | ## Execute Notebooks Programmatically |
| 33 | |
| 34 | ```bash |
| 35 | # Execute and save output |
| 36 | jupyter nbconvert --to notebook --execute input.ipynb --output output.ipynb |
| 37 | |
| 38 | # With timeout |
| 39 | jupyter nbconvert --to notebook --execute --ExecutePreprocessor.timeout=300 input.ipynb |
| 40 | |
| 41 | # Export to HTML |
| 42 | jupyter nbconvert --to html notebook.ipynb |
| 43 | |
| 44 | # Export to Python script |
| 45 | jupyter nbconvert --to script notebook.ipynb |
| 46 | |
| 47 | # Export to PDF (requires LaTeX) |
| 48 | jupyter nbconvert --to pdf notebook.ipynb |
| 49 | ``` |
| 50 | |
| 51 | --- |
| 52 | |
| 53 | ## Create Notebooks with nbformat |
| 54 | |
| 55 | ```python |
| 56 | import nbformat |
| 57 | |
| 58 | nb = nbformat.v4.new_notebook() |
| 59 | |
| 60 | # Add markdown cell |
| 61 | nb.cells.append(nbformat.v4.new_markdown_cell("# My Analysis")) |
| 62 | |
| 63 | # Add code cell |
| 64 | nb.cells.append(nbformat.v4.new_code_cell(""" |
| 65 | import pandas as pd |
| 66 | import matplotlib.pyplot as plt |
| 67 | |
| 68 | df = pd.read_csv('data.csv') |
| 69 | df.head() |
| 70 | """)) |
| 71 | |
| 72 | # Save |
| 73 | with open("analysis.ipynb", "w") as f: |
| 74 | nbformat.write(nb, f) |
| 75 | ``` |
| 76 | |
| 77 | --- |
| 78 | |
| 79 | ## Execute Cells Programmatically with nbclient |
| 80 | |
| 81 | ```python |
| 82 | import nbformat |
| 83 | from nbclient import NotebookClient |
| 84 | |
| 85 | with open("analysis.ipynb") as f: |
| 86 | nb = nbformat.read(f, as_version=4) |
| 87 | |
| 88 | client = NotebookClient(nb, timeout=600, kernel_name="python3") |
| 89 | client.execute() |
| 90 | |
| 91 | with open("analysis_output.ipynb", "w") as f: |
| 92 | nbformat.write(nb, f) |
| 93 | ``` |
| 94 | |
| 95 | --- |
| 96 | |
| 97 | ## Papermill — Parameterized Notebooks |
| 98 | |
| 99 | ```bash |
| 100 | pip install papermill |
| 101 | |
| 102 | # Run with parameters |
| 103 | papermill input.ipynb output.ipynb -p learning_rate 0.001 -p epochs 10 |
| 104 | |
| 105 | # Pass dict parameter |
| 106 | papermill input.ipynb output.ipynb -y "{'config': {'lr': 0.001}}" |
| 107 | ``` |
| 108 | |
| 109 | Mark parameter cell with tag `parameters` in the notebook. |
| 110 | |
| 111 | --- |
| 112 | |
| 113 | ## Kernel Management |
| 114 | |
| 115 | ```bash |
| 116 | # List running kernels |
| 117 | jupyter kernel list |
| 118 | |
| 119 | # List available kernel specs |
| 120 | jupyter kernelspec list |
| 121 | |
| 122 | # Install a kernel from venv |
| 123 | source myenv/bin/activate |
| 124 | pip install ipykernel |
| 125 | python -m ipykernel install --user --name myenv |
| 126 | |
| 127 | # Remove kernel |
| 128 | jupyter kernelspec remove myenv |
| 129 | ``` |
| 130 | |
| 131 | --- |
| 132 | |
| 133 | ## Magic Commands (in notebooks) |
| 134 | |
| 135 | ```python |
| 136 | # Time a single line |
| 137 | %timeit [i**2 for i in range(1000)] |
| 138 | |
| 139 | # Time a cell |
| 140 | %%timeit |
| 141 | result = [i**2 for i in range(1000)] |
| 142 | |
| 143 | # Run shell command |
| 144 | !pip install pandas |
| 145 | !ls -la |
| 146 | |
| 147 | # Show matplotlib inline |
| 148 | %matplotlib inline |
| 149 | |
| 150 | # Load external script |
| 151 | %load script.py |
| 152 | |
| 153 | # Auto-reload modules |
| 154 | %load_ext autoreload |
| 155 | %autoreload 2 |
| 156 | |
| 157 | # Run bash cell |
| 158 | %%bash |
| 159 | echo "Hello from bash" |
| 160 | ls |
| 161 | ``` |
| 162 | |
| 163 | --- |
| 164 | |
| 165 | ## Common Data Analysis Pattern |
| 166 | |
| 167 | ```python |
| 168 | import pandas as pd |
| 169 | import matplotlib.pyplot as plt |
| 170 | import numpy as np |
| 171 | |
| 172 | # Load data |
| 173 | df = pd.read_csv("data.csv") |
| 174 | |
| 175 | # Quick overview |
| 176 | print(df.shape) |
| 177 | df.info() |
| 178 | df.describe() |
| 179 | df.isnull().sum() |
| 180 | |
| 181 | # Plot |
| 182 | fig, axes = plt.subplots(1, 2, figsize=(12, 4)) |
| 183 | df["column"].hist(ax=axes[0]) |
| 184 | df.plot.scatter(x="col1", y="col2", ax=axes[1]) |
| 185 | plt.tight_layout() |
| 186 | plt.savefig("plot.png", dpi=150) |
| 187 | plt.show() |
| 188 | ``` |
| 189 | |
| 190 | --- |
| 191 | |
| 192 | ## VS Code Integration |
| 193 | |
| 194 | - Install "Jupyter" extension |
| 195 | - Open `.ipynb` files directly |
| 196 | - Select kernel from top-right dropdown |
| 197 | - Run cells with `Shift+Enter` |
| 198 | - Variables panel: View → Variables |