The %run magic executes another notebook in your current kernel's namespace. After it returns, every variable, function, and import defined by the executed notebook is available in your current notebook as if you had typed those cells yourself. It's the standard tool for sharing setup or helper code across notebooks without duplicating it.
Both Python and Scala kernels support it.
Basic usage
python # Python — execute another notebook in this kernel's namespace %run helpers.ipynb # After the call, anything helpers.ipynb defined is in scope here df = load_curated_data()
scala // Scala — same magic, same behavior %run helpers.ipynb // helpers' definitions are now available val df = loadCuratedData()
How it resolves the path
%run accepts either the full path of the notebook to be executed or a relative path with respect to the current working directory, which is the directory of the notebook you're running it from. Pass a relative path to point at a file in a sibling folder, or an absolute path under the workspace root for anything further away. Cross-workspace references are not supported — %run can only reach files in the workspace this notebook lives in.
What it executes
The entire target notebook is executed top to bottom. Every cell runs in the current kernel and shares state with the calling notebook. Cells that print or return output produce that output in your current notebook's cell where %run was invoked.
Common uses
- Share helper functions or imports across multiple notebooks — keep them in one file and %run it at the top of each notebook that needs them.
- Bootstrap a notebook with environment setup, common Spark configurations, or shared constants.
- Run a setup notebook before an analysis notebook so the analysis starts with the right state.
% python Magic
%python is an advanced cell magic used in Syntasa notebook environments to execute Python code within a notebook that otherwise runs on a Scala kernel. When a cell is prefixed with %python, that specific cell is executed using a Python kernel (Python 3.9 by default), while all other cells continue to run using the Scala kernel. This enables multi-language workflows within a single notebook, allowing users to leverage Python libraries alongside Scala code. The execution context is limited to the cell in which the magic is applied, and variables are not automatically shared between Scala and Python environments.