nblean 0.2.0__py3-none-win_amd64.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.
Binary file
@@ -0,0 +1,307 @@
1
+ Metadata-Version: 2.4
2
+ Name: nblean
3
+ Version: 0.2.0
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Environment :: Console
6
+ Classifier: Framework :: Jupyter
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: Intended Audience :: Science/Research
9
+ Classifier: Operating System :: MacOS
10
+ Classifier: Operating System :: Microsoft :: Windows
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Programming Language :: Rust
13
+ Classifier: Topic :: Scientific/Engineering
14
+ Classifier: Topic :: Software Development
15
+ License-File: LICENSE
16
+ Summary: Token-lean Jupyter notebook access for coding agents: outlines, clipped outputs, images as files, a persistent kernel.
17
+ Keywords: jupyter,notebook,ipynb,llm,coding-agent,claude-code,tokens,cli
18
+ Home-Page: https://github.com/kaanrkaraman/nblean
19
+ Author-email: Recep Kaan Karaman <kaanrkaraman@gmail.com>
20
+ License-Expression: MIT
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
23
+ Project-URL: Homepage, https://github.com/kaanrkaraman/nblean
24
+ Project-URL: Issues, https://github.com/kaanrkaraman/nblean/issues
25
+ Project-URL: Repository, https://github.com/kaanrkaraman/nblean
26
+
27
+ <p align="center">
28
+ <strong>nblean</strong><br>
29
+ <strong>Lets coding agents work with Jupyter notebooks without reading every output</strong>
30
+ </p>
31
+
32
+ <p align="center">
33
+ <a href="https://github.com/kaanrkaraman/nblean/actions/workflows/ci.yml"><img src="https://github.com/kaanrkaraman/nblean/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
34
+ <a href="https://pypi.org/project/nblean/"><img src="https://img.shields.io/pypi/v/nblean" alt="PyPI"></a>
35
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT"></a>
36
+ </p>
37
+
38
+ <p align="center">
39
+ <a href="#installation">Install</a> &bull;
40
+ <a href="#quick-start">Quick Start</a> &bull;
41
+ <a href="#commands">Commands</a> &bull;
42
+ <a href="#how-savings-work">Benchmarks</a> &bull;
43
+ <a href="#supported-agents">Agents</a>
44
+ </p>
45
+
46
+ ---
47
+
48
+ An `.ipynb` file holds code plus everything the code printed: DataFrame dumps,
49
+ progress bars, tracebacks, and plots stored as base64 images. An agent that opens one
50
+ reads all of it. To fix one cell, it then runs the whole notebook again and reads the
51
+ result again.
52
+
53
+ nblean is a small CLI and agent skill that lets the agent work one cell at a time. It
54
+ lists the notebook as an outline, opens only the cells asked for, clips their outputs,
55
+ and runs cells in a background kernel that stays alive between commands.
56
+
57
+ ## What nblean Does
58
+
59
+ | Agent needs to | Without nblean | With nblean |
60
+ |---|---|---|
61
+ | See what a notebook contains | Reads the whole JSON, outputs included | `outline`: one line per cell, with an output summary like `→ 14L img ERR KeyError` |
62
+ | Look at a few cells | Writes a one-off `json`/`jq` script | `show 12 15-18`: source, plus outputs clipped to the first and last lines |
63
+ | Find code | Greps JSON-escaped strings | `grep`: matches by cell and line number |
64
+ | Debug | Scrolls through ANSI-colored tracebacks full of library frames | `errors`: only the failing cells, showing your frame and the exception |
65
+ | Edit a cell | Rewrites the JSON, or reads the notebook first | `set` / `add` / `rm`, with the new source passed on stdin |
66
+ | Re-run after a fix | Runs the whole notebook again and reads all the output | `run 12`: runs that cell in a kernel that is still alive, prints only its output, and saves it into the notebook |
67
+ | Check a value | Adds a throwaway `print` cell | `eval 'df.dtypes'`: runs the code in the kernel without changing the notebook |
68
+ | Look at plots | Every plot costs image tokens | Plots are saved as files and only their paths are printed; the agent opens one when it needs to |
69
+
70
+ ## How Savings Work
71
+
72
+ nblean cuts **notebook tokens**, which are only part of an agent's bill. Every session
73
+ also pays for the system prompt, tool definitions, and conversation history. These
74
+ fixed costs come to about 28k tokens per session on Claude Code. Savings grow with the
75
+ size of the notebook and the volume of its outputs.
76
+
77
+ ### A/B test in Claude Code
78
+
79
+ Claude Sonnet ran headless (`claude -p`), two times with the nblean skill and two
80
+ times without it. Token counts
81
+ come from the `usage` that Claude Code reports; costs are what the same usage would
82
+ cost at API prices.
83
+
84
+ | Task | Without nblean | With nblean | Change |
85
+ |---|---:|---:|---:|
86
+ | Answer two questions from the saved outputs of a 7 MB EDA notebook (97 cells, 31 plots) | 236k tokens · $0.207 | 172k tokens · $0.160 | **-27% tokens, -23% cost** |
87
+ | Find and fix a bug in a 124 KB notebook, then re-run it until clean | 183k tokens · $0.153 | 183k tokens · $0.150 | no measurable change |
88
+
89
+ The first version of nblean showed execution counts in the outline, and one run
90
+ reported them as cell indices. The numbers above come from runs after that fix, and
91
+ all of them answered correctly. Every fix run ended with a clean notebook. On the
92
+ small notebook the baseline agent already worked efficiently: it ran `nbconvert` and
93
+ grepped for errors, so nblean had little to remove.
94
+
95
+ ### First look
96
+
97
+ This compares the `outline` output with reading the whole notebook,
98
+ counting text as bytes/4 and images by pixel area. It is an upper bound on what the
99
+ first step saves.
100
+
101
+ | Notebook | Whole notebook | `nblean outline` |
102
+ |---|---:|---:|
103
+ | Flight-data EDA, 97 cells, 31 plots | ~81k | ~1.5k |
104
+ | Data preprocessing | ~58k | ~260 |
105
+ | Kaggle training run | ~29k | ~90 |
106
+
107
+ ## Installation
108
+
109
+ ```bash
110
+ uv tool install nblean # or: pipx install nblean
111
+ nblean --help
112
+ ```
113
+
114
+ You can also run it without installing: `uvx nblean outline nb.ipynb`.
115
+
116
+ nblean is a single Rust binary. The PyPI package ships prebuilt wheels for macOS
117
+ (Apple Silicon and Intel), Linux (x86_64 and aarch64), and Windows (x64), so
118
+ installing it does not pull in any Python dependencies. On other platforms pip builds
119
+ it from source, which needs a Rust toolchain. To build from the repository:
120
+ `cargo install --git https://github.com/kaanrkaraman/nblean`.
121
+
122
+ The kernel runs in the notebook's own environment, not in nblean's. nblean picks the
123
+ nearest `.venv` above the notebook, which needs `ipykernel` installed
124
+ (`uv add --dev ipykernel`). Use `--python PATH` to pick a different interpreter.
125
+
126
+ ## Quick Start
127
+
128
+ ```bash
129
+ # 1. Install the skill for your agent
130
+ nblean init # Claude Code (default)
131
+ nblean init --agent codex # Codex
132
+ nblean init --agent opencode # OpenCode
133
+ nblean init --agent gemini # Gemini CLI
134
+ nblean init --agent all # all of the above
135
+ nblean init --project # into ./ instead of ~/
136
+
137
+ # 2. Ask your agent anything about a notebook
138
+ ```
139
+
140
+ The skill tells the agent to start with `outline` and never to read the `.ipynb`
141
+ directly.
142
+
143
+ ## How It Works
144
+
145
+ ```
146
+ Without nblean: With nblean:
147
+
148
+ agent --read--> nb.ipynb agent --outline/show--> nblean --> nb.ipynb
149
+ ^ | ^ | clip, summarize,
150
+ | every source, | | only requested | images to files
151
+ | output, image | | cells, clipped |
152
+ +-----------------+ +-----------------------+
153
+ agent --run 12--> nblean --> live kernel
154
+ | only this cell's output,
155
+ | saved back into nb.ipynb
156
+ ```
157
+
158
+ The kernel is a detached `ipykernel` process. Each notebook gets its own kernel, and
159
+ each nblean call connects to it, runs code, and disconnects. Variables stay in memory
160
+ between calls until `kernel stop` or `kernel restart`.
161
+
162
+ ## Commands
163
+
164
+ CELL is an index (`12`), a range (`3-7`, `5-`), `all`, or the start of a cell id.
165
+
166
+ ### Read
167
+
168
+ ```bash
169
+ nblean outline nb.ipynb # one line per cell
170
+ nblean show nb.ipynb 12 15-18 # source + clipped outputs
171
+ nblean show nb.ipynb 12 --no-output # source only
172
+ nblean show nb.ipynb 12 --lines 60 # bigger clip; --full disables it
173
+ nblean grep nb.ipynb 'read_csv' # search sources; -o includes outputs
174
+ nblean errors nb.ipynb # failing cells only
175
+ ```
176
+
177
+ ### Edit
178
+
179
+ ```bash
180
+ nblean set nb.ipynb 12 <<'PY' # replace source, clears stale outputs
181
+ df = pd.read_parquet(path)
182
+ PY
183
+ nblean add nb.ipynb --at 13 <<'PY' # insert; --md for markdown
184
+ df.describe()
185
+ PY
186
+ nblean rm nb.ipynb 14 20-22
187
+ ```
188
+
189
+ ### Execute
190
+
191
+ ```bash
192
+ nblean run nb.ipynb 0-12 # run cells, save outputs, stop at first error
193
+ nblean eval nb.ipynb 'df.shape' # scratch code, nothing saved
194
+ nblean kernel nb.ipynb status|stop|restart
195
+ ```
196
+
197
+ ## Examples
198
+
199
+ ```
200
+ $ nblean outline eda.ipynb
201
+ eda.ipynb: 97 cells (36 markdown, 61 code), kernel off
202
+ 0 md 1. Files and Schema +14L
203
+ 1 code import itertools +27L
204
+ 3 code files = pl.DataFrame( +5L → 13L
205
+ 13 code p0 = pl.read_parquet(PARQ / "part.0.parquet") +7L → 1L img
206
+ 15 code fl_min = feat["flight_length"].to_numpy() / 60 +19L → img
207
+ ```
208
+
209
+ A 40-line pandas traceback, cut down to the line that failed:
210
+
211
+ ```
212
+ $ nblean errors buggy.ipynb
213
+ ── 8 code id=cell08 exec=3 ──
214
+ KeyError Traceback (most recent call last)
215
+ Cell In[3], line 1
216
+ ----> 1 df["pressure_kpa"] = df["presure"] * 6.89476
217
+ 2 df.head()
218
+
219
+ … 11 library or chained frames omitted …
220
+ KeyError: 'presure'
221
+ ```
222
+
223
+ A 300-line training log, with a plot that is saved to a file instead of loaded:
224
+
225
+ ```
226
+ $ nblean run buggy.ipynb 3 4 --lines 6
227
+ ── 3 code id=cell03 exec=4 ──
228
+ epoch 000 smoothing pass loss=1.000000 temp_mean=141.845
229
+ epoch 001 smoothing pass loss=0.500000 temp_mean=141.724
230
+ epoch 002 smoothing pass loss=0.333333 temp_mean=141.651
231
+ … 294 lines omitted …
232
+ epoch 297 smoothing pass loss=0.003356 temp_mean=139.027
233
+ epoch 298 smoothing pass loss=0.003344 temp_mean=139.038
234
+ epoch 299 smoothing pass loss=0.003333 temp_mean=139.048
235
+ ── 4 code id=cell04 exec=5 ──
236
+ [image/png → /tmp/nblean/buggy-ec4a859a6390/img/4_0.png]
237
+ ```
238
+
239
+ ## Supported Agents
240
+
241
+ The skill uses the [Agent Skills](https://agentskills.io) `SKILL.md` format, so the
242
+ same file works in every agent below. The CLI works with any agent that can run shell
243
+ commands.
244
+
245
+ | Agent | `nblean init` | Skill location |
246
+ |---|---|---|
247
+ | Claude Code | `--agent claude`, or the plugin below | `~/.claude/skills/nblean` |
248
+ | Codex | `--agent codex` | `~/.agents/skills/nblean` |
249
+ | OpenCode | `--agent opencode` | `~/.agents/skills/nblean` |
250
+ | Gemini CLI | `--agent gemini` | `~/.gemini/skills/nblean` |
251
+ | Others | `npx skills add kaanrkaraman/nblean` | per agent |
252
+
253
+ In Claude Code the skill is also available as a plugin:
254
+
255
+ ```
256
+ /plugin marketplace add kaanrkaraman/nblean
257
+ /plugin install nblean@nblean
258
+ ```
259
+
260
+ nblean ships as a CLI and a skill instead of an MCP server. An MCP server's tool
261
+ definitions are loaded into every session. A skill is loaded only when a notebook
262
+ comes up.
263
+
264
+ ## Speed
265
+
266
+ Version 0.1 was written in Python. Version 0.2 is the same CLI rewritten in Rust,
267
+ and it produces byte-identical output. Startup time dropped from about 90 ms to
268
+ 2 ms per call. Commands that talk to a running kernel dropped from about 345 ms to
269
+ 7 ms.
270
+
271
+ | Command | Python 0.1 | Rust 0.2 |
272
+ |---|---:|---:|
273
+ | `outline` on a 7 MB notebook | 109 ms | 6 ms |
274
+ | `show 0-5` on a 7 MB notebook | 111 ms | 6 ms |
275
+ | `eval` against a running kernel | 346 ms | 7 ms |
276
+ | `run` one cell against a running kernel | 349 ms | 11 ms |
277
+ | starting a kernel | 308 ms | 211 ms |
278
+
279
+ Measured with hyperfine on an Apple Silicon Mac, mean of at least 20 runs. Kernel
280
+ start time is mostly ipykernel's own startup.
281
+
282
+ ## Platform Support
283
+
284
+ macOS, Linux, and Windows. The kernel's Python can be any version that `ipykernel`
285
+ supports.
286
+
287
+ ## Limitations
288
+
289
+ - A cell's outputs are written when the cell finishes. If a long cell is killed, its output is lost.
290
+ - Writes are atomic but not merged. If the notebook is open in Jupyter or VS Code, reload it there after nblean writes.
291
+ - Widgets, `update_display_data`, and `input()` are not supported.
292
+
293
+ ## Contributing
294
+
295
+ ```bash
296
+ cargo test
297
+ cargo clippy --all-targets -- -D warnings
298
+ cargo fmt --check
299
+ ```
300
+
301
+ The kernel test needs a Python with `ipykernel`. Point `NBLEAN_TEST_PYTHON` at it if
302
+ `python3` on your PATH does not have it.
303
+
304
+ ## License
305
+
306
+ [MIT](LICENSE)
307
+
@@ -0,0 +1,6 @@
1
+ nblean-0.2.0.data/scripts/nblean.exe,sha256=YVxPkyDB8h83wz96ILu1CUSN9vzGgO9FSFMHcF8x8JI,3615744
2
+ nblean-0.2.0.dist-info/METADATA,sha256=MZ-_RH8ocHHi9pRheX3cjyPj9nUthtZhyjE8kx3tUh8,12732
3
+ nblean-0.2.0.dist-info/WHEEL,sha256=8Aej0W0a6Cz6apA3IzJrTnxLRVLAt-w0Oh8SA3Con_c,94
4
+ nblean-0.2.0.dist-info/licenses/LICENSE,sha256=VpFR89ITTA-L07BOzI5FeBTjKzNkaXCUQAsn5ZujHGo,1096
5
+ nblean-0.2.0.dist-info/sboms/nblean.cyclonedx.json,sha256=WJUSPcVulReI-DaGgxumuCEMlgkv8nttrRM0QXpRKGE,118994
6
+ nblean-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.15.0)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Recep Kaan Karaman
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.