Hi,
I am currently writing Jupyter cell magic packages.
And now I wonder what implementation I should use to import them into the notebook.The following example is based on the package GitHub - kolibril13/jupyter-splitview: Making before/after image sliders in JupyterLab .
First of all the magic %%splity
, could be registered
- either with
import jupyter_splitview
- or with
%load_ext jupyter_splitview
.
Now I wonder what is the best way.
Here is a pro con list from my perception:
import jupyter_splitview
# option to reload_extension ❌
# option to unload_extension ❌
# auto-complete âś…
# easy to remember âś…
# Copy&Paste to normal Python won't throw an error âś…
# clear that its a Jupyter features 🟡
%load_ext jupyter_splitview
# option to reload_extension âś… -> %reload_ext jupyter_splitview
# option to reload_extension âś… -> %unload_ext jupyter_splitview
# auto-complete ❌
# easy to remember ❌
# Copy&Paste to normal Python won't throw an error ❌
# clear that its a Jupyter features âś…
And the corresponding implementations in the package are:
# for `import jupyter_splitview`
try:
ipy = get_ipython()
ipy.register_magics(SplitViewMagic)
except AttributeError:
print("Can not load SplitViewMagic because this is not a notebook")
# for `load_ext jupyter_splitview `
def load_ipython_extension(ipython):
ipython.register_magics(SplitViewMagic)
I am looking forward to any inspiration.