Skip to main content

Swarmauri notebook-execution tool for running Jupyter notebooks with nbclient and capturing cell outputs.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_tool_jupyterexecutenotebook Discord

Swarmauri Jupyter Execute Notebook Tool

swarmauri_tool_jupyterexecutenotebook executes every cell in a Jupyter notebook with nbclient, captures notebook outputs in-place, and returns the executed NotebookNode for downstream processing.

Why

  • Run notebooks inside Swarmauri workflows without shelling out to a separate notebook runner.
  • Capture generated outputs for reporting, validation, or export steps.
  • Keep notebook execution inside a simple Python tool contract.

Features

  • Loads notebooks from disk with nbformat.
  • Executes all cells with nbclient.NotebookClient.
  • Returns the executed notebook object rather than a file path.
  • Supports per-cell execution timeout control.
  • Uses allow_errors=True, so the notebook can retain partial outputs even when a cell fails.

FAQ

What does this tool return?

It returns the NotebookNode after execution. If execution fails partway through, the tool still returns the notebook object so callers can inspect partial output.

Does it stop on the first cell error?

No. The underlying client is created with allow_errors=True, which preserves notebook state and outputs even when cells fail.

When should I use this instead of the parameterized execution tool?

Use this package for direct notebook execution. Use swarmauri_tool_jupyterexecutenotebookwithparameters when you need papermill-style parameter injection and an output notebook path.

Installation

uv add swarmauri_tool_jupyterexecutenotebook
pip install swarmauri_tool_jupyterexecutenotebook

Usage

from swarmauri_tool_jupyterexecutenotebook import JupyterExecuteNotebookTool

tool = JupyterExecuteNotebookTool()
executed = tool("notebooks/report.ipynb", timeout=60)

for cell in executed.cells:
    if cell.get("outputs"):
        print(cell["outputs"])

Examples

Execute a notebook before export

from swarmauri_tool_jupyterexecutenotebook import JupyterExecuteNotebookTool

tool = JupyterExecuteNotebookTool()
notebook = tool("analytics/daily_metrics.ipynb", timeout=120)

print(len(notebook.cells))

Inspect partial output after a failing cell

executed = JupyterExecuteNotebookTool()("debug/failing_notebook.ipynb")

for index, cell in enumerate(executed.cells):
    print(index, cell.get("outputs", []))

Related Packages

Foundational Swarmauri Packages

More Documentation

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

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

File details

Details for the file swarmauri_tool_jupyterexecutenotebook-0.11.0.dev1.tar.gz.

File metadata

  • Download URL: swarmauri_tool_jupyterexecutenotebook-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_tool_jupyterexecutenotebook-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 feb489957c7403322e58026ba8fd0d2322bffd83aa81bd102ea73949bc037ef9
MD5 92cb20d18559d56a6c019e878de4edaa
BLAKE2b-256 9fca502d1d4c46f863bce245a4e2d4667452d2c18053e565b46b46ded0c57025

See more details on using hashes here.

File details

Details for the file swarmauri_tool_jupyterexecutenotebook-0.11.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_tool_jupyterexecutenotebook-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_tool_jupyterexecutenotebook-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b206708b680f7d8ee9022069ddcb8ce8cc11c3581835481e4de8bcc32b39fa0
MD5 a880cf45ea05be9cd3c7f219ce832d32
BLAKE2b-256 9d696a6e566f7792c41da874d6f62f29d0e0efc1e25c2b7b390a240f6bec5d46

See more details on using hashes here.

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