Skip to main content

ASTScribe

Evidence-backed scientific explanations for ML notebooks, without LLMs.

PyPI Python CI

ASTScribe statically analyzes Python and Jupyter notebooks and produces deterministic, traceable explanations of supported ML operations in PyTorch, Transformers, Datasets, and PEFT.

No LLMs. No API keys. No execution of analyzed code. No telemetry.

Installation

python -m pip install astscribe

For IPython/Jupyter magics, install the optional extra with python -m pip install "astscribe[ipython]".

Explain inference and training

PyTorch is not required to run this example: the source inside the string is analyzed, never executed.

from astscribe import explain

source = """import torch
model.eval()
with torch.no_grad():
    outputs = model(inputs)
"""
print(explain(source, style="concise"))

Output:

Performs PyTorch inference using evaluation-oriented execution semantics.

A training step can be analyzed in the same way:

training = """model.train()
for batch in train_loader:
    optimizer.zero_grad()
    outputs = model(**batch)
    loss = outputs.loss
    loss.backward()
    optimizer.step()
"""
print(explain(training, style="concise"))

Output:

Performs a PyTorch gradient-based training step with backward propagation and a parameter update.

Use analyze(source) to get structured operations, claims, provenance and inference/training flags, instead of rendered text.

Notebook dependencies

from astscribe import NotebookAnalyzer

notebook = NotebookAnalyzer.from_cells([
    "raw = 10",
    "features = raw * 2",
    "prediction = features + 1",
])
print(notebook.render_dependency_graph())

Output:

# Cell dependency graph

Cell 0 -> Cell 1 [raw]
Cell 1 -> Cell 2 [features]

Find the downstream cells affected by changing an earlier cell:

print(notebook.render_impact_ranking())

Output:

# Notebook impact ranking

- Cell 0: 2 affected cell(s), 1 direct dependent(s).
- Cell 1: 1 affected cell(s), 1 direct dependent(s).
- Cell 2: 0 affected cell(s), 0 direct dependent(s).

Analyze an existing notebook file

This command reads a committed example notebook; it does not execute its cells.

from astscribe import NotebookAnalyzer

report = NotebookAnalyzer.from_ipynb("examples/notebooks/notebook_audit.ipynb")
print(report.cell_count)

Output:

3

Further reports: render_methodology(), render_pipeline(), render_diagnostics(), render_impact(cell), dependency_dot(), and structured to_dict() results. Analyzing a real .ipynb preserves original cell indices, even when Markdown or unsupported cells appear between them.

CLI

printf 'value = 1\n' | astscribe - --style concise

Output (no supported ML operations in this source):

No supported PyTorch semantics were identified in the analyzed source.

Notebook reports are also available from the CLI, such as astscribe experiment.ipynb --report diagnostics --json and astscribe experiment.ipynb --report dependencies --dot. Use --strict to reject unsupported notebook cells, and --fail-on-warning to report dependency warnings with a non-zero exit status. Incompatible report and output options are rejected rather than silently ignored.

Jupyter / IPython

Install astscribe[ipython] and load the extension with %load_ext astscribe.ipython. Then %scribe N concise explains the previous In[N] input using earlier static context, and %%scribe concise explains the current cell without running the body. These magics display the same deterministic text in Markdown form.

Executed notebooks with recorded outputs

All three example notebooks contain real code cells and saved outputs displayed by GitHub's notebook viewer. They analyze code statically, so no ML frameworks, datasets, GPUs or network calls are needed to run them.

Re-run and compare the notebooks against their committed outputs after installing nbclient, nbformat and ipykernel:

python scripts/verify_notebooks.py

Expected terminal output:

Verified 3 executed example notebooks; all stored outputs match.

The verifier fails if any output differs, and runs in CI. To deliberately refresh the recorded outputs, use python scripts/verify_notebooks.py --update.

Scope and limitations

ASTScribe provides evidence-backed semantics for PyTorch, Hugging Face Transformers, Hugging Face Datasets and PEFT. It can infer methodology, experiment pipelines, cross-cell dependencies, diagnostics, impact and composite techniques such as QLoRA. Dynamic effects and hidden Jupyter kernel state are not inferred. See the technical documentation.

Development

python -m pip install -e ".[dev]"
pytest
ruff check .
mypy src/astscribe

Contributions: CONTRIBUTING.md. License: Apache-2.0.

Metadata

Release files for astscribe 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for astscribe 0.9.1
File Size Uploaded
astscribe-0.9.1.tar.gz 83.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for astscribe 0.9.1
File Interpreter ABI Platform
astscribe-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 146.1 kB

Release files / astscribe-0.9.1.tar.gz

Download URL astscribe-0.9.1.tar.gz
Size 83.2 kB
Tags Source
SHA-256 checksum
How to use checksums
950fc7577f431cdb7fead2f1eccf054848f091066d7399bb3803ec69cba5bf86
BLAKE2b-256 checksum
How to use checksums
1efe79d47f4e2970d0ae6cdc2d4f6982c5a9b5288b32f92ba5a565cbaa2837b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release files / astscribe-0.9.1-py3-none-any.whl

Download URL astscribe-0.9.1-py3-none-any.whl
Size 62.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
848a911e06dc13c96c9f74a9f9d01091d36049234eda37ce61325d739ab8421e
BLAKE2b-256 checksum
How to use checksums
c50dd9bb97bb75fcefcc14f5f17b8e2fb1f75e58ce4593b3aefbd6f4bdd201dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

0.9.0

2 release files

0.8.8

2 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page