Skip to main content

Dual-rendering for Jupyter notebook outputs — rich visuals for humans, structured data for AI agents

Project description

nbaide

PyPI Tests Python License

The agent-readability standard for Jupyter notebooks. Ruff makes your code clean — nbaide makes your notebooks intelligent.

AI coding agents (Claude Code, Cursor, Codex) struggle with Jupyter notebooks because outputs are stored as HTML tables, base64 images, and opaque blobs. nbaide solves this with three layers:

  1. Formatters — embed structured JSON in notebook outputs so agents can read them. Humans see exactly what they've always seen.
  2. CLInbaide manifest, nbaide read, and nbaide lint give agents structured access to any notebook.
  3. Linter — score notebooks 0-100 for agent readability and auto-fix common issues.

Quick Start

pip install nbaide
import nbaide
nbaide.install()  # one line — all displays are now dual-rendered

import pandas as pd
df = pd.read_csv("data.csv")
df  # humans see the HTML table; agents see structured JSON with schema + stats

Lint Your Notebooks

$ nbaide lint notebook.ipynb

notebook.ipynb

  cell  1: AIR001 Output size 292KB exceeds 256KB
  cell  3: AIR003 Error output: ZeroDivisionError
  cell  5: AIM001 Chart missing title
  notebook: AIN003 No nbaide.install() call found

  4 issue(s) (1 error, 2 warning, 1 info)
  Agent readability score: 64/100 (Fair)

$ nbaide lint notebook.ipynb --fix

  Fixed:
    [AIR001] cell 1: Auto-fixed
    [AIR003] cell 3: Auto-fixed
    [AIN003] notebook: Auto-fixed

  cell  5: AIM001 Chart missing title

  1 issue(s) (0 error, 1 warning, 0 info)
  Agent readability score: 95/100 (Excellent)

Lint Rules

Code Severity Rule Auto-fix
AIR001 error Output >256KB Summarize: keep metadata, strip bloat
AIR002 warning Output >100KB Summarize: keep metadata, strip bloat
AIR003 warning Error/traceback output Strip traceback
AIR004 info Stream noise >5KB (progress bars, logging) Strip stream output
AIR005 info Redundant base64 image (nbaide metadata present) Strip image, keep metadata
AID001 warning DataFrame >40 columns -
AIM001 warning Chart missing title -
AIN001 info No markdown headings Add heading from filename
AIN002 warning Code cells not executed -
AIN003 info No nbaide.install() call Inject install cell

Pre-commit Hook

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/igerber/nbaide
    rev: v0.2.0
    hooks:
      - id: nbaide-lint
        args: [--check, --min, "70"]

Blocks commits if any .ipynb file scores below the threshold.

CI Integration

# Fail CI if agent readability score drops below 80
nbaide lint notebook.ipynb --check --min 80

What Agents See

When an agent reads a notebook with nbaide installed, each output includes structured JSON:

---nbaide---
{"type": "dataframe", "shape": [200, 9], "columns": [{"name": "price", "dtype": "float64", "nulls": 10, "stats": {"mean": 151.97, "min": 8.58, "max": 299.91}}, ...], "sample_rows": [...]}

For charts, agents get chart type, axis labels, trend detection, and sampled data:

---nbaide---
{"type": "figure", "axes": [{"title": "Monthly Revenue", "series": [{"plot_type": "line", "data_points": 12, "trend": {"direction": "increasing", "slope": 2280.0, "r_squared": 0.97}}]}]}

Humans see exactly what they've always seen. The structured JSON is invisible in Jupyter (HTML takes priority over text/plain).

Supported Types

Type What agents get
pandas DataFrame Schema, column types, null counts, per-column stats, sample rows
matplotlib Figure Chart type (line/scatter/bar/histogram/heatmap), axis labels, trend detection (direction + slope + R2), adaptive data sampling
numpy ndarray Shape, dtype, global stats, per-column stats for 2D, adaptive data
plotly Figure Trace types, layout metadata, trend detection, categories/values. Interactive charts preserved.
Custom types Register your own with nbaide.register()

Custom Type Registration

import nbaide

def format_experiment(exp):
    return {
        "type": "experiment",
        "name": exp.name,
        "params": exp.params,
        "metrics": exp.metrics,
    }

nbaide.register(Experiment, format_experiment)

Works even after install() has been called (late registration).

CLI Tools

# Structured summary of an entire notebook
nbaide manifest notebook.ipynb

# Extract structured data from all cell outputs
nbaide read notebook.ipynb

# Get data for a specific cell
nbaide read notebook.ipynb --cell 7

# Filter by type
nbaide read notebook.ipynb --type dataframe

# Lint for agent readability
nbaide lint notebook.ipynb
nbaide lint notebook.ipynb --fix
nbaide lint notebook.ipynb --check --min 80
nbaide lint notebook.ipynb --json

Installation

# Core (pandas + numpy)
pip install nbaide

# With matplotlib support
pip install nbaide[matplotlib]

# With plotly support
pip install nbaide[plotly]

# Everything
pip install nbaide[all]

How It Works

Jupyter stores multiple MIME representations per output. The frontend picks the richest one (HTML, PNG) for display, but text/plain is also stored. nbaide embeds structured JSON in text/plain — invisible to humans in Jupyter, but readable by any agent that opens the .ipynb file.

The linter statically analyzes .ipynb files for agent-hostile patterns (oversized outputs, missing metadata, error tracebacks) and can auto-fix most issues without a running kernel.

Status

v0.2.0 — 253 tests. The agent-readability standard for Jupyter notebooks.

  • Formatters: pandas, matplotlib, numpy, plotly, custom types via plugin system
  • CLI: manifest, read, lint with scoring, rules, and auto-fix
  • Linter: 10 rules, 0-100 scoring, CI integration via --check
  • See CLAUDE.md for the full roadmap and technical design

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

nbaide-0.3.0.tar.gz (47.0 kB view details)

Uploaded Source

Built Distribution

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

nbaide-0.3.0-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file nbaide-0.3.0.tar.gz.

File metadata

  • Download URL: nbaide-0.3.0.tar.gz
  • Upload date:
  • Size: 47.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nbaide-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c02da76434d6ca0e26d180fe00580380879160e9258a35e9586d560ba383d24e
MD5 f2785624f6696427430fb13f7b14ae49
BLAKE2b-256 d7f00db1180d3d55c321583d702bc4062cd6b623aff7ae8a5d93ae550aaacbdb

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbaide-0.3.0.tar.gz:

Publisher: publish.yml on igerber/nbaide

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nbaide-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: nbaide-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 33.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nbaide-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 970bb9f164159b141a8124ff08d063ab65686025f5da479b5e446a66d89934c6
MD5 cd221aa0392ea43b8ad812e439090d9e
BLAKE2b-256 4679bdb6f5ffbf4cb1f0a6aec05bf87a9fcdcfc6be6324c735e9e5d55cd0f993

See more details on using hashes here.

Provenance

The following attestation bundles were made for nbaide-0.3.0-py3-none-any.whl:

Publisher: publish.yml on igerber/nbaide

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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