We created some documentation for a client regarding
how to pin a Python library to a specific version of a JupyterLab extension and we’d like to share it more publicly so that other people can benefit from it. This may go into the JupyterLab docs, but in the meantime we’d like to share it here and invite others to comment and/or revise.
This file has been truncated.
The best practice for pinning a Python library (or any kernel-side library) to a specific JupyterLab extension is to use a versioned _MIME type_ or _media type_. A good example of this is the [Altair](https://github.com/altair-viz/altair) Python library which supports multiple versions of Vega and Vega-lite and [vega4-extension](https://github.com/jupyterlab/jupyter-renderers/tree/master/packages/vega4-extension), [vega3-extension](https://github.com/jupyterlab/jupyter-renderers/tree/master/packages/vega3-extension), and [vega2-extension](https://github.com/jupyterlab/jupyter-renderers/tree/master/packages/vega2-extension) which render Altair output.
# MIME types
In Jupyter notebooks, cell _output areas_ contain one or more _outputs_ of a given MIME type. The MIME type describes the data type of the output. The default MIME type is `text/plain`. JupyterLab provides a set of _mimerender extensions_ that render common MIME types such as `text/plain` or `application/json`. There are many third-party extensions that render other MIME types, such as [geojson-extension](https://github.com/jupyterlab/jupyter-renderers/tree/master/packages/geojson-extension) which renders `application/geo+json` and [plotly-extension](https://github.com/jupyterlab/jupyter-renderers/tree/master/packages/plotly-extension) that renders `application/vnd.plotly.v1+json`.
As you can see in the Plotly example, MIME types can include versions. This allows a mimerender extension to target a specific version of a MIME type. The [vega2-extension](https://github.com/jupyterlab/jupyter-renderers/tree/master/packages/vega2-extension) targets `application/vnd.vega.v2+json` and [vega3-extension](https://github.com/jupyterlab/jupyter-renderers/tree/master/packages/vega3-extension) targets `application/vnd.vega.v3+json`, etc. In the case of Vega (which is currently at version 5), this is a useful pattern because vega2-extension cannot render vega 5 specs and vice-versa.