Skip to article frontmatterSkip to article content

Jupyter Magic Commands


In addition to running Python code, Jupyter Notebooks provide magic commands with various functions. We provide an introduction to a several, but many more are available. Plese see the Jupyter Magics documentaion for more information.


Shell Assignment Syntax

In Jupyter Notebooks, the exclamation mark ! allows users to run shell commands from inside a Jupyter Notebook code cell (/bin/bash in OpenSARLab).

Simply start a line of code with ! and it will run the command in a shell, using the Conda environment of the currently running Python kernel.

Using ! to run shell commands in a Jupyter Notebook.

Using ! to run shell commands in a Jupyter Notebook.


Line Magics

Line magics start with a single %. They either update a setting that affect the entire notebook or they affect only the line where % is used.

%matplotlib inline

%matplotlib widget

%time

Find information on many more line magics here.


Cell Magics

Cell magics start with %% and affect the contents of an entire code cell.

%%javascript or %%js

Jupyter Javascript magic example.

Jupyter Javascript magic example.

%%capture

Find information on many more cell magics here.