Skip to main content

Agent Jupyter Toolkit

A Python toolkit for building agent tools that interact with Jupyter kernels and the Jupyter protocol. This package provides high-level wrappers and abstractions around jupyter_client, jupyter_ydoc, and pycrdt, making it easy to manage kernels, execute code, and build agent-driven workflows for automation, orchestration, and integration with Model Context Protocol (MCP) servers.

Features

Kernel

  • Async-first kernel sessions with pluggable transports:
    • Local transport — direct ZMQ communication with local kernel processes
    • Server transport — HTTP REST + WebSocket to remote Jupyter servers
  • Code execution with bounded, coalesced streaming callbacks and separate callback diagnostics
  • Notebook-compatible output state for deferred clears, display updates, stream coalescing, and bounded output
  • Kernel introspection — tab-completion, object inspection, code-completeness checks, and execution history retrieval
  • Kernel control — interrupt/restart, query metadata, and capability-gated debugger and subshell workflows
  • Ownership-aware lifecycle — normal shutdown preserves attached/borrowed kernels
  • Variable management — inspect and set strict JSON values through base64-encoded payloads
  • Extensible hooks — pre/post execution and output hooks for instrumentation

Notebook

  • Multi-notebook workspaces: NotebookWorkspace manages open sessions and a default notebook from Python. Switching defaults preserves other live sessions. See the workspace API.
  • Multiple notebook transports:
    • Local file transport — filesystem-backed notebooks with thread-safe read/write
    • Contents API transport — Jupyter Server-managed notebooks via REST
    • Collaboration transport — real-time multi-client editing via Yjs/CRDT (pycrdt + jupyter_ydoc)
  • Cell operations — append, insert, delete, set source, update outputs (full replace and delta)
  • In-memory notebook buffer for staged edits with explicit commit
  • Local notebook autosave with optional debounced writes
  • Change observers — register callbacks for cell mutations, saves, and awareness events
  • Validated persistence with atomic stable-cell identity, explicit normalization, and source/persistence conflicts
  • Optional batch execution and trust inspection through public nbclient/nbformat APIs

Use Cases

  • Build agent tools that execute code in Jupyter kernels
  • Integrate Jupyter kernel execution into MCP servers or other orchestration systems
  • Automate notebook and code execution for data science, ML, and automation pipelines
  • Build collaborative notebook editing experiences with CRDT-based conflict resolution

Installation

Install from PyPI

# Using pip
pip install agent-jupyter-toolkit

# Install optional DataFrame serialization support
pip install agent-jupyter-toolkit[dataframe]

# Include named actions and exportable input schemas (no MCP dependency)
pip install "agent-jupyter-toolkit[actions]"

# Include a managed local Python kernel
pip install agent-jupyter-toolkit[local]

# Include the nbclient batch executor
pip install agent-jupyter-toolkit[batch]

# Or using uv
uv pip install agent-jupyter-toolkit

The local extra installs ipykernel, batch installs nbclient, and dataframe installs pandas/Arrow serialization support. The integration extra is for maintainers running the real Jupyter Server and collaboration tests.

Named actions without MCP

The optional actions extra provides NotebookActions, the same implementations used by the corresponding notebook MCP tools. An application can inspect action descriptions/input schemas and invoke a selected action directly:

from agent_jupyter_toolkit.actions import NotebookActions
from agent_jupyter_toolkit.notebook import NotebookWorkspace

async def investigate():
    async with NotebookWorkspace() as workspace:
        actions = NotebookActions(workspace)
        definitions = actions.definitions()
        await actions.invoke("open", {"notebook_path": "investigation.ipynb"})
        await actions.invoke("code_run", {"code": "value = 21"})
        result = await actions.invoke("code_run", {"code": "print(value * 2)"})
        return result

The explicit action set covers lifecycle, stable-ID document reads/edits, visible code/markdown, packages/dependencies, kernel introspection and JSON variables. invoke rejects unknown actions and validates typed inputs without coercion or automatic retries. Named Python methods remain available for direct integrations. Calls share the workspace's existing sessions; they do not create a new workspace context per action. The embedding application owns authorization, concurrency, deadlines and retention. Saved notebooks do not restore live Python variables. The action layer does not add dataset export or DataFrame serialization to the existing JSON variable getter.

Development (monorepo)

git clone https://github.com/Cyb3rWard0g/agent-jupyter-toolkit.git
cd agent-jupyter-toolkit
uv sync --all-packages --all-extras --dev

This installs both agent-jupyter-toolkit and mcp-jupyter-notebook in editable mode into the .venv.

Quickstart

Local kernel execution does not require a Jupyter Server. The library starts a local kernel process for you (via jupyter_client) and connects over ZMQ.

Basic execution

import asyncio
from agent_jupyter_toolkit.kernel import SessionConfig, create_session


async def main() -> None:
    async with create_session(SessionConfig(mode="local", kernel_name="python3")) as session:
        result = await session.execute(
            "import os\n"
            "from platform import node\n"
            "user = os.environ.get('USER', 'friend')\n"
            "print(f'Hello {user} from {node()}')\n"
        )
    print("status:", result.status)
    print("stdout:", result.stdout.strip())


asyncio.run(main())

Introspection and control

async with create_session() as session:
    # Tab-completion
    result = await session.complete("import os; os.path.jo", cursor_pos=21)
    print(result.matches)  # ["join"]

    # Object inspection
    info = await session.inspect("len", cursor_pos=3)
    print(info.data.get("text/plain", ""))

    # Code-completeness check
    check = await session.is_complete("for i in range(10):")
    print(check.status)  # "incomplete"
    print(check.indent)  # "    "

    # Execution history
    hist = await session.history(n=5)
    for entry in hist.history:
        print(f"[{entry.line_number}] {entry.input}")

    # Kernel metadata
    kinfo = await session.kernel_info()
    print(f"{kinfo.language_info['name']} {kinfo.language_info['version']}")

    # Interrupt a long-running cell
    import asyncio

    task = asyncio.create_task(session.execute("import time; time.sleep(999)"))
    await asyncio.sleep(1)
    await session.interrupt()

For server-backed and notebook scenarios, see the quickstarts/ directory.

API Overview

Kernel Session

Method Description
execute(code, *, timeout, output_callback, ...) Execute code with optional streaming callbacks
debug(request) Send a DAP request when the kernel advertises debugger support
create_subshell() / list_subshells() / delete_subshell() Manage advertised kernel subshells
interrupt() Send SIGINT to cancel running execution
complete(code, cursor_pos) Tab-completion suggestions
inspect(code, cursor_pos, detail_level) Object documentation/signature
is_complete(code) Syntax completeness check
history(*, output, raw, hist_access_type, n) Execution history retrieval
kernel_info() Kernel metadata (language, version, protocol)
session_info() Non-secret kernel/session IDs, ownership, generation, and encryption state
is_alive() Health check
start() / shutdown() Start and close; shutdown terminates only resources created by this client
shutdown_kernel() Explicitly terminate a kernel, including a borrowed one

Notebook Document Transport

Method Description
fetch() Get notebook content as nbformat dict
save(content) Write notebook content
append_code_cell(source, metadata, tags) Append a code cell
append_code_cell_with_id(source, metadata, tags) Append and return its stable ID atomically
insert_code_cell(index, source, metadata, tags) Insert a code cell at index
append_markdown_cell(source, tags) Append a markdown cell
insert_markdown_cell(index, source, tags) Insert a markdown cell at index
set_cell_source(index, source) Update cell source text
set_cell_source_by_id(id, source, expected_source) Resolve, verify, and update source atomically
update_cell_outputs(index, outputs, execution_count) Replace cell outputs
delete_cell(index) Delete cell at index
on_change(callback) Register mutation observer

Architecture

agent_jupyter_toolkit
├── kernel/
│   ├── session.py          # Session + create_session() factory
│   ├── transport.py        # KernelTransport protocol
│   ├── types.py            # Dataclasses (SessionConfig, ExecutionResult, ...)
│   ├── manager.py          # KernelManager (lifecycle, channels)
│   ├── messages.py         # Wire-protocol message builders
│   ├── variables.py        # VariableManager (inspect/set kernel vars)
│   ├── hooks.py            # Extensible execution hooks
│   ├── mimetypes.py        # MIME-type serialization registry
│   ├── serialization.py    # High-level serialize/deserialize API
│   └── transports/
│       ├── local.py        # LocalTransport (ZMQ)
│       └── server.py       # ServerTransport (HTTP+WS)
├── notebook/
│   ├── session.py          # NotebookSession (kernel + document orchestration)
│   ├── workspace.py        # Multi-notebook registry, default selection, lifecycle
│   ├── _workspace_files.py # Private local and Contents API file operations
│   ├── transport.py        # NotebookDocumentTransport protocol
│   ├── factory.py          # make_document_transport() factory
│   ├── buffer.py           # In-memory NotebookBuffer
│   ├── cells.py            # Cell creation helpers (code, markdown)
│   ├── config.py           # Environment-based Config (allowlist, timeout)
│   ├── utils.py            # Path validation, output normalization
│   └── transports/
│       ├── local_file.py   # LocalFileDocumentTransport (+ autosave)
│       ├── contents.py     # ContentsApiDocumentTransport
│       └── collab/         # CollabYjsDocumentTransport (Yjs/CRDT)
└── utils/                  # High-level helpers (factories, execution, packages)

Dependencies

Package Purpose
jupyter-client Kernel protocol, ZMQ channels, kernel management
jupyter-ydoc YNotebook schema for collaborative editing
pycrdt CRDT types (Doc, Array, Map, Text, Awareness)
nbformat Notebook file format handling
packaging PEP 508 requirement and version checks
aiohttp Async HTTP/WS for server transport
pandas + pyarrow Optional dataframe extra for DataFrame variable inspection

See the API reference for execution result fields and optional APIs, and configuration for collaboration modes and local launch options.

Contributing

See CONTRIBUTING.md for dev setup, testing, and the release process.


Contributions and feedback are welcome!

Metadata

Release files for agent-jupyter-toolkit 0.10.0

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

Source distribution (sdist)

Source distribution for agent-jupyter-toolkit 0.10.0
File Size Uploaded Provenance
agent_jupyter_toolkit-0.10.0.tar.gz 141.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for agent-jupyter-toolkit 0.10.0
File Interpreter ABI Platform
agent_jupyter_toolkit-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 284.6 kB

Release files / agent_jupyter_toolkit-0.10.0.tar.gz

Download URL agent_jupyter_toolkit-0.10.0.tar.gz
Size 141.6 kB
Tags Source
SHA-256 checksum
How to use checksums
38c6cff8fc80a789d57d80af488241f206bcfbdfb1517a7e1b848b568b8311dc
BLAKE2b-256 checksum
How to use checksums
2bc9b75ffa0ad3b034065dae245aeafb2c2a4c25d6268ca082197eb4636c790e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 22, 2026.

Transparency log

Release files / agent_jupyter_toolkit-0.10.0-py3-none-any.whl

Download URL agent_jupyter_toolkit-0.10.0-py3-none-any.whl
Size 143.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
946d624b08c58536d247c430828d3404529e5b637bc672d6f3ac182194411bb1
BLAKE2b-256 checksum
How to use checksums
b5d6148b89823740f0bd975eb97fb13384e818554e38a23838324d42417f798a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 22, 2026.

Transparency log

Security for agent-jupyter-toolkit 0.10.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for agent_jupyter_toolkit-0.10.0.tar.gz

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 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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