Metadata-Version: 2.4
Name: nbskill
Version: 0.0.21
Summary: Notebook-aware context, editing, execution, and review for Python agents
Author-email: Konrad <62557233+MorsCerta-crypto@users.noreply.github.com>
License: Apache-2.0
Project-URL: Repository, https://github.com/MorsCerta-crypto/nbskill
Project-URL: Documentation, https://MorsCerta-crypto.github.io/nbskill/
Keywords: nbdev
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: execnb>=0.2.2
Requires-Dist: fastaistyle>=0.0.15
Requires-Dist: fastcore<2.3,>=2.2.31
Requires-Dist: nbdev>=3.3.25
Requires-Dist: pyskills>=0.0.33
Requires-Dist: remold>=0.1.0
Requires-Dist: safepyrun>=0.2.10
Requires-Dist: httpx2>=2.13.1
Dynamic: license-file

# nbskill


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

`nbskill` gives Python agents and maintainers tools to read, edit, run, and review nbdev notebooks by chapter, symbol, or cell ID.

``` python
from pyskills import doc, list_pyskills
from nbskill import skill
from nbskill.foundation import cell_source, parse_cells
from nbskill.graph import notebook_knowledge_graph_data
from nbskill.read import context
```

## Why it exists

`nbskill` validates notebook edits before writing and keeps existing cell IDs stable. Use focused execution and source diffs to check what changed.

## Learn the problem areas

Start with the [Pyskill workflow](https://MorsCerta-crypto.github.io/nbskill/pyskill.html). The source notebooks contain the implementation, examples, and tests for [reading](https://MorsCerta-crypto.github.io/nbskill/read.html), [editing](https://MorsCerta-crypto.github.io/nbskill/edit.html), [execution](https://MorsCerta-crypto.github.io/nbskill/execute.html), and [review](https://MorsCerta-crypto.github.io/nbskill/review.html). The [editing notebook](https://MorsCerta-crypto.github.io/nbskill/edit.html) documents validation, export, and rollback for batch edits.

## Choose a tool

| Need | Public operation |
|----|----|
| Find the relevant chapter or symbol | [`context`](https://MorsCerta-crypto.github.io/nbskill/read.html#context) |
| Route generated Python back to its source notebook | [`generated_owner`](https://MorsCerta-crypto.github.io/nbskill/foundation.html#generated_owner) |
| Make an atomic edit using stable cell IDs | [`edit_notebook`](https://MorsCerta-crypto.github.io/nbskill/edit.html#edit_notebook) |
| Run focused checks in the project environment | [`exec_nb`](https://MorsCerta-crypto.github.io/nbskill/execute.html#exec_nb) |
| Review changed cell source and notebook style | [`diff_nb`](https://MorsCerta-crypto.github.io/nbskill/review.html#diff_nb), [`style_check`](https://MorsCerta-crypto.github.io/nbskill/review.html#style_check) |
| Assess execution evidence after a change | [`notebook_state`](https://MorsCerta-crypto.github.io/nbskill/state.html#notebook_state) |

Load `nbskill.skill` through Pyskills, then read `doc()` for the callable you intend to use. Its signature and parameter documentation are the operation’s contract.

## Parse notebook cells

[`parse_cells`](https://MorsCerta-crypto.github.io/nbskill/parser.html#parse_cells) accepts a compact text format with `%%markdown`, `%%code`, and `---` boundaries. This is useful when proposing several cells without notebook JSON. The result retains the two different cell types:

``` python
cell_text = "\n".join(["%%markdown", "## Demo", "---", "%%code", "value = 42"])
parsed_cells = parse_cells(cell_text)
assert [cell.cell_type for cell in parsed_cells] == ["markdown", "code"]
[(cell.cell_type, cell_source(cell)) for cell in parsed_cells]
```

    [('markdown', '## Demo'), ('code', 'value = 42')]

## Read a notebook

Use [`context`](https://MorsCerta-crypto.github.io/nbskill/read.html#context) to get stable cell addresses. Start with a summary, then select a chapter or symbol for the full source.

``` python
notebook_context = context("nbs/14_pyskill.ipynb", view="summary", verbose=False)
assert notebook_context["selection"]["matches"]
notebook_context
```

## Load the Pyskill

Install `nbskill==0.0.21` from its GitHub release tag in the Python environment used by the agent. With uv, pin both the package version and its release source:

``` toml
[project]
dependencies = ["nbskill==0.0.21"]

[tool.uv.sources]
nbskill = {git = "https://github.com/MorsCerta-crypto/nbskill.git", tag = "0.0.21"}
```

Authenticate private-repository access with `gh auth login` and `gh auth setup-git`, commit `uv.lock`, and install with `uv sync --locked`. For development inside this repository, use `uv sync --locked` and the checks in [DEVELOPMENT.md](DEVELOPMENT.md). The package registers `nbskill.skill` in the `pyskills` entry-point group. Discovery lists its scope without importing every problem area. Inspect the module and then the selected operation:

``` python
assert "nbskill.skill" in list_pyskills()
doc(skill.context)
```

## Use with aai-coding

`aai-coding` owns the persistent session and ordinary Python files. `nbskill.skill` owns notebook source, generated modules, focused execution, and notebook review. [`generated_owner`](https://MorsCerta-crypto.github.io/nbskill/foundation.html#generated_owner) chooses the route for each Python file; a repository marker alone does not make every file generated.

`install_nbskill --target codex` installs the local notebook routing skill. The Python Pyskill works independently of that host-specific installation.

## Trace notebook relationships

The local graph links notebooks, cells, headings, symbols, and imports. Definition and call evidence helps a maintainer find related source before changing a symbol. Similarity edges are hints rather than runtime dependency guarantees. This example displays a small summary of the real source tree. Run it manually because building the graph scans all source notebooks:

``` python
graph = notebook_knowledge_graph_data("nbs")
dict(nodes=len(graph["nodes"]), edges=len(graph["edges"]), node_types=sorted({node["type"] for node in graph["nodes"]}), edge_types=sorted({edge["type"] for edge in graph["edges"]}))
```

## Development

Use the [development guide](DEVELOPMENT.md) for checks and releases, and [WORKFLOW.md](WORKFLOW.md) for the shared branch and review policy.
