extensions.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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
  6. new themes, file viewers and editors, or renderers for rich outputs in
  7. notebooks. Extensions can add items to the menu or command palette, keyboard
  8. shortcuts, or settings in the settings system. Extensions can provide an API
  9. for other extensions to use and can depend on other extensions. In fact, the
  10. whole of JupyterLab itself is simply a collection of extensions that are no
  11. more powerful or privileged than any custom extension.
  12. For information about developing extensions, see the :ref:`developer
  13. documentation <developer_extensions>`.
  14. .. contents:: Table of contents
  15. :local:
  16. :depth: 1
  17. Installing Extensions
  18. ---------------------
  19. A JupyterLab extension is a JavaScript package that can be installed into
  20. JupyterLab and runs in the browser. An extension contains one or more plugins
  21. that extend JupyterLab. An extension's JavaScript can be distributed as a
  22. single JavaScript package (which requires a rebuild of JupyterLab to activate
  23. it), or starting in JupyterLab 3.0, can be bundled together with its
  24. dependencies (which does not require a rebuild of JupyterLab to activate it).
  25. Rebuilding JupyterLab requires Node.js to be :ref:`installed
  26. <installing_nodejs>`.
  27. An extension can be installed using the `pip <https://pypi.org/>`__ or `conda
  28. <https://anaconda.org/>`__ package managers, or using the Jupyter Lab tools to
  29. install packages from `npm
  30. <https://www.npmjs.com/search?q=keywords:jupyterlab-extension>`__.
  31. - Python ``pip`` or ``conda`` packages can include extensions as either single
  32. JavaScript packages (requiring Node.js and a JupyterLab rebuild) or bundled
  33. with their dependencies (not requiring Node.js nor a JupyterLab rebuild).
  34. These packages may also include by a server-side component necessary for the
  35. extension to function.
  36. - The Extension Manager in JupyterLab and the ``jupyter labextension install``
  37. command install extension packages from `npm
  38. <https://www.npmjs.com/search?q=keywords:jupyterlab-extension>`__. These
  39. require Node.js and a JupyterLab rebuild to activate. See
  40. :ref:`installing_nodejs` and :ref:`install_command`.
  41. .. _installing_nodejs:
  42. Installing Node.js
  43. ^^^^^^^^^^^^^^^^^^
  44. Some extensions require `Node.js <https://nodejs.org/>`__ to rebuild
  45. JupyterLab and activate the extension. If you use ``conda`` with
  46. ``conda-forge`` packages, you can get Node.js with:
  47. .. code:: bash
  48. conda install -c conda-forge nodejs
  49. If you use ``conda`` with default Anaconda packages (i.e., you don't normally
  50. use ``conda-forge``), you should install Node.js from the Anaconda default
  51. channel with ``conda install nodejs`` instead.
  52. You may also be able to get Node.js from your system package manager, or you
  53. can download Node.js from the `Node.js website <https://nodejs.org/>`__
  54. and install it directly.
  55. .. _install_command:
  56. Managing Extensions with ``jupyter labextension``
  57. -------------------------------------------------
  58. The ``jupyter labextension`` command enables you to install or uninstall
  59. extensions from `npm
  60. <https://www.npmjs.com/search?q=keywords:jupyterlab-extension>`__, list all
  61. installed extensions, or disable any extension. See the help with ``jupyter
  62. labextension --help``.
  63. Installing and Uninstalling Extensions
  64. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  65. You can install extensions from `npm
  66. <https://www.npmjs.com/search?q=keywords:jupyterlab-extension>`__ with:
  67. .. code:: bash
  68. jupyter labextension install my-extension my-other-extension
  69. Use the ``my-extension@version`` syntax to install a specific version
  70. of an extension, for example:
  71. .. code:: bash
  72. jupyter labextension install my-extension@1.2.3
  73. You can also install an extension that is not uploaded to npm, i.e.,
  74. ``my-extension`` can be a local directory containing the extension, a
  75. gzipped tarball, or a URL to a gzipped tarball.
  76. .. note::
  77. Any extension installed from npm will require :ref:`installing
  78. Node.js <installing_nodejs>` and require a rebuild of JupyterLab.
  79. Uninstall extensions that were installed from npm using the command:
  80. .. code:: bash
  81. jupyter labextension uninstall my-extension my-other-extension
  82. If you are installing/uninstalling several extensions in several stages,
  83. you may want to defer rebuilding the application by including the flag
  84. ``--no-build`` in the install/uninstall step. Once you are ready to
  85. rebuild, you can run the command:
  86. .. code:: bash
  87. jupyter lab build
  88. .. note::
  89. If you are rebuilding JupyterLab on Windows, you may encounter a
  90. ``FileNotFoundError`` due to the default path length on Windows. Node
  91. modules are stored in a deeply nested directory structure, so paths can get
  92. quite long. If you have administrative access and are on Windows 8 or 10,
  93. you can update the registry setting using these instructions:
  94. https://stackoverflow.com/a/37528731.
  95. Listing installed extensions
  96. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  97. List all installed extensions, including those installed with ``pip`` or
  98. ``conda``, with:
  99. .. code:: bash
  100. jupyter labextension list
  101. .. note::
  102. ``jupyter labextension`` identifies an extension by its JavaScript package
  103. name, which may be different from the name of the ``pip`` or ``conda``
  104. package used to distribute the extension.
  105. .. _enable_disable_config:
  106. Enabling and Disabling Extensions
  107. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  108. Disabling an extension prevents the extension from running in JupyterLab
  109. (though the code is still loaded). You can disable specific JupyterLab
  110. extensions (including core extensions) without rebuilding JupyterLab with:
  111. .. code:: bash
  112. jupyter labextension disable my-extension
  113. You can enable a disabled extension with:
  114. .. code:: bash
  115. jupyter labextension enable my-extension
  116. Installed extensions are enabled by default, unless there is configuration explicity disabling them.
  117. Extensions can be disabled or forcably enabled using the command line.
  118. Extensions or individual plugins with an extension can be disabled by another extension.
  119. The priority order for whether an extension is enabled or disabled is as follows:
  120. - Presence of ``<jupyter_config_path>/labconfig/pageconfig.json`` file(s) with a ``disabledExtensions`` key that is a object with package names as keys and boolean values.
  121. - (deprecated) Presence of ``disabledExensions`` key in ``<lab_app_dir>/settings/pageconfig.json``. This value is a list of extensions to disable, but is deprecated in favor of the layered configuration approach in the `labconfig` location(s).
  122. - Presence of ``disabledExtensions`` key in another JupyterLab extension's metadata that disables a given extension. The key is ignored if that extension itself is disabled.
  123. When using the command line, you can target the ``--level`` of the config: ``user``, ``system``, or ``sys-prefix`` (default).
  124. An example ``<jupyter_config_path>/labconfig/pageconfig.json`` could look as follows:
  125. .. code:: json
  126. {
  127. "disabledExtensions": {
  128. "@jupyterlab/notebook-extension": true
  129. }
  130. }
  131. See :ref:`documentation on LabConfig directories <labconfig_directories>` for more information.
  132. Managing Extensions Using the Extension Manager
  133. -----------------------------------------------
  134. You can use the Extension Manager in JupyterLab to manage extensions that are
  135. distributed as single JavaScript packages on npm.
  136. The Extension Manager is in the :ref:`left sidebar <left-sidebar>`.
  137. TODO: update screenshots
  138. .. figure:: images/extension_manager_default.png
  139. :align: center
  140. :class: jp-screenshotls
  141. **Figure:** The default view has three components: a search bar, an "Installed"
  142. section, and a "Discover" section.
  143. Disclaimer
  144. ^^^^^^^^^^
  145. .. danger::
  146. Installing an extension allows it to execute arbitrary code on the server,
  147. kernel, and the browser. Therefore, we ask you to explicitly acknowledge
  148. this.
  149. By default, the disclaimer is not acknowledged.
  150. .. figure:: images/listings/disclaimer_unchecked.png
  151. :align: center
  152. :class: jp-screenshot
  153. **Figure:** User has not acknowledged the disclaimer
  154. As the disclaimer is not acknowledged, you can search for an extension,
  155. but can not install it (no install button is available).
  156. .. figure:: images/listings/disclaimer_unchecked_noinstall.png
  157. :align: center
  158. :class: jp-screenshot
  159. **Figure:** With Disclaimer unchecked, you can not install an extension
  160. To install an extension, you first have to explicitly acknowledge the disclaimer.
  161. Once done, this will remain across sessions and the user does not have to
  162. check it again.
  163. .. figure:: images/listings/disclaimer_checked.png
  164. :align: center
  165. :class: jp-screenshot
  166. **Figure:** Disclaimer checked
  167. For ease of use, you can hide the disclaimer so it takes less space on
  168. your screen.
  169. .. figure:: images/listings/disclaimer_hidden.png
  170. :align: center
  171. :class: jp-screenshot
  172. **Figure:** Disclaimer is hidden
  173. Finding Extensions
  174. ^^^^^^^^^^^^^^^^^^
  175. You can use the extension manager to find extensions for JupyterLab. To discovery
  176. freely among the currently available extensions, expand the "Discovery" section.
  177. This triggers a search for all JupyterLab extensions on the NPM registry, and
  178. the results are listed according to the `registry's sort order
  179. <https://docs.npmjs.com/searching-for-and-choosing-packages-to-download#package-search-rank-criteria>`__.
  180. An exception to this sort order is that extensions released by the Jupyter
  181. organization are always placed first. These extensions are distinguished by
  182. a small Jupyter icon next to their name.
  183. .. image:: images/extension_manager_discover.png
  184. :align: center
  185. :class: jp-screenshot
  186. :alt: Screenshot showing the discovery extension listing.
  187. Alternatively, you can limit your discovery by using the search bar. This
  188. performs a free-text search of JupyterLab extensions on the NPM registry.
  189. .. image:: images/extension_manager_search.png
  190. :align: center
  191. :class: jp-screenshot
  192. :alt: Screenshot showing an example search result
  193. Installing an Extension
  194. ^^^^^^^^^^^^^^^^^^^^^^^
  195. Once you have found an extension that you think is interesting, install
  196. it by clicking the "Install" button of the extension list entry.
  197. .. danger::
  198. Installing an extension allows it to execute arbitrary code on the
  199. server, kernel, and in the client's browser. You should therefore
  200. avoid installing extensions you do not trust, and watch out for
  201. any extensions trying to masquerade as a trusted extension.
  202. A short while after starting the install of an extension, a drop-down should
  203. appear under the search bar indicating that the extension has been
  204. downloaded, but that a rebuild is needed to complete the installation.
  205. .. image:: images/extension_manager_rebuild.png
  206. :align: center
  207. :class: jp-screenshot
  208. :alt: Screenshot showing the rebuild indicator
  209. If you want to install/uninstall other extensions as well, you can ignore
  210. the rebuild notice until you have made all the changes you want. Once satisfied,
  211. click the 'Rebuild' button to start a rebuild in the background.
  212. Once the rebuild completes, a dialog will pop up, indicating that a reload of
  213. the page is needed in order to load the latest build into the browser.
  214. If you ignore the rebuild notice by mistake, simply refresh your browser
  215. window to trigger a new rebuild check.
  216. Managing Installed Extensions
  217. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  218. When there are some installed extensions, they will be shown in the "Installed"
  219. section. These can then be uninstalled or disabled. Disabling an extension will
  220. prevent it from being activated, but without rebuilding the application.
  221. Companion packages
  222. ^^^^^^^^^^^^^^^^^^
  223. During installation of an extension, JupyterLab will inspect the package
  224. metadata for any
  225. :ref:`instructions on companion packages <ext-author-companion-packages>`.
  226. Companion packages can be:
  227. - Notebook server extensions (or any other packages that need to be
  228. installed on the Notebook server).
  229. - Kernel packages. An example of companion packages for the
  230. kernel are Jupyter Widget packages, like the `ipywidgets <https://ipywidgets.readthedocs.io/en/stable>`__
  231. Python package for the
  232. `@jupyter-widgets/jupyterlab-manager package <https://www.npmjs.com/package/@jupyter-widgets/jupyterlab-manager>`__.
  233. If JupyterLab finds instructions for companion packages, it will present
  234. a dialog to notify you about these. These are informational only, and it
  235. will be up to you to take these into account or not.
  236. .. _extension_listings:
  237. Listings
  238. ^^^^^^^^
  239. When searching extensions in the Extension Manager, JupyterLab displays the complete search result and
  240. the user is free to install any extension. This is the :ref:`default_mode`.
  241. To bring more security, you or your administrator can enable ``blocklists`` or ``allowlists``
  242. mode. JupyterLab will check the extensions against the defined listings.
  243. .. warning::
  244. Only one mode at a time is allowed. If you or your server administrator configures
  245. both block and allow listings, the JupyterLab server will not start.
  246. .. figure:: images/listings/simultaneous_block_allow_listings.png
  247. :align: center
  248. :class: jp-screenshot
  249. **Figure:** Simultaneous block and allow listings
  250. The following details the behavior for the :ref:`blocklist_mode` and the :ref:`allowlist_mode`.
  251. The details to enable configure the listings can be read :ref:`listings_conf`.
  252. .. _default_mode:
  253. Default mode
  254. """"""""""""
  255. In the ``default`` mode, no listing is enabled and the search behavior is unchanged and
  256. is the one described previously.
  257. .. _blocklist_mode:
  258. Blocklist mode
  259. """"""""""""""
  260. Extensions can be freely downloaded without going through a vetting process.
  261. However, users can add malicious extensions to a blocklist. The extension manager
  262. will show all extensions except for those that have
  263. been explicitly added to the blocklist. Therfore, the extension manager
  264. does not allow you to install blocklisted extensions.
  265. If you, or your administrator, has enabled the blocklist mode,
  266. JupyterLab will use the blocklist and remove all blocklisted
  267. extensions from your search result.
  268. If you have installed an extension before it has been blocklisted,
  269. the extension entry in the installed list will be highlighted
  270. in red. It is recommended that you uninstall it. You can move
  271. your mouse on the question mark icon to read the instructions.
  272. .. figure:: images/listings/installed_blocklisted.png
  273. :align: center
  274. :class: jp-screenshot
  275. **Figure:** Blocklisted installed extension which should be removed
  276. .. _allowlist_mode:
  277. Allowlist mode
  278. """"""""""""""
  279. An allowlist maintains a set of approved extensions that users can freely
  280. search and install. Extensions need to go through some sort of vetting process
  281. before they are added to the allowlist. When using an allowlist, the extension manager
  282. will only show extensions that have been explicitly added to the allowlist.
  283. If you, or your administrator, has enabled the allowlist mode
  284. JupyterLab will use the allowlist and only show extensions present
  285. in the withelist. The other extensions will not be show in the search result.
  286. If you have installed an allowlisted extension and at some point
  287. in time that extension is removed from the allowlist, the extension entry
  288. in the installed list will be highlighted in red. It is recommended that
  289. you uninstall it. You can move your mouse on the question mark icon to
  290. read the instructions.
  291. .. figure:: images/listings/installed_allowlisted.png
  292. :align: center
  293. :class: jp-screenshot
  294. **Figure:** The second of the installed extensions was removed from the allowlist and should be removed
  295. .. _listings_conf:
  296. Listing Configuration
  297. """""""""""""""""""""
  298. You or your administrator can use the following traits to define the listings loading.
  299. - ``blocklist_uris``: A list of comma-separated URIs to fetch a blocklist file from
  300. - ``allowlist_uris``: A list of comma-separated URIs to fetch an allowlist file from
  301. - ``listings_refresh_seconds``: The interval delay in seconds to refresh the lists
  302. - ``listings_request_options``: The optional kwargs to use for the listings HTTP requests
  303. For example, to enable blocklist, launch the server with ``--LabServerApp.blocklist_uris=http://example.com/blocklist.json`` where ``http://example.com/blocklist.json`` is a blocklist JSON file as described below.
  304. The details for the listings_request_options are listed
  305. on `this page <https://2.python-requests.org/en/v2.7.0/api/#requests.request>`__
  306. (for example, you could pass ``{'timeout': 10}`` to change the HTTP request timeout value).
  307. The listings are json files hosted on the URIs you have given.
  308. For each entry, you have to define the `name` of the extension as published in the NPM registry.
  309. The ``name`` attribute supports regular expressions.
  310. Optionally, you can also add some more fields for your records (``type``, ``reason``, ``creation_date``,
  311. ``last_update_date``). These optional fields are not used in the user interface.
  312. This is an example of a blocklist file.
  313. .. code:: json
  314. {
  315. "blocklist": [
  316. {
  317. "name": "@jupyterlab-examples/launcher",
  318. "type": "jupyterlab",
  319. "reason": "@jupyterlab-examples/launcher is blocklisted for test purpose - Do NOT take this for granted!!!",
  320. "creation_date": "2020-03-11T03:28:56.782Z",
  321. "last_update_date": "2020-03-11T03:28:56.782Z"
  322. }
  323. ]
  324. }
  325. In the following allowlist example a ``@jupyterlab/*`` will allowlist
  326. all jupyterlab organization extensions.
  327. .. code:: json
  328. {
  329. "allowlist": [
  330. {
  331. "name": "@jupyterlab/*",
  332. "type": "jupyterlab",
  333. "reason": "All @jupyterlab org extensions are allowlisted, of course...",
  334. "creation_date": "2020-03-11T03:28:56.782Z",
  335. "last_update_date": "2020-03-11T03:28:56.782Z"
  336. }
  337. ]
  338. }