Notebook Magic Functions
Jupyter notebook magic functions, also known as magics, are special commands that provide notebook functions that might not be easy for you to program using Python. HPE Ezmeral ML Ops on Kubernetes in HPE Ezmeral Runtime Enterprise supports line magics and cell magics.
Jupyter notebook Magic functions, also known as magic commands or
magics, are commands that you can execute within a code cell. Magics are not
Python code. They are shortcuts that extend a notebook's capabilities. Magic commands
start with the %
character.
HPE Ezmeral ML Ops on HPE Ezmeral Runtime Enterprise supports built-in magic functions and the custom magics that are described in this topic. HPE Ezmeral ML Ops on Kubernetes in HPE Ezmeral Runtime Enterprise supports line magics and cell magics.
Magic functions are deprecated. Support for magics will be discontinued in a future release.
The ezmllib
library is a packaged library that streamlines your
notebook-based coding experience through built-in Python functions. This library has
built-in functions are intended as replacements for the equivalent notebook magic
commands.
Where possible, use the ezmllib
functions instead of the equivalent
magics. See Notebook ezmllib Functions.
Line magic commands do not require a cell body and start with a single %
character. Cell magic commands start with %%
and require additional
lines of input (a cell body).
Some magic commands require a password. After you have supplied the password for one of
these commands in the notebook, the password you supply is automatically applied to
other commands in the notebook that require a password, so you do not have use the
--pwd
argument in subsequent commands. You can override the saved
password, if needed, by specifying the --pwd
argument in the
command.
Listing Available Magics
The %lsmagic
command lists all the magic commands available to this
notebook. The commands are grouped by line magics and then by cell magics.
Getting Help
To display help about a magic command, enter the command followed by a
?
(question mark). For example:
%%kubeRefresh?
%kubeRefresh
Execute this magic if a user-specific kubeconfig
secret was attached
to the Notebook cluster before launching. This magic should be executed before
entering kubectl
commands from the notebook cell.
The syntax is:
%kubeRefresh [--local_kubeconfig {true|false}] [--pwd PWD]
Executing the magic without the --pwd
argument generates an
interactive request for the user password, unless you have already supplied the
password in a previous command in this notebook.
If you want to use a local kubeconfig
file instead of the default
kubeconfig
file, upload the file to the
/home/{user}/kubeconfig
directory and then use the
--local_kubeconfig true
argument.
The magic then obtains the appropriate kubeconfig
file, and you may
begin executing kubectl
commands.
For example:
In HPE Ezmeral Runtime Enterprise 5.4.0 and later, this
magic has an equivalent function in the ezmllib
library. See Notebook ezmllib Functions.
%setLivy
You can use the %setLivy
magic to connect to a different Livy
session.
Syntax:
%setLivy --url URL [--pwd PWD]
For example:
%setLivy --url http://mycorp.net:10029
The --url
argument specifies the Livy endpoint to which you want to
connect.
Executing the magic without the --pwd
argument generates an
interactive request for the user password, unless you have already supplied the
password in a previous command in this notebook. If the Livy session needs
authentication, enter the password. If not, press enter.