extensions.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. Managing Installed Extensions
  96. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  97. When there are some installed extensions, they will be shown in the "Installed"
  98. section. These can then be uninstalled or disabled. Disabling an extension will
  99. prevent it from being activated, but without rebuilding the application.
  100. Companion packages
  101. ^^^^^^^^^^^^^^^^^^
  102. During installation of an extension, JupyterLab will inspect the package
  103. metadata for any
  104. :ref:`instructions on companion packages <ext-author-companion-packages>`.
  105. Companion packages can be:
  106. - Notebook server extensions (or any other packages that need to be
  107. installed on the Notebook server).
  108. - Kernel packages. An example of companion packages for the
  109. kernel are Jupyter Widget packages, like the `ipywidgets <https://ipywidgets.readthedocs.io/en/stable>`__
  110. Python package for the
  111. `@jupyter-widgets/jupyterlab-manager package <https://www.npmjs.com/package/@jupyter-widgets/jupyterlab-manager>`__.
  112. If JupyterLab finds instructions for companion packages, it will present
  113. a dialog to notify you about these. These are informational only, and it
  114. will be up to you to take these into account or not.
  115. Using the Terminal
  116. ~~~~~~~~~~~~~~~~~~~~~
  117. Another way of managing your extensions is from the terminal on the server,
  118. using the ``jupyter labextension`` entry point. In general, a simple help text
  119. is available by typing ``jupyter labextension --help``.
  120. Installing Extensions
  121. ^^^^^^^^^^^^^^^^^^^^^
  122. You can install new extensions into the application
  123. using the command:
  124. .. code:: bash
  125. jupyter labextension install my-extension
  126. where ``my-extension`` is the name of a valid JupyterLab extension npm package
  127. on `npm <https://www.npmjs.com>`__. Use the ``my-extension@version``
  128. syntax to install a specific version of an extension, for example:
  129. .. code:: bash
  130. jupyter labextension install my-extension@1.2.3
  131. You can also install an extension that is not uploaded to npm, i.e.,
  132. ``my-extension`` can be a local directory containing the extension, a gzipped
  133. tarball, or a URL to a gzipped tarball.
  134. We encourage extension authors to add the ``jupyterlab-extension``
  135. GitHub topic to any repository with a JupyterLab extension to facilitate
  136. discovery. You can see a list of extensions by searching GitHub for the
  137. `jupyterlab-extension <https://github.com/search?utf8=%E2%9C%93&q=topic%3Ajupyterlab-extension&type=Repositories>`__
  138. topic.
  139. You can list the currently installed extensions by running the command:
  140. .. code:: bash
  141. jupyter labextension list
  142. Uninstall an extension by running the command:
  143. .. code:: bash
  144. jupyter labextension uninstall my-extension
  145. where ``my-extension`` is the name of the extension, as printed in the
  146. extension list. You can also uninstall core extensions using this
  147. command (you can always re-install core extensions later).
  148. Installing and uninstalling extensions can take some time, as they are
  149. downloaded, bundled with the core extensions, and the whole application
  150. is rebuilt. You can install/uninstall more than one extension in the
  151. same command by listing their names after the ``install`` command.
  152. If you are installing/uninstalling several extensions in several stages,
  153. you may want to defer rebuilding the application by including the flag
  154. ``--no-build`` in the install/uninstall step. Once you are ready to
  155. rebuild, you can run the command:
  156. .. code:: bash
  157. jupyter lab build
  158. **Note**
  159. If using Windows, you may encounter a `FileNotFoundError` due to the default PATH length on
  160. Windows. Node modules are stored in a nested file structure, so the path can get quite
  161. long. If you have administrative access and are on Windows 8 or 10, you can update the
  162. registry setting using these instructions: https://stackoverflow.com/a/37528731.
  163. Disabling Extensions
  164. ^^^^^^^^^^^^^^^^^^^^
  165. You can disable specific JupyterLab extensions (including core
  166. extensions) without rebuilding the application by running the command:
  167. .. code:: bash
  168. jupyter labextension disable my-extension
  169. This will prevent the extension from loading in the browser, but does not
  170. require a rebuild.
  171. You can re-enable an extension using the command:
  172. .. code:: bash
  173. jupyter labextension enable my-extension
  174. Advanced Usage
  175. ~~~~~~~~~~~~~~
  176. Any information that JupyterLab persists is stored in its application directory,
  177. including settings and built assets.
  178. This is separate from where the Python package is installed (like in ``site_packages``)
  179. so that the install directory is immutable.
  180. The application directory can be overridden using ``--app-dir`` in
  181. any of the JupyterLab commands, or by setting the ``JUPYTERLAB_DIR``
  182. environment variable. If not specified, it will default to
  183. ``<sys-prefix>/share/jupyter/lab``, where ``<sys-prefix>`` is the
  184. site-specific directory prefix of the current Python environment. You
  185. can query the current application path by running ``jupyter lab path``.
  186. Note that the application directory is expected to contain the JupyterLab
  187. static assets (e.g. `static/index.html`). If JupyterLab is launched
  188. and the static assets are not present, it will display an error in the console and in the browser.
  189. JupyterLab Build Process
  190. ^^^^^^^^^^^^^^^^^^^^^^^^
  191. To rebuild the app directory, run ``jupyter lab build``. By default, the
  192. ``jupyter labextension install`` command builds the application, so you
  193. typically do not need to call ``build`` directly.
  194. Building consists of:
  195. - Populating the ``staging/`` directory using template files
  196. - Handling any locally installed packages
  197. - Ensuring all installed assets are available
  198. - Bundling the assets
  199. - Copying the bundled assets to the ``static`` directory
  200. Note that building will always use the latest JavaScript packages that meet
  201. the dependency requirements of JupyterLab itself and any installed extensions.
  202. If you wish to run JupyterLab with the set of pinned requirements that was
  203. shipped with the Python package, you can launch as
  204. ``jupyter lab --core-mode``.
  205. JupyterLab Application Directory
  206. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  207. The JupyterLab application directory contains the subdirectories
  208. ``extensions``, ``schemas``, ``settings``, ``staging``, ``static``, and
  209. ``themes``. The default application directory mirrors the location where
  210. JupyterLab was installed. For example, in a conda environment, it is in
  211. ``<conda_root>/envs/<env_name>/share/jupyter/lab``. The directory can be
  212. overridden by setting a ``JUPYTERLAB_DIR`` environment variable.
  213. It is not recommended to install JupyterLab in a root location (on Unix-like
  214. systems). Instead, use a conda environment or ``pip install --user jupyterlab``
  215. so that the application directory ends up in a writable location.
  216. Note: this folder location and semantics do *not* follow the standard Jupyter
  217. config semantics because we need to build a single unified application, and the
  218. default config location for Jupyter is at the user level (user's home directory).
  219. By explicitly using a directory alongside the currently installed JupyterLab,
  220. we can ensure better isolation between conda or other virtual environments.
  221. .. _extensions-1:
  222. extensions
  223. ''''''''''
  224. The ``extensions`` directory has the packed tarballs for each of the
  225. installed extensions for the app. If the application directory is not
  226. the same as the ``sys-prefix`` directory, the extensions installed in
  227. the ``sys-prefix`` directory will be used in the app directory. If an
  228. extension is installed in the app directory that exists in the
  229. ``sys-prefix`` directory, it will shadow the ``sys-prefix`` version.
  230. Uninstalling an extension will first uninstall the shadowed extension,
  231. and then attempt to uninstall the ``sys-prefix`` version if called
  232. again. If the ``sys-prefix`` version cannot be uninstalled, its plugins
  233. can still be ignored using ``ignoredPackages`` metadata in ``settings``.
  234. schemas
  235. '''''''
  236. The ``schemas`` directory contains `JSON
  237. Schemas <http://json-schema.org/>`__ that describe the settings used by
  238. individual extensions. Users may edit these settings using the
  239. JupyterLab Settings Editor.
  240. settings
  241. ''''''''
  242. The ``settings`` directory may contain ``page_config.json``, ``overrides.json``, and/or
  243. ``build_config.json`` files, depending on which configurations are
  244. set on your system.
  245. .. _page_configjson:
  246. page_config.json
  247. The ``page_config.json`` data is used to provide configuration data to the
  248. application environment.
  249. The following configurations may be present in this file:
  250. 1. ``terminalsAvailable`` identifies whether a terminal (i.e. ``bash/tsch``
  251. on Mac/Linux OR ``PowerShell`` on Windows) is available to be launched
  252. via the Launcher. (This configuration was predominantly required for
  253. Windows prior to PowerShell access being enabled in Jupyter Lab.) The
  254. value for this field is a Boolean: ``true`` or ``false``.
  255. 2. ``disabledExtensions`` controls which extensions should not load at all.
  256. 3. ``deferredExtensions`` controls which extensions should not load until
  257. they are required by something, irrespective of whether they set
  258. ``autoStart`` to ``true``.
  259. The value for the ``disabledExtensions`` and ``deferredExtensions`` fields
  260. are an array of strings. The following sequence of checks are performed
  261. against the patterns in ``disabledExtensions`` and ``deferredExtensions``.
  262. - If an identical string match occurs between a config value and a
  263. package name (e.g., ``"@jupyterlab/apputils-extension"``), then the
  264. entire package is disabled (or deferred).
  265. - If the string value is compiled as a regular expression and tests
  266. positive against a package name (e.g.,
  267. ``"disabledExtensions": ["@jupyterlab/apputils*$"]``), then the
  268. entire package is disabled (or deferred).
  269. - If an identical string match occurs between a config value and an
  270. individual plugin ID within a package (e.g.,
  271. ``"disabledExtensions": ["@jupyterlab/apputils-extension:settings"]``),
  272. then that specific plugin is disabled (or deferred).
  273. - If the string value is compiled as a regular expression and tests
  274. positive against an individual plugin ID within a package (e.g.,
  275. ``"disabledExtensions": ["^@jupyterlab/apputils-extension:set.*$"]``),
  276. then that specific plugin is disabled (or deferred).
  277. An example of a ``page_config.json`` file is:
  278. .. code:: json
  279. {
  280. "disabledExtensions": [
  281. "@jupyterlab/toc"
  282. ],
  283. "terminalsAvailable": false
  284. }
  285. .. _overridesjson:
  286. overrides.json
  287. You can override default values of the extension settings by
  288. defining new default values in an ``overrides.json`` file.
  289. So for example, if you would like
  290. to set the dark theme by default instead of the light one, an
  291. ``overrides.json`` file containing the following lines needs to be
  292. added in the application settings directory (by default this is the
  293. ``share/jupyter/lab/settings`` folder).
  294. .. code:: json
  295. {
  296. "@jupyterlab/apputils-extension:themes": {
  297. "theme": "JupyterLab Dark"
  298. }
  299. }
  300. .. _build_configjson:
  301. build_config.json
  302. The ``build_config.json`` file is used to track the local directories
  303. that have been installed using
  304. ``jupyter labextension install <directory>``, as well as core extensions
  305. that have been explicitly uninstalled. An example of a
  306. ``build_config.json`` file is:
  307. .. code:: json
  308. {
  309. "uninstalled_core_extensions": [
  310. "@jupyterlab/markdownwidget-extension"
  311. ],
  312. "local_extensions": {
  313. "@jupyterlab/python-tests": "/path/to/my/extension"
  314. }
  315. }
  316. staging and static
  317. ''''''''''''''''''
  318. The ``static`` directory contains the assets that will be loaded by the
  319. JuptyerLab application. The ``staging`` directory is used to create the
  320. build and then populate the ``static`` directory.
  321. Running ``jupyter lab`` will attempt to run the ``static`` assets in the
  322. application directory if they exist. You can run
  323. ``jupyter lab --core-mode`` to load the core JupyterLab application
  324. (i.e., the application without any extensions) instead.
  325. themes
  326. ''''''
  327. The ``themes`` directory contains assets (such as CSS and icons) for
  328. JupyterLab theme extensions.
  329. JupyterLab User Settings Directory
  330. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  331. The user settings directory contains the user-level settings for Jupyter extensions.
  332. 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,
  333. because these settings are typically shared across Python environments.
  334. The location can be modified using the ``JUPYTERLAB_SETTINGS_DIR`` environment variable. Files are automatically created in this folder as modifications are made
  335. to settings from the JupyterLab UI. They can also be manually created. The files
  336. follow the pattern of ``<package_name>/<extension_name>.jupyterlab-settings``.
  337. They are JSON files with optional comments. These values take precedence over the
  338. default values given by the extensions, but can be overridden by an ``overrides.json``
  339. file in the application's settings directory.
  340. JupyterLab Workspaces Directory
  341. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  342. JupyterLab sessions always reside in a workspace. Workspaces contain the state
  343. of JupyterLab: the files that are currently open, the layout of the application
  344. areas and tabs, etc. When the page is refreshed, the workspace is restored.
  345. By default, the location is ``~/.jupyter/lab/workspacess/``, where ``~`` is the user's home directory. This folder is not in the JupyterLab application directory,
  346. because these files are typically shared across Python environments.
  347. The location can be modified using the ``JUPYTERLAB_WORKSPACES_DIR`` environment variable. These files can be imported and exported to create default "profiles",
  348. using the :ref:`workspace command line tool <url-workspaces-cli>`.