Skip to main content

script-widget

A Jupyter cell magic that runs a cell in a fresh, isolated namespace and shows everything it produced -- stdout, stderr, rich display output, any exception -- in a shaded box below the cell, built on anywidget.

import script_widget  # registers the %%exercise cell magic
%%exercise
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])

Nothing the cell defines or imports persists past that one run, and nothing the notebook has already defined is visible to it -- except through the cell's own import/from ... import statements. Because Python caches loaded modules in sys.modules, such an import is essentially free and hands back the exact same live object the notebook already has (the same plt, with the same open figures; the same model, with the same weights) -- nothing is reloaded or reinitialized, and no kernel restart happens.

Installation

# pixi
pixi workspace channel add munch-group
pixi add script-widget

# conda
conda install -c munch-group script-widget

# pip
pip install script-widget

Writing a %%exercise cell

  • Anything the cell needs -- a library, a model, a helper function -- must be imported by the cell itself. Plain notebook variables with no import path (e.g. a dataframe built inline two cells up) aren't visible.
  • A trailing bare expression is displayed, exactly like a normal cell (a + b, or a variable's name on its own); an assignment as the last line still runs, but produces no comparable output.

Documentation

Full docs live at munch-group.org/script-widget.

Development

This repo is managed with pixi:

pixi run install-dev   # editable install into the pixi environment
pixi run test          # run the pytest suite
pixi run docs          # execute the documentation notebooks
pixi run api           # build the quartodoc API reference

License

MIT

Download files

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

Source Distribution

script_widget-1.0.3.tar.gz (467.0 kB view details)

Uploaded Source

Built Distribution

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

script_widget-1.0.3-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

Details for the file script_widget-1.0.3.tar.gz.

File metadata

  • Download URL: script_widget-1.0.3.tar.gz
  • Upload date:
  • Size: 467.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for script_widget-1.0.3.tar.gz
Algorithm Hash digest
SHA256 417eed2d14f5768bc4a65bfcd8a4cb6756f7ea456fb12dc76e3431d1d7e83b7a
MD5 3b436036ea8e2e806f13429e1e2f46c3
BLAKE2b-256 386cfcc84616e5f98b83288bdf0d69e33fbf5bd76722a2fa438b1827565968e2

See more details on using hashes here.

File details

Details for the file script_widget-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: script_widget-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 26.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for script_widget-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 df423e481181cf3920ef69a0dcab3749244935fc9f8be09b007eb96308a49d7b
MD5 52cb8d4bafd2b217980a6a627a958065
BLAKE2b-256 8c1e508665ece4e34384f7e78bcee8a9a3832702dee46b6bdef4474ef01732e6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 files

1.0.1

2 files

0.1.21

2 files

0.1.19

2 files

0.1.18

2 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