Check the List of Magic Commands in Jupyter Notebook and IPython
You can check the list of magic commands available in Jupyter Notebook (IPython Notebook) with %lsmagic
.
ALthough official documents about magic commands are available online, some commands might be unavailable depending on the version or environment. Therefore, it's more reliable to check within the running Jupyter Notebook / IPython.
Note that %lsmagic
is a magic command implemented in IPython and cannot be used in other kernels unless they also support it.
This article covers the following topics.
- The official documentation for IPython magic commands
- Display the list of magic commands with
%lsmagic
- Check the details of each magic command within Jupyter Notebook
?
and??
- Keyboard shortcut:
shift + TAB
The official documentation for IPython magic commands
The official documentation for IPython magic commands can be found here:
Display the list of magic commands with %lsmagic
You can display the list of available magic commands with %lsmagic
.
For .ipynb
, refer to the link below:
%lsmagic
can also be used in IPython's interactive console.
In [1]: %lsmagic
Out[1]:
Available line magics:
%alias %alias_magic %autocall %autoindent %automagic %bookmark %cat %cd %clear %colors %config %cp %cpaste %debug %dhist %dirs %doctest_mode %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %lf %lk %ll %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %lx %macro %magic %man %matplotlib %mkdir %more %mv %notebook %page %paste %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %popd %pprint %precision %profile %prun %psearch %psource %pushd %pwd %pycat %pylab %quickref %recall %rehashx %reload_ext %rep %rerun %reset %reset_selective %rm %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode
Available cell magics:
%%! %%HTML %%SVG %%bash %%capture %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile
Automagic is ON, % prefix IS NOT needed for line magics.
Check the details of each magic command within Jupyter Notebook
You can check the details of each magic command within Jupyter Notebook and IPython's interactive console.
?
and ??
Appending ?
to the end of a magic command and executing it will display its docstring. Appending ??
will display its source code.
In [1]: %lsmagic?
Docstring: List currently available magic functions.
File: /opt/homebrew/lib/python3.11/site-packages/IPython/core/magics/basic.py
In [2]: %lsmagic??
Source:
@line_magic
def lsmagic(self, parameter_s=''):
"""List currently available magic functions."""
return MagicsDisplay(self.shell.magics_manager, ignore=[])
File: /opt/homebrew/lib/python3.11/site-packages/IPython/core/magics/basic.py
Keyboard shortcut: shift + TAB
In Jupyter Notebook, place the caret on a magic command in an input cell and press shift + TAB
to display the docstring. Pressing TAB
again while holding shift
will display more detailed information.
Keep in mind that you need to place the caret (vertical bar) on the magic command, not the mouse pointer.