---
title: "Python scripts and notebooks"
summary: "Run code in the current scientific session and save scientific changes separately."
url: https://hookeui.org/docs/python-console/
status: Development docs
publication_status: development-docs
implementation_status: merged-source-review
availability: Development docs. Check your installed version; Stable or Beta may differ.
source_repository: https://github.com/wpulier/HookeUI
source_revision: 07a0e90c99a6638835b35891a5fc6b041bdcf051
reviewed_date: 2026-10-28
source_paths: ["apps/studio/src/scientific-document.ts","apps/studio/src/scientific-console.ts","apps/studio/src/scientific-scripts.ts","apps/studio/src/scientific-python-help.ts","apps/studio/src/scientific-notebook.ts"]
---

# Python scripts and notebooks

Run code in the current scientific session and save scientific changes separately.

Development docs. Check your installed version; Stable or Beta may differ.

These guides follow development; your installed Stable or Beta may differ.

The scientific **Python** panel belongs to an opened, prepared scientific session. It operates on that session's data and variables; it does not select an unrelated terminal Python environment.

## Review and run a script [#review-and-run-a-script]

### Open the correct session [#open-the-correct-session]
Open the retained scientific document, then **Controls → Open saved view → Python**. Check the Project, saved input and private session before running code.
### Enter or load the code [#enter-or-load-the-code]
Use **Python code**, or **Open Python script** for a nonempty UTF-8 `.py` file up to 256 KiB. When a draft exists, choose **Replace draft with this script** or **Keep current draft** deliberately. Review code and its file/provider effects before executing it.
### Run and inspect the outcome [#run-and-inspect-the-outcome]
Choose **Run code**. Inspect the cell's output, error and refreshed view. **Complete name** or **Help for name** supports session introspection; Ctrl+Space requests completion. Those name lookups are not AI provider calls.
### Retain what you need [#retain-what-you-need]
**Download draft as .py** exports script text only. Use the scientific **Save** controls to retain array changes or supported tool state. A visible Python history entry is not a saved scientific-data revision.

## Interrupt or end a session [#interrupt-or-end-a-session]

**Interrupt code** requests interruption while retaining variables and partial changes. A native call can need to return before interruption is observed. **Stop Python session** ends the session and discards its unsaved state; accepted Project data remains.

If execution is unconfirmed, it may already have run. Follow the instruction to stop that session before another execution rather than blindly retrying a possibly effective command. Earlier history and drafts can remain visible in a new session, but their code is not automatically replayed.

## Connect local Jupyter [#connect-local-jupyter]

Where offered, open **Connect a notebook**, then its **Connect a notebook** action. Follow the app's displayed local kernelspec-install command and expiry, then select that displayed kernel in Jupyter on this Mac. Use the command shown by your current session rather than copying a stale command from a previous run.

Notebook cells execute in the same Hooke scientific session and enter its Python history. **Revoke notebook connection** ends that access. Reconnecting replaces the previous connection; stopping or replacing the private session ends it. Save scientific data explicitly before ending that session.

For ordinary image-analysis tasks without code, start with [Run an analysis tool](/docs/run-a-tool/).
