extensions.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. .. _user_extensions:
  2. Extensions
  3. ----------
  4. Fundamentally, JupyterLab is designed as an extensible environment. JupyterLab
  5. extensions can customize or enhance any part of JupyterLab. They can provide new
  6. themes, file viewers and editors, or renderers for rich outputs in notebooks.
  7. Extensions can add items to the menu or command palette, keyboard shortcuts, or
  8. settings in the settings system. Extensions can provide an API for other
  9. extensions to use and can depend on other extensions. In fact, the whole of
  10. JupyterLab itself is simply a collection of extensions that are no more powerful
  11. or privileged than any custom extension.
  12. JupyterLab extensions are `npm <https://www.npmjs.com/>`__ packages (the
  13. standard package format in Javascript development). You can search for the
  14. keyword `jupyterlab-extension
  15. <https://www.npmjs.com/search?q=keywords%3Ajupyterlab-extension>`__ on the
  16. npm registry to find extensions. For information about developing extensions,
  17. see the :ref:`developer documentation <developer_extensions>`.
  18. .. note::
  19. If you are a JupyterLab extension developer, please note that the extension
  20. developer API is not stable and will evolve in the near future.
  21. In order to install JupyterLab extensions, you need to have `Node.js
  22. <https://nodejs.org/>`__ installed.
  23. If you use ``conda``, you can get it with:
  24. .. code:: bash
  25. conda install -c conda-forge nodejs
  26. If you use `Homebrew <https://brew.sh/>`__ on Mac OS X:
  27. .. code:: bash
  28. brew install node
  29. You can also download Node.js from the `Node.js website <https://nodejs.org/>`__ and
  30. install it directly.
  31. Using the Extension Manager
  32. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. To manage your extensions, you can use the extension manager. By default, the
  34. manager is disabled, but you can enable it with the following steps:
  35. - Go into advanced settings editor.
  36. - Open the Extension Manager section.
  37. - Add the entry "enabled": true.
  38. - Save the settings.
  39. - If prompted whether you are sure, read the warning, and click "Enable"
  40. if you are still sure.
  41. Once enabled, you should see a new tab appear in the :ref:`left sidebar <left-sidebar>`.
  42. .. figure:: images/extension_manager_default.png
  43. :align: center
  44. :class: jp-screenshot
  45. **Figure:** The default view has three components: a search bar, an "Installed"
  46. section, and a "Discover" section.
  47. Finding Extensions
  48. ^^^^^^^^^^^^^^^^^^
  49. You can use the extension manager to find extensions for JupyterLab. To discovery
  50. freely among the currently available extensions, expand the "Discovery" section.
  51. This triggers a search for all JupyterLab extensions on the NPM registry, and
  52. the results are listed according to the `registry's sort order
  53. <https://docs.npmjs.com/searching-for-and-choosing-packages-to-download#package-search-rank-criteria>`__.
  54. An exception to this sort order is that extensions released by the Jupyter
  55. organization are always placed first. These extensions are distinguished by
  56. a small Jupyter icon next to their name.
  57. .. image:: images/extension_manager_discover.png
  58. :align: center
  59. :class: jp-screenshot
  60. :alt: Screenshot showing the discovery extension listing.
  61. Alternatively, you can limit your discovery by using the search bar. This
  62. performs a free-text search of JupyterLab extensions on the NPM registry.
  63. .. image:: images/extension_manager_search.png
  64. :align: center
  65. :class: jp-screenshot
  66. :alt: Screenshot showing an example search result
  67. Installing an Extension
  68. ^^^^^^^^^^^^^^^^^^^^^^^
  69. Once you have found an extension that you think is interesting, install
  70. it by clicking the "Install" button of the extension list entry.
  71. .. danger::
  72. Installing an extension allows it to execute arbitrary code on the
  73. server, kernel, and in the client's browser. You should therefore
  74. avoid installing extensions you do not trust, and watch out for
  75. any extensions trying to masquerade as a trusted extension.
  76. A short while after starting the install of an extension, a drop-down should
  77. appear under the search bar indicating that the extension has been
  78. downloaded, but that a rebuild is needed to complete the installation.
  79. .. image:: images/extension_manager_rebuild.png
  80. :align: center
  81. :class: jp-screenshot
  82. :alt: Screenshot showing the rebuild indicator
  83. If you want to install/uninstall other extensions as well, you can ignore
  84. the rebuild notice until you have made all the changes you want. Once satisfied,
  85. click the 'Rebuild' button to start a rebuild in the background.
  86. Once the rebuild completes, a dialog will pop up, indicating that a reload of
  87. the page is needed in order to load the latest build into the browser.
  88. If you ignore the rebuild notice by mistake, simply refresh your browser
  89. window to trigger a new rebuild check.
  90. Managing Installed Extensions
  91. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  92. When there are some installed extensions, they will be shown in the "Installed"
  93. section. These can then be uninstalled or disabled. Disabling an extension will
  94. prevent it from being activated, but without rebuilding the application.
  95. Companion packages
  96. ^^^^^^^^^^^^^^^^^^
  97. During installation of an extension, JupyterLab will inspect the package
  98. metadata for any
  99. :ref:`instructions on companion packages <ext-author-companion-packages>`.
  100. Companion packages can be:
  101. - Notebook server extensions (or any other packages that need to be
  102. installed on the Notebook server).
  103. - Kernel packages. An example of companion packages for the
  104. kernel are Jupyter Widget packages, like the `ipywidgets <https://ipywidgets.readthedocs.io/en/stable>`__
  105. Python package for the
  106. `@jupyter-widgets/jupyterlab-manager package <https://www.npmjs.com/package/@jupyter-widgets/jupyterlab-manager>`__.
  107. If JupyterLab finds instructions for companion packages, it will present
  108. a dialog to notify you about these. These are informational only, and it
  109. will be up to you to take these into account or not.
  110. Using the Terminal
  111. ~~~~~~~~~~~~~~~~~~~~~
  112. Another way of managing your extensions is from the terminal on the server,
  113. using the ``jupyter labextension`` entry point. In general, a simple help text
  114. is available by typing ``jupyter labextension --help``.
  115. Installing Extensions
  116. ^^^^^^^^^^^^^^^^^^^^^
  117. You can install new extensions into the application
  118. using the command:
  119. .. code:: bash
  120. jupyter labextension install my-extension
  121. where ``my-extension`` is the name of a valid JupyterLab extension npm package
  122. on `npm <https://www.npmjs.com>`__. Use the ``my-extension@version``
  123. syntax to install a specific version of an extension, for example:
  124. .. code:: bash
  125. jupyter labextension install my-extension@1.2.3
  126. You can also install an extension that is not uploaded to npm, i.e.,
  127. ``my-extension`` can be a local directory containing the extension, a gzipped
  128. tarball, or a URL to a gzipped tarball.
  129. We encourage extension authors to add the ``jupyterlab-extension``
  130. GitHub topic to any repository with a JupyterLab extension to facilitate
  131. discovery. You can see a list of extensions by searching GitHub for the
  132. `jupyterlab-extension <https://github.com/search?utf8=%E2%9C%93&q=topic%3Ajupyterlab-extension&type=Repositories>`__
  133. topic.
  134. You can list the currently installed extensions by running the command:
  135. .. code:: bash
  136. jupyter labextension list
  137. Uninstall an extension by running the command:
  138. .. code:: bash
  139. jupyter labextension uninstall my-extension
  140. where ``my-extension`` is the name of the extension, as printed in the
  141. extension list. You can also uninstall core extensions using this
  142. command (you can always re-install core extensions later).
  143. Installing and uninstalling extensions can take some time, as they are
  144. downloaded, bundled with the core extensions, and the whole application
  145. is rebuilt. You can install/uninstall more than one extension in the
  146. same command by listing their names after the ``install`` command.
  147. If you are installing/uninstalling several extensions in several stages,
  148. you may want to defer rebuilding the application by including the flag
  149. ``--no-build`` in the install/uninstall step. Once you are ready to
  150. rebuild, you can run the command:
  151. .. code:: bash
  152. jupyter lab build
  153. **Note**
  154. If using Windows, you may encounter a `FileNotFoundError` due to the default PATH length on
  155. Windows. Node modules are stored in a nested file structure, so the path can get quite
  156. long. If you have administrative access and are on Windows 8 or 10, you can update the
  157. registry setting using these instructions: https://stackoverflow.com/a/37528731.
  158. Disabling Extensions
  159. ^^^^^^^^^^^^^^^^^^^^
  160. You can disable specific JupyterLab extensions (including core
  161. extensions) without rebuilding the application by running the command:
  162. .. code:: bash
  163. jupyter labextension disable my-extension
  164. This will prevent the extension from loading in the browser, but does not
  165. require a rebuild.
  166. You can re-enable an extension using the command:
  167. .. code:: bash
  168. jupyter labextension enable my-extension
  169. Advanced Usage
  170. ~~~~~~~~~~~~~~
  171. Any information that JupyterLab persists is stored in its application directory,
  172. including settings and built assets.
  173. This is separate from where the Python package is installed (like in ``site_packages``)
  174. so that the install directory is immutable.
  175. The application directory can be overridden using ``--app-dir`` in
  176. any of the JupyterLab commands, or by setting the ``JUPYTERLAB_DIR``
  177. environment variable. If not specified, it will default to
  178. ``<sys-prefix>/share/jupyter/lab``, where ``<sys-prefix>`` is the
  179. site-specific directory prefix of the current Python environment. You
  180. can query the current application path by running ``jupyter lab path``.
  181. JupyterLab Build Process
  182. ^^^^^^^^^^^^^^^^^^^^^^^^
  183. To rebuild the app directory, run ``jupyter lab build``. By default, the
  184. ``jupyter labextension install`` command builds the application, so you
  185. typically do not need to call ``build`` directly.
  186. Building consists of:
  187. - Populating the ``staging/`` directory using template files
  188. - Handling any locally installed packages
  189. - Ensuring all installed assets are available
  190. - Bundling the assets
  191. - Copying the bundled assets to the ``static`` directory
  192. Note that building will always use the latest JavaScript packages that meet
  193. the dependency requirements of JupyterLab itself and any installed extensions.
  194. If you wish to run JupyterLab with the set of pinned requirements that was
  195. shipped with the Python package, you can launch as
  196. ``jupyter lab --core-mode``.
  197. JupyterLab Application Directory
  198. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  199. The JupyterLab application directory contains the subdirectories
  200. ``extensions``, ``schemas``, ``settings``, ``staging``, ``static``, and
  201. ``themes``.
  202. .. _extensions-1:
  203. extensions
  204. ''''''''''
  205. The ``extensions`` directory has the packed tarballs for each of the
  206. installed extensions for the app. If the application directory is not
  207. the same as the ``sys-prefix`` directory, the extensions installed in
  208. the ``sys-prefix`` directory will be used in the app directory. If an
  209. extension is installed in the app directory that exists in the
  210. ``sys-prefix`` directory, it will shadow the ``sys-prefix`` version.
  211. Uninstalling an extension will first uninstall the shadowed extension,
  212. and then attempt to uninstall the ``sys-prefix`` version if called
  213. again. If the ``sys-prefix`` version cannot be uninstalled, its plugins
  214. can still be ignored using ``ignoredPackages`` metadata in ``settings``.
  215. schemas
  216. '''''''
  217. The ``schemas`` directory contains `JSON
  218. Schemas <http://json-schema.org/>`__ that describe the settings used by
  219. individual extensions. Users may edit these settings using the
  220. JupyterLab Settings Editor.
  221. settings
  222. ''''''''
  223. The ``settings`` directory may contain the ``page_config.json`` and/or
  224. ``build_config.json`` files, depending on which configurations are
  225. set on your system.
  226. .. _page_configjson:
  227. page_config.json
  228. The ``page_config.json`` data is used to provide configuration data to the
  229. application environment.
  230. The following configurations may be present in this file:
  231. 1. ``terminalsAvailable`` identifies whether a terminal (i.e. ``bash/tsch``
  232. on Mac/Linux OR ``PowerShell`` on Windows) is available to be launched
  233. via the Launcher. (This configuration was predominantly required for
  234. Windows prior to PowerShell access being enabled in Jupyter Lab.) The
  235. value for this field is a Boolean: ``true`` or ``false``.
  236. 2. ``disabledExtensions`` controls which extensions should not load at all.
  237. 3. ``deferredExtensions`` controls which extensions should not load until
  238. they are required by something, irrespective of whether they set
  239. ``autostart`` to ``true``.
  240. The value for the ``disabledExtensions`` and ``deferredExtensions`` fields
  241. are an array of strings. The following sequence of checks are performed
  242. against the patterns in ``disabledExtensions`` and ``deferredExtensions``.
  243. - If an identical string match occurs between a config value and a
  244. package name (e.g., ``"@jupyterlab/apputils-extension"``), then the
  245. entire package is disabled (or deferred).
  246. - If the string value is compiled as a regular expression and tests
  247. positive against a package name (e.g.,
  248. ``"disabledExtensions": ["@jupyterlab/apputils*$"]``), then the
  249. entire package is disabled (or deferred).
  250. - If an identical string match occurs between a config value and an
  251. individual plugin ID within a package (e.g.,
  252. ``"disabledExtensions": ["@jupyterlab/apputils-extension:settings"]``),
  253. then that specific plugin is disabled (or deferred).
  254. - If the string value is compiled as a regular expression and tests
  255. positive against an individual plugin ID within a package (e.g.,
  256. ``"disabledExtensions": ["^@jupyterlab/apputils-extension:set.*$"]``),
  257. then that specific plugin is disabled (or deferred).
  258. An example of a ``page_config.json`` file is:
  259. .. code:: json
  260. {
  261. "disabledExtensions": [
  262. "@jupyterlab/toc"
  263. ],
  264. "terminalsAvailable": false
  265. }
  266. .. _build_configjson:
  267. build_config.json
  268. The ``build_config.json`` file is used to track the local directories
  269. that have been installed using
  270. ``jupyter labextension install <directory>``, as well as core extensions
  271. that have been explicitly uninstalled. An example of a
  272. ``build_config.json`` file is:
  273. .. code:: json
  274. {
  275. "uninstalled_core_extensions": [
  276. "@jupyterlab/markdownwidget-extension"
  277. ],
  278. "local_extensions": {
  279. "@jupyterlab/python-tests": "/path/to/my/extension"
  280. }
  281. }
  282. staging and static
  283. ''''''''''''''''''
  284. The ``static`` directory contains the assets that will be loaded by the
  285. JuptyerLab application. The ``staging`` directory is used to create the
  286. build and then populate the ``static`` directory.
  287. Running ``jupyter lab`` will attempt to run the ``static`` assets in the
  288. application directory if they exist. You can run
  289. ``jupyter lab --core-mode`` to load the core JupyterLab application
  290. (i.e., the application without any extensions) instead.
  291. themes
  292. ''''''
  293. The ``themes`` directory contains assets (such as CSS and icons) for
  294. JupyterLab theme extensions.