extensions.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. .. contents:: Table of contents
  13. :local:
  14. :depth: 1
  15. Starting in JupyterLab 3.0, extensions are typically ``pip`` or ``conda``
  16. packages that are dynamically loaded by the application (no more build step). You can search using ``pip search "jupyterlab extension"`` to find extensions. For information about developing extensions,
  17. see the :ref:`developer documentation <developer_extensions>`.
  18. Once an extension is installed, you can refresh a running application
  19. or launch a new application to use the new extension.
  20. .. note::
  21. If you are a JupyterLab extension developer, please note that the extension
  22. developer API is not stable and will evolve in the near future.
  23. Built-in Extensions
  24. --------------------
  25. In order to install JupyterLab built in (bundled) extensions, you need to have `Node.js
  26. <https://nodejs.org/>`__ installed.
  27. If you use ``conda`` with ``conda-forge`` packages, you can get it with:
  28. .. code:: bash
  29. conda install -c conda-forge nodejs
  30. If you use ``conda`` with default Anaconda packages (i.e., you don't normally use ``conda-forge``), you should install nodejs with ``conda install nodejs`` instead.
  31. If you use `Homebrew <https://brew.sh/>`__ on Mac OS X:
  32. .. code:: bash
  33. brew install node
  34. You can also download Node.js from the `Node.js website <https://nodejs.org/>`__ and
  35. install it directly.
  36. Disabling Rebuild Checks
  37. ~~~~~~~~~~~~~~~~~~~~~~~~
  38. In some cases, such as automated testing, you may wish to disable the startup
  39. rebuild checks altogether. This can be achieved through setting ``buildCheck``
  40. and ``buildAvailable`` in ``jupyter_notebook_config.json`` (or ``.py`` equivalent)
  41. in any of the ``config`` locations returned by ``jupyter --paths``.
  42. .. code:: json
  43. {
  44. "LabApp": {
  45. "tornado_settings": {
  46. "page_config_data": {
  47. "buildCheck": false,
  48. "buildAvailable": false,
  49. }
  50. }
  51. }
  52. }
  53. Using the Terminal
  54. ~~~~~~~~~~~~~~~~~~~~~
  55. Another way of managing your extensions is from the terminal on the server,
  56. using the ``jupyter labextension`` entry point. In general, a simple help text
  57. is available by typing ``jupyter labextension --help``.
  58. Installing Built-in Extensions
  59. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  60. You can install new extensions into the application
  61. using the command:
  62. .. code:: bash
  63. jupyter labextension install my-extension
  64. where ``my-extension`` is the name of a valid JupyterLab extension npm package
  65. on `npm <https://www.npmjs.com>`__. Use the ``my-extension@version``
  66. syntax to install a specific version of an extension, for example:
  67. .. code:: bash
  68. jupyter labextension install my-extension@1.2.3
  69. You can also install an extension that is not uploaded to npm, i.e.,
  70. ``my-extension`` can be a local directory containing the extension, a gzipped
  71. tarball, or a URL to a gzipped tarball.
  72. We encourage extension authors to add the ``jupyterlab-extension``
  73. GitHub topic to any repository with a JupyterLab extension to facilitate
  74. discovery. You can see a list of extensions by searching GitHub for the
  75. `jupyterlab-extension <https://github.com/search?utf8=%E2%9C%93&q=topic%3Ajupyterlab-extension&type=Repositories>`__
  76. topic.
  77. You can list the currently installed extensions by running the command:
  78. .. code:: bash
  79. jupyter labextension list
  80. Uninstall an extension by running the command:
  81. .. code:: bash
  82. jupyter labextension uninstall my-extension
  83. where ``my-extension`` is the name of the extension, as printed in the
  84. extension list. You can also uninstall core extensions using this
  85. command (you can always re-install core extensions later).
  86. Installing and uninstalling extensions can take some time, as they are
  87. downloaded, bundled with the core extensions, and the whole application
  88. is rebuilt. You can install/uninstall more than one extension in the
  89. same command by listing their names after the ``install`` command.
  90. If you are installing/uninstalling several extensions in several stages,
  91. you may want to defer rebuilding the application by including the flag
  92. ``--no-build`` in the install/uninstall step. Once you are ready to
  93. rebuild, you can run the command:
  94. .. code:: bash
  95. jupyter lab build
  96. **Note**
  97. If using Windows, you may encounter a `FileNotFoundError` due to the default PATH length on
  98. Windows. Node modules are stored in a nested file structure, so the path can get quite
  99. long. If you have administrative access and are on Windows 8 or 10, you can update the
  100. registry setting using these instructions: https://stackoverflow.com/a/37528731.
  101. Disabling Extensions
  102. ^^^^^^^^^^^^^^^^^^^^
  103. You can disable specific JupyterLab extensions (including core
  104. extensions) without rebuilding the application by running the command:
  105. .. code:: bash
  106. jupyter labextension disable my-extension
  107. This will prevent the extension from loading in the browser, but does not
  108. require a rebuild.
  109. You can re-enable an extension using the command:
  110. .. code:: bash
  111. jupyter labextension enable my-extension
  112. Advanced Usage
  113. ~~~~~~~~~~~~~~
  114. Any information that JupyterLab persists is stored in its application directory,
  115. including settings and built assets.
  116. This is separate from where the Python package is installed (like in ``site_packages``)
  117. so that the install directory is immutable.
  118. The application directory can be overridden using ``--app-dir`` in
  119. any of the JupyterLab commands, or by setting the ``JUPYTERLAB_DIR``
  120. environment variable. If not specified, it will default to
  121. ``<sys-prefix>/share/jupyter/lab``, where ``<sys-prefix>`` is the
  122. site-specific directory prefix of the current Python environment. You
  123. can query the current application path by running ``jupyter lab path``.
  124. Note that the application directory is expected to contain the JupyterLab
  125. static assets (e.g. `static/index.html`). If JupyterLab is launched
  126. and the static assets are not present, it will display an error in the console and in the browser.
  127. JupyterLab Build Process
  128. ^^^^^^^^^^^^^^^^^^^^^^^^
  129. To rebuild the app directory, run ``jupyter lab build``. By default, the
  130. ``jupyter labextension install`` command builds the application, so you
  131. typically do not need to call ``build`` directly.
  132. Building consists of:
  133. - Populating the ``staging/`` directory using template files
  134. - Handling any locally installed packages
  135. - Ensuring all installed assets are available
  136. - Bundling the assets
  137. - Copying the bundled assets to the ``static`` directory
  138. Note that building will always use the latest JavaScript packages that meet
  139. the dependency requirements of JupyterLab itself and any installed extensions.
  140. If you wish to run JupyterLab with the set of pinned requirements that was
  141. shipped with the Python package, you can launch as
  142. ``jupyter lab --core-mode``.
  143. **Note**
  144. The build process uses a specific ``yarn`` version with a default working
  145. combination of npm packages stored in a ``yarn.lock`` file shipped with
  146. JupyterLab. Those package source urls point to the default yarn registry.
  147. But if you defined your own yarn registry in yarn configuration, the
  148. default yarn registry will be replaced by your custom registry.
  149. If then you switch back to the default yarn registry, you will need to
  150. clean your ``staging`` folder before building:
  151. .. code:: bash
  152. jupyter lab clean
  153. jupyter lab build
  154. JupyterLab Application Directory
  155. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  156. The JupyterLab application directory contains the subdirectories
  157. ``extensions``, ``schemas``, ``settings``, ``staging``, ``static``, and
  158. ``themes``. The default application directory mirrors the location where
  159. JupyterLab was installed. For example, in a conda environment, it is in
  160. ``<conda_root>/envs/<env_name>/share/jupyter/lab``. The directory can be
  161. overridden by setting a ``JUPYTERLAB_DIR`` environment variable.
  162. It is not recommended to install JupyterLab in a root location (on Unix-like
  163. systems). Instead, use a conda environment or ``pip install --user jupyterlab``
  164. so that the application directory ends up in a writable location.
  165. Note: this folder location and semantics do *not* follow the standard Jupyter
  166. config semantics because we need to build a single unified application, and the
  167. default config location for Jupyter is at the user level (user's home directory).
  168. By explicitly using a directory alongside the currently installed JupyterLab,
  169. we can ensure better isolation between conda or other virtual environments.
  170. .. _extensions-1:
  171. extensions
  172. ''''''''''
  173. The ``extensions`` directory has the packed tarballs for each of the
  174. installed extensions for the app. If the application directory is not
  175. the same as the ``sys-prefix`` directory, the extensions installed in
  176. the ``sys-prefix`` directory will be used in the app directory. If an
  177. extension is installed in the app directory that exists in the
  178. ``sys-prefix`` directory, it will shadow the ``sys-prefix`` version.
  179. Uninstalling an extension will first uninstall the shadowed extension,
  180. and then attempt to uninstall the ``sys-prefix`` version if called
  181. again. If the ``sys-prefix`` version cannot be uninstalled, its plugins
  182. can still be ignored using ``ignoredPackages`` metadata in ``settings``.
  183. schemas
  184. '''''''
  185. The ``schemas`` directory contains `JSON
  186. Schemas <http://json-schema.org/>`__ that describe the settings used by
  187. individual extensions. Users may edit these settings using the
  188. JupyterLab Settings Editor.
  189. settings
  190. ''''''''
  191. The ``settings`` directory may contain ``page_config.json``, ``overrides.json``, and/or
  192. ``build_config.json`` files, depending on which configurations are
  193. set on your system.
  194. .. _page_configjson:
  195. page_config.json
  196. The ``page_config.json`` data is used to provide configuration data to the
  197. application environment.
  198. The following configurations may be present in this file:
  199. 1. ``terminalsAvailable`` identifies whether a terminal (i.e. ``bash/tsch``
  200. on Mac/Linux OR ``PowerShell`` on Windows) is available to be launched
  201. via the Launcher. (This configuration was predominantly required for
  202. Windows prior to PowerShell access being enabled in Jupyter Lab.) The
  203. value for this field is a Boolean: ``true`` or ``false``.
  204. 2. ``disabledExtensions`` controls which extensions should not load at all.
  205. 3. ``deferredExtensions`` controls which extensions should not load until
  206. they are required by something, irrespective of whether they set
  207. ``autoStart`` to ``true``.
  208. The value for the ``disabledExtensions`` and ``deferredExtensions`` fields
  209. are an array of strings. The following sequence of checks are performed
  210. against the patterns in ``disabledExtensions`` and ``deferredExtensions``.
  211. - If an identical string match occurs between a config value and a
  212. package name (e.g., ``"@jupyterlab/apputils-extension"``), then the
  213. entire package is disabled (or deferred).
  214. - If the string value is compiled as a regular expression and tests
  215. positive against a package name (e.g.,
  216. ``"disabledExtensions": ["@jupyterlab/apputils*$"]``), then the
  217. entire package is disabled (or deferred).
  218. - If an identical string match occurs between a config value and an
  219. individual plugin ID within a package (e.g.,
  220. ``"disabledExtensions": ["@jupyterlab/apputils-extension:settings"]``),
  221. then that specific plugin is disabled (or deferred).
  222. - If the string value is compiled as a regular expression and tests
  223. positive against an individual plugin ID within a package (e.g.,
  224. ``"disabledExtensions": ["^@jupyterlab/apputils-extension:set.*$"]``),
  225. then that specific plugin is disabled (or deferred).
  226. An example of a ``page_config.json`` file is:
  227. .. code:: json
  228. {
  229. "disabledExtensions": [
  230. "@jupyterlab/toc"
  231. ],
  232. "terminalsAvailable": false
  233. }
  234. .. _overridesjson:
  235. overrides.json
  236. You can override default values of the extension settings by
  237. defining new default values in an ``overrides.json`` file.
  238. So for example, if you would like
  239. to set the dark theme by default instead of the light one, an
  240. ``overrides.json`` file containing the following lines needs to be
  241. added in the application settings directory (by default this is the
  242. ``share/jupyter/lab/settings`` folder).
  243. .. code:: json
  244. {
  245. "@jupyterlab/apputils-extension:themes": {
  246. "theme": "JupyterLab Dark"
  247. }
  248. }
  249. .. _build_configjson:
  250. build_config.json
  251. The ``build_config.json`` file is used to track the local directories
  252. that have been installed using
  253. ``jupyter labextension install <directory>``, as well as core extensions
  254. that have been explicitly uninstalled. An example of a
  255. ``build_config.json`` file is:
  256. .. code:: json
  257. {
  258. "uninstalled_core_extensions": [
  259. "@jupyterlab/markdownwidget-extension"
  260. ],
  261. "local_extensions": {
  262. "@jupyterlab/python-tests": "/path/to/my/extension"
  263. }
  264. }
  265. staging and static
  266. ''''''''''''''''''
  267. The ``static`` directory contains the assets that will be loaded by the
  268. JupyterLab application. The ``staging`` directory is used to create the
  269. build and then populate the ``static`` directory.
  270. Running ``jupyter lab`` will attempt to run the ``static`` assets in the
  271. application directory if they exist. You can run
  272. ``jupyter lab --core-mode`` to load the core JupyterLab application
  273. (i.e., the application without any extensions) instead.
  274. themes
  275. ''''''
  276. The ``themes`` directory contains assets (such as CSS and icons) for
  277. JupyterLab theme extensions.
  278. JupyterLab User Settings Directory
  279. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  280. The user settings directory contains the user-level settings for Jupyter extensions.
  281. 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,
  282. because these settings are typically shared across Python environments.
  283. The location can be modified using the ``JUPYTERLAB_SETTINGS_DIR`` environment variable. Files are automatically created in this folder as modifications are made
  284. to settings from the JupyterLab UI. They can also be manually created. The files
  285. follow the pattern of ``<package_name>/<extension_name>.jupyterlab-settings``.
  286. They are JSON files with optional comments. These values take precedence over the
  287. default values given by the extensions, but can be overridden by an ``overrides.json``
  288. file in the application's settings directory.
  289. JupyterLab Workspaces Directory
  290. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  291. JupyterLab sessions always reside in a workspace. Workspaces contain the state
  292. of JupyterLab: the files that are currently open, the layout of the application
  293. areas and tabs, etc. When the page is refreshed, the workspace is restored.
  294. By default, the location is ``~/.jupyter/lab/workspaces/``, where ``~`` is the user's home directory. This folder is not in the JupyterLab application directory,
  295. because these files are typically shared across Python environments.
  296. The location can be modified using the ``JUPYTERLAB_WORKSPACES_DIR`` environment variable. These files can be imported and exported to create default "profiles",
  297. using the :ref:`workspace command line tool <url-workspaces-cli>`.