extensions.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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. You can enable it by searching **Extension Manager** in the command palette.
  35. .. figure:: images/extension_manager_enable_manager.png
  36. :align: center
  37. :class: jp-screenshot
  38. **Figure:** Enable extension manager by searching in the command palette
  39. You can also enable it with the following steps:
  40. - Go into advanced settings editor.
  41. - Open the Extension Manager section.
  42. - Add the entry "enabled": true.
  43. - Save the settings.
  44. - If prompted whether you are sure, read the warning, and click "Enable"
  45. if you are still sure.
  46. Once enabled, you should see a new tab appear in the :ref:`left sidebar <left-sidebar>`.
  47. .. figure:: images/extension_manager_default.png
  48. :align: center
  49. :class: jp-screenshot
  50. **Figure:** The default view has three components: a search bar, an "Installed"
  51. section, and a "Discover" section.
  52. Finding Extensions
  53. ^^^^^^^^^^^^^^^^^^
  54. You can use the extension manager to find extensions for JupyterLab. To discovery
  55. freely among the currently available extensions, expand the "Discovery" section.
  56. This triggers a search for all JupyterLab extensions on the NPM registry, and
  57. the results are listed according to the `registry's sort order
  58. <https://docs.npmjs.com/searching-for-and-choosing-packages-to-download#package-search-rank-criteria>`__.
  59. An exception to this sort order is that extensions released by the Jupyter
  60. organization are always placed first. These extensions are distinguished by
  61. a small Jupyter icon next to their name.
  62. .. image:: images/extension_manager_discover.png
  63. :align: center
  64. :class: jp-screenshot
  65. :alt: Screenshot showing the discovery extension listing.
  66. Alternatively, you can limit your discovery by using the search bar. This
  67. performs a free-text search of JupyterLab extensions on the NPM registry.
  68. .. image:: images/extension_manager_search.png
  69. :align: center
  70. :class: jp-screenshot
  71. :alt: Screenshot showing an example search result
  72. Installing an Extension
  73. ^^^^^^^^^^^^^^^^^^^^^^^
  74. Once you have found an extension that you think is interesting, install
  75. it by clicking the "Install" button of the extension list entry.
  76. .. danger::
  77. Installing an extension allows it to execute arbitrary code on the
  78. server, kernel, and in the client's browser. You should therefore
  79. avoid installing extensions you do not trust, and watch out for
  80. any extensions trying to masquerade as a trusted extension.
  81. A short while after starting the install of an extension, a drop-down should
  82. appear under the search bar indicating that the extension has been
  83. downloaded, but that a rebuild is needed to complete the installation.
  84. .. image:: images/extension_manager_rebuild.png
  85. :align: center
  86. :class: jp-screenshot
  87. :alt: Screenshot showing the rebuild indicator
  88. If you want to install/uninstall other extensions as well, you can ignore
  89. the rebuild notice until you have made all the changes you want. Once satisfied,
  90. click the 'Rebuild' button to start a rebuild in the background.
  91. Once the rebuild completes, a dialog will pop up, indicating that a reload of
  92. the page is needed in order to load the latest build into the browser.
  93. If you ignore the rebuild notice by mistake, simply refresh your browser
  94. window to trigger a new rebuild check.
  95. Disabling Rebuild Checks
  96. ~~~~~~~~~~~~~~~~~~~~~~~~
  97. In some cases, such as automated testing, you may wish to disable the startup
  98. rebuild checks altogether. This can be achieved through setting ``buildCheck``
  99. and ``buildAvailable`` in ``jupyter_notebook_config.json`` (or ``.py`` equivalent)
  100. in any of the ``config`` locations returned by ``jupyter --paths``.
  101. .. code:: json
  102. {
  103. "LabApp": {
  104. "tornado_settings": {
  105. "page_config_data": {
  106. "buildCheck": false,
  107. "buildAvailable": false,
  108. }
  109. }
  110. }
  111. }
  112. Managing Installed Extensions
  113. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  114. When there are some installed extensions, they will be shown in the "Installed"
  115. section. These can then be uninstalled or disabled. Disabling an extension will
  116. prevent it from being activated, but without rebuilding the application.
  117. Companion packages
  118. ^^^^^^^^^^^^^^^^^^
  119. During installation of an extension, JupyterLab will inspect the package
  120. metadata for any
  121. :ref:`instructions on companion packages <ext-author-companion-packages>`.
  122. Companion packages can be:
  123. - Notebook server extensions (or any other packages that need to be
  124. installed on the Notebook server).
  125. - Kernel packages. An example of companion packages for the
  126. kernel are Jupyter Widget packages, like the `ipywidgets <https://ipywidgets.readthedocs.io/en/stable>`__
  127. Python package for the
  128. `@jupyter-widgets/jupyterlab-manager package <https://www.npmjs.com/package/@jupyter-widgets/jupyterlab-manager>`__.
  129. If JupyterLab finds instructions for companion packages, it will present
  130. a dialog to notify you about these. These are informational only, and it
  131. will be up to you to take these into account or not.
  132. Using the Terminal
  133. ~~~~~~~~~~~~~~~~~~~~~
  134. Another way of managing your extensions is from the terminal on the server,
  135. using the ``jupyter labextension`` entry point. In general, a simple help text
  136. is available by typing ``jupyter labextension --help``.
  137. Installing Extensions
  138. ^^^^^^^^^^^^^^^^^^^^^
  139. You can install new extensions into the application
  140. using the command:
  141. .. code:: bash
  142. jupyter labextension install my-extension
  143. where ``my-extension`` is the name of a valid JupyterLab extension npm package
  144. on `npm <https://www.npmjs.com>`__. Use the ``my-extension@version``
  145. syntax to install a specific version of an extension, for example:
  146. .. code:: bash
  147. jupyter labextension install my-extension@1.2.3
  148. You can also install an extension that is not uploaded to npm, i.e.,
  149. ``my-extension`` can be a local directory containing the extension, a gzipped
  150. tarball, or a URL to a gzipped tarball.
  151. We encourage extension authors to add the ``jupyterlab-extension``
  152. GitHub topic to any repository with a JupyterLab extension to facilitate
  153. discovery. You can see a list of extensions by searching GitHub for the
  154. `jupyterlab-extension <https://github.com/search?utf8=%E2%9C%93&q=topic%3Ajupyterlab-extension&type=Repositories>`__
  155. topic.
  156. You can list the currently installed extensions by running the command:
  157. .. code:: bash
  158. jupyter labextension list
  159. Uninstall an extension by running the command:
  160. .. code:: bash
  161. jupyter labextension uninstall my-extension
  162. where ``my-extension`` is the name of the extension, as printed in the
  163. extension list. You can also uninstall core extensions using this
  164. command (you can always re-install core extensions later).
  165. Installing and uninstalling extensions can take some time, as they are
  166. downloaded, bundled with the core extensions, and the whole application
  167. is rebuilt. You can install/uninstall more than one extension in the
  168. same command by listing their names after the ``install`` command.
  169. If you are installing/uninstalling several extensions in several stages,
  170. you may want to defer rebuilding the application by including the flag
  171. ``--no-build`` in the install/uninstall step. Once you are ready to
  172. rebuild, you can run the command:
  173. .. code:: bash
  174. jupyter lab build
  175. **Note**
  176. If using Windows, you may encounter a `FileNotFoundError` due to the default PATH length on
  177. Windows. Node modules are stored in a nested file structure, so the path can get quite
  178. long. If you have administrative access and are on Windows 8 or 10, you can update the
  179. registry setting using these instructions: https://stackoverflow.com/a/37528731.
  180. Disabling Extensions
  181. ^^^^^^^^^^^^^^^^^^^^
  182. You can disable specific JupyterLab extensions (including core
  183. extensions) without rebuilding the application by running the command:
  184. .. code:: bash
  185. jupyter labextension disable my-extension
  186. This will prevent the extension from loading in the browser, but does not
  187. require a rebuild.
  188. You can re-enable an extension using the command:
  189. .. code:: bash
  190. jupyter labextension enable my-extension
  191. Advanced Usage
  192. ~~~~~~~~~~~~~~
  193. Any information that JupyterLab persists is stored in its application directory,
  194. including settings and built assets.
  195. This is separate from where the Python package is installed (like in ``site_packages``)
  196. so that the install directory is immutable.
  197. The application directory can be overridden using ``--app-dir`` in
  198. any of the JupyterLab commands, or by setting the ``JUPYTERLAB_DIR``
  199. environment variable. If not specified, it will default to
  200. ``<sys-prefix>/share/jupyter/lab``, where ``<sys-prefix>`` is the
  201. site-specific directory prefix of the current Python environment. You
  202. can query the current application path by running ``jupyter lab path``.
  203. Note that the application directory is expected to contain the JupyterLab
  204. static assets (e.g. `static/index.html`). If JupyterLab is launched
  205. and the static assets are not present, it will display an error in the console and in the browser.
  206. JupyterLab Build Process
  207. ^^^^^^^^^^^^^^^^^^^^^^^^
  208. To rebuild the app directory, run ``jupyter lab build``. By default, the
  209. ``jupyter labextension install`` command builds the application, so you
  210. typically do not need to call ``build`` directly.
  211. Building consists of:
  212. - Populating the ``staging/`` directory using template files
  213. - Handling any locally installed packages
  214. - Ensuring all installed assets are available
  215. - Bundling the assets
  216. - Copying the bundled assets to the ``static`` directory
  217. Note that building will always use the latest JavaScript packages that meet
  218. the dependency requirements of JupyterLab itself and any installed extensions.
  219. If you wish to run JupyterLab with the set of pinned requirements that was
  220. shipped with the Python package, you can launch as
  221. ``jupyter lab --core-mode``.
  222. **Note**
  223. The build process uses a specific ``yarn`` version with a default working
  224. combination of npm packages stored in a ``yarn.lock`` file shipped with
  225. JupyterLab. Those package source urls point to the default yarn registry.
  226. But if you defined your own yarn registry in yarn configuration, the
  227. default yarn registry will be replaced by your custom registry.
  228. If then you switch back to the default yarn registry, you will need to
  229. clean your ``staging`` folder before building:
  230. .. code:: bash
  231. jupyter lab clean
  232. jupyter lab build
  233. JupyterLab Application Directory
  234. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  235. The JupyterLab application directory contains the subdirectories
  236. ``extensions``, ``schemas``, ``settings``, ``staging``, ``static``, and
  237. ``themes``. The default application directory mirrors the location where
  238. JupyterLab was installed. For example, in a conda environment, it is in
  239. ``<conda_root>/envs/<env_name>/share/jupyter/lab``. The directory can be
  240. overridden by setting a ``JUPYTERLAB_DIR`` environment variable.
  241. It is not recommended to install JupyterLab in a root location (on Unix-like
  242. systems). Instead, use a conda environment or ``pip install --user jupyterlab``
  243. so that the application directory ends up in a writable location.
  244. Note: this folder location and semantics do *not* follow the standard Jupyter
  245. config semantics because we need to build a single unified application, and the
  246. default config location for Jupyter is at the user level (user's home directory).
  247. By explicitly using a directory alongside the currently installed JupyterLab,
  248. we can ensure better isolation between conda or other virtual environments.
  249. .. _extensions-1:
  250. extensions
  251. ''''''''''
  252. The ``extensions`` directory has the packed tarballs for each of the
  253. installed extensions for the app. If the application directory is not
  254. the same as the ``sys-prefix`` directory, the extensions installed in
  255. the ``sys-prefix`` directory will be used in the app directory. If an
  256. extension is installed in the app directory that exists in the
  257. ``sys-prefix`` directory, it will shadow the ``sys-prefix`` version.
  258. Uninstalling an extension will first uninstall the shadowed extension,
  259. and then attempt to uninstall the ``sys-prefix`` version if called
  260. again. If the ``sys-prefix`` version cannot be uninstalled, its plugins
  261. can still be ignored using ``ignoredPackages`` metadata in ``settings``.
  262. schemas
  263. '''''''
  264. The ``schemas`` directory contains `JSON
  265. Schemas <http://json-schema.org/>`__ that describe the settings used by
  266. individual extensions. Users may edit these settings using the
  267. JupyterLab Settings Editor.
  268. settings
  269. ''''''''
  270. The ``settings`` directory may contain ``page_config.json``, ``overrides.json``, and/or
  271. ``build_config.json`` files, depending on which configurations are
  272. set on your system.
  273. .. _page_configjson:
  274. page_config.json
  275. The ``page_config.json`` data is used to provide configuration data to the
  276. application environment.
  277. The following configurations may be present in this file:
  278. 1. ``terminalsAvailable`` identifies whether a terminal (i.e. ``bash/tsch``
  279. on Mac/Linux OR ``PowerShell`` on Windows) is available to be launched
  280. via the Launcher. (This configuration was predominantly required for
  281. Windows prior to PowerShell access being enabled in Jupyter Lab.) The
  282. value for this field is a Boolean: ``true`` or ``false``.
  283. 2. ``disabledExtensions`` controls which extensions should not load at all.
  284. 3. ``deferredExtensions`` controls which extensions should not load until
  285. they are required by something, irrespective of whether they set
  286. ``autoStart`` to ``true``.
  287. The value for the ``disabledExtensions`` and ``deferredExtensions`` fields
  288. are an array of strings. The following sequence of checks are performed
  289. against the patterns in ``disabledExtensions`` and ``deferredExtensions``.
  290. - If an identical string match occurs between a config value and a
  291. package name (e.g., ``"@jupyterlab/apputils-extension"``), then the
  292. entire package is disabled (or deferred).
  293. - If the string value is compiled as a regular expression and tests
  294. positive against a package name (e.g.,
  295. ``"disabledExtensions": ["@jupyterlab/apputils*$"]``), then the
  296. entire package is disabled (or deferred).
  297. - If an identical string match occurs between a config value and an
  298. individual plugin ID within a package (e.g.,
  299. ``"disabledExtensions": ["@jupyterlab/apputils-extension:settings"]``),
  300. then that specific plugin is disabled (or deferred).
  301. - If the string value is compiled as a regular expression and tests
  302. positive against an individual plugin ID within a package (e.g.,
  303. ``"disabledExtensions": ["^@jupyterlab/apputils-extension:set.*$"]``),
  304. then that specific plugin is disabled (or deferred).
  305. An example of a ``page_config.json`` file is:
  306. .. code:: json
  307. {
  308. "disabledExtensions": [
  309. "@jupyterlab/toc"
  310. ],
  311. "terminalsAvailable": false
  312. }
  313. .. _overridesjson:
  314. overrides.json
  315. You can override default values of the extension settings by
  316. defining new default values in an ``overrides.json`` file.
  317. So for example, if you would like
  318. to set the dark theme by default instead of the light one, an
  319. ``overrides.json`` file containing the following lines needs to be
  320. added in the application settings directory (by default this is the
  321. ``share/jupyter/lab/settings`` folder).
  322. .. code:: json
  323. {
  324. "@jupyterlab/apputils-extension:themes": {
  325. "theme": "JupyterLab Dark"
  326. }
  327. }
  328. .. _build_configjson:
  329. build_config.json
  330. The ``build_config.json`` file is used to track the local directories
  331. that have been installed using
  332. ``jupyter labextension install <directory>``, as well as core extensions
  333. that have been explicitly uninstalled. An example of a
  334. ``build_config.json`` file is:
  335. .. code:: json
  336. {
  337. "uninstalled_core_extensions": [
  338. "@jupyterlab/markdownwidget-extension"
  339. ],
  340. "local_extensions": {
  341. "@jupyterlab/python-tests": "/path/to/my/extension"
  342. }
  343. }
  344. staging and static
  345. ''''''''''''''''''
  346. The ``static`` directory contains the assets that will be loaded by the
  347. JupyterLab application. The ``staging`` directory is used to create the
  348. build and then populate the ``static`` directory.
  349. Running ``jupyter lab`` will attempt to run the ``static`` assets in the
  350. application directory if they exist. You can run
  351. ``jupyter lab --core-mode`` to load the core JupyterLab application
  352. (i.e., the application without any extensions) instead.
  353. themes
  354. ''''''
  355. The ``themes`` directory contains assets (such as CSS and icons) for
  356. JupyterLab theme extensions.
  357. JupyterLab User Settings Directory
  358. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  359. The user settings directory contains the user-level settings for Jupyter extensions.
  360. By default, the location is ``~/.jupyter/lab/user-settings/``, where ``~`` is the user's home directory. This folder is not in the JupyterLab application directory,
  361. because these settings are typically shared across Python environments.
  362. The location can be modified using the ``JUPYTERLAB_SETTINGS_DIR`` environment variable. Files are automatically created in this folder as modifications are made
  363. to settings from the JupyterLab UI. They can also be manually created. The files
  364. follow the pattern of ``<package_name>/<extension_name>.jupyterlab-settings``.
  365. They are JSON files with optional comments. These values take precedence over the
  366. default values given by the extensions, but can be overridden by an ``overrides.json``
  367. file in the application's settings directory.
  368. JupyterLab Workspaces Directory
  369. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  370. JupyterLab sessions always reside in a workspace. Workspaces contain the state
  371. of JupyterLab: the files that are currently open, the layout of the application
  372. areas and tabs, etc. When the page is refreshed, the workspace is restored.
  373. By default, the location is ``~/.jupyter/lab/workspacess/``, where ``~`` is the user's home directory. This folder is not in the JupyterLab application directory,
  374. because these files are typically shared across Python environments.
  375. The location can be modified using the ``JUPYTERLAB_WORKSPACES_DIR`` environment variable. These files can be imported and exported to create default "profiles",
  376. using the :ref:`workspace command line tool <url-workspaces-cli>`.