Skip to main content

sandbox-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 sandbox_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 sandbox-widget

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

# pip
pip install sandbox-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

sandbox_widget-1.0.7.tar.gz (468.7 kB view details)

Uploaded Source

Built Distribution

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

sandbox_widget-1.0.7-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file sandbox_widget-1.0.7.tar.gz.

File metadata

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

File hashes

Hashes for sandbox_widget-1.0.7.tar.gz
Algorithm Hash digest
SHA256 2e44e2ac2a71696669c097c4f98e9a3bd178f77ae248b6bc8824d9cb404ccc62
MD5 b332255383f339c92b75b9f342e77f49
BLAKE2b-256 1696ce0bf534dc34d3c774cdacaca7f4da411e24287be8f2649a680b95a4e815

See more details on using hashes here.

File details

Details for the file sandbox_widget-1.0.7-py3-none-any.whl.

File metadata

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

File hashes

Hashes for sandbox_widget-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bf0c1ae6626cb6dcf5377fbc974ebec722ffe10ec34cdf6dd1816d91342a7206
MD5 45c3babeecbdc70088fd75a49acc9c6a
BLAKE2b-256 c4990232f20bd6836b42526119aa91da088695b0c6505b75961f8da09dbb4ff7

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.21

2 files

1.0.19

2 files

1.0.17

2 files

1.0.15

2 files

1.0.13

2 files

1.0.11

2 files

1.0.9

2 files

This release

1.0.7 This release

2 files

1.0.5

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