Jupyter Blog

The Jupyter Blog

Follow publication

Inspector JupyterLab

JupyterLab provides multiple ways to improve your coding workflow: code highlighting, code completion, theming, debugger with rich variable rendering and more.

The JupyterLab inspector

The JupyterLab inspector is one of the ways to enhance your coding experience, it is a UI panel that provides contextual help while you are typing:

You can open the inspector using the Ctrl + I shortcut (or ⌘ + I on Mac).

With the Python kernel (ipykernel or xeus-python), this contextual help normally contains a text representation generated using the inspect Python module and the docstrings associated to an object. But there is a way to make it much nicer!

Go-Go-Gadget Docrepr

Docrepr is a Python package which renders docstrings into HTML using Sphinx, maintained by the Spyder team. IPython allows to use docrepr for code inspection, making it the perfect combination for a nice rendering of the contextual help in the inspector!

Thanks to the recent work on the jupyterlab-pygments extension, the docrepr output even respect the current JupyterLab theme for syntax highlighting!

Installation

First you will need to install the package (either with pip or mamba)

pip install docrepr jupyterlab_pygments

Or:

mamba install -c conda-forge docrepr jupyterlab_pygments

In order for IPython to use docrepr, you will need to execute the following in your Notebook (e.g. in the first cell):

ip = get_ipython()
ip.sphinxify_docstring = True
ip.enable_html_pager = True

This also can be set in your IPython configuration file located in ~/.ipython/profile_default/ipython_config.py:

c = get_config()c.InteractiveShell.sphinxify_docstring = True
c.InteractiveShell.enable_html_pager = True

You are all set! The JupyterLab inspector will now render HTML representations of the contextual help.

Acknowledgments

Docrepr has a long history, it originates from the Sphinxify tool of the Sage project that was created back in 2009 by Tim Dumol. In 2010 Carlos Córdoba used it to power Spyder’s help pane and in 2015 he extracted that code and created the docrepr Python package, so that other projects could benefit from it. It was later integrated in IPython by Sylvain Corlay. In 2021 C.A.M. Gerlach, Ahmed Fasih and myself updated the package to support the latest Sphinx version.

My work on this project at QuantStack was funded by Bloomberg.

About the Author

My name is Martin Renou, I am a Scientific Software Engineer at QuantStack. Before joining QuantStack, I studied at the aerospace engineering school SUPAERO in Toulouse, France. I also worked at Logilab in Paris, France and Enthought in Cambridge, UK. As an open-source developer at QuantStack, I work on a variety of projects, from xtensor and xeus-python in C++ to ipyleaflet and bqplot in Python and JavaScript/TypeScript, I am also the author of several JupyterLab extensions.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response