Useful Magic Commands for JupterLab

Shan Dou
Jun 4, 2021

--

1. nb_black: Black auto-formmater for Jupyter

  • Installation (view on PyPI): pip install nb-black
  • Usage: In top-cell magic in jupyter lab
%load_ext lab_black

2. ipython-autotime: Time each code cell

  • Installation (view on PyPI): pip install ipython-autotime
  • Usage: In top-cell magic in jupyter lab
%load_ext autotime

3. autoreload: Reload imported modules

  • Built-in (Docs)
  • Usage: In top-cell magic in jupyter lab
%load_ext autoreload
%autoreload 2
  • Example usage:
In [1]: %load_ext autoreload
In [2]: %autoreload 2
In [3]: from foo import some_function
In [4]: some_function()
Out[4]: 42
In [5]: # open foo.py in an editor and change some_function to return 43
In [6]: some_function()
Out[6]: 43

--

--

Shan Dou
Shan Dou

No responses yet