extensions.rst 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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). There are many
  14. community-developed extensions being built on GitHub. You can search for the
  15. GitHub topic `jupyterlab-extension
  16. <https://github.com/topics/jupyterlab-extension>`__ to find extensions. For
  17. information about developing extensions, see the :ref:`developer documentation
  18. <developer_extensions>`.
  19. .. note::
  20. If you are a JupyterLab extension developer, please note that the extension
  21. developer API is not stable and will evolve in the near future.
  22. In order to install JupyterLab extensions, you need to have `Node.js
  23. <https://nodejs.org/>`__ installed.
  24. If you use ``conda``, you can get it with:
  25. .. code:: bash
  26. conda install -c conda-forge nodejs
  27. If you use `Homebrew <https://brew.sh/>`__ on Mac OS X:
  28. .. code:: bash
  29. brew install node
  30. You can also download Node.js from the `Node.js website <https://nodejs.org/>`__ and
  31. install it directly.
  32. Installing Extensions
  33. ~~~~~~~~~~~~~~~~~~~~~
  34. The base JupyterLab application includes a core set of extensions, which
  35. provide the features described in this user guide (notebook, terminal,
  36. text editor, etc.) You can install new extensions into the application
  37. using the command:
  38. .. code:: bash
  39. jupyter labextension install my-extension
  40. where ``my-extension`` is the name of a valid JupyterLab extension npm package
  41. on `npm <https://www.npmjs.com>`__. Use the ``my-extension@version``
  42. syntax to install a specific version of an extension, for example:
  43. .. code:: bash
  44. jupyter labextension install my-extension@1.2.3
  45. You can also install an extension that is not uploaded to npm, i.e.,
  46. ``my-extension`` can be a local directory containing the extension, a gzipped
  47. tarball, or a URL to a gzipped tarball.
  48. We encourage extension authors to add the ``jupyterlab-extension``
  49. GitHub topic to any repository with a JupyterLab extension to facilitate
  50. discovery. You can see a list of extensions by searching GitHub for the
  51. `jupyterlab-extension <https://github.com/search?utf8=%E2%9C%93&q=topic%3Ajupyterlab-extension&type=Repositories>`__
  52. topic.
  53. You can list the currently installed extensions by running the command:
  54. .. code:: bash
  55. jupyter labextension list
  56. Uninstall an extension by running the command:
  57. .. code:: bash
  58. jupyter labextension uninstall my-extension
  59. where ``my-extension`` is the name of the extension, as printed in the
  60. extension list. You can also uninstall core extensions using this
  61. command (you can always re-install core extensions later).
  62. Installing and uninstalling extensions can take some time, as they are
  63. downloaded, bundled with the core extensions, and the whole application
  64. is rebuilt. You can install/uninstall more than one extension in the
  65. same command by listing their names after the ``install`` command.
  66. If you are installing/uninstalling several extensions in several stages,
  67. you may want to defer rebuilding the application by including the flag
  68. ``--no-build`` in the install/uninstall step. Once you are ready to
  69. rebuild, you can run the command:
  70. .. code:: bash
  71. jupyter lab build
  72. Disabling Extensions
  73. ~~~~~~~~~~~~~~~~~~~~
  74. You can disable specific JupyterLab extensions (including core
  75. extensions) without rebuilding the application by running the command:
  76. .. code:: bash
  77. jupyter labextension disable my-extension
  78. This will prevent the extension from loading in the browser, but does not
  79. require a rebuild.
  80. You can re-enable an extension using the command:
  81. .. code:: bash
  82. jupyter labextension enable my-extension
  83. Advanced Usage
  84. ~~~~~~~~~~~~~~
  85. Any information that JupyterLab persists is stored in its application directory,
  86. including settings and built assets.
  87. This is separate from where the Python package is installed (like in ``site_packages``)
  88. so that the install directory is immutable.
  89. The application directory can be overridden using ``--app-dir`` in
  90. any of the JupyterLab commands, or by setting the ``JUPYTERLAB_DIR``
  91. environment variable. If not specified, it will default to
  92. ``<sys-prefix>/share/jupyter/lab``, where ``<sys-prefix>`` is the
  93. site-specific directory prefix of the current Python environment. You
  94. can query the current application path by running ``jupyter lab path``.
  95. JupyterLab Build Process
  96. ^^^^^^^^^^^^^^^^^^^^^^^^
  97. To rebuild the app directory, run ``jupyter lab build``. By default, the
  98. ``jupyter labextension install`` command builds the application, so you
  99. typically do not need to call ``build`` directly.
  100. Building consists of:
  101. - Populating the ``staging/`` directory using template files
  102. - Handling any locally installed packages
  103. - Ensuring all installed assets are available
  104. - Bundling the assets
  105. - Copying the bundled assets to the ``static`` directory
  106. Note that building will always use the latest JavaScript packages that meet
  107. the dependency requirements of JupyterLab itself and any installed extensions.
  108. If you wish to run JupyterLab with the set of pinned requirements that was
  109. shipped with the Python package, you can launch as `jupyter lab --core-mode`.
  110. JupyterLab Application Directory
  111. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  112. The JupyterLab application directory contains the subdirectories
  113. ``extensions``, ``schemas``, ``settings``, ``staging``, ``static``, and
  114. ``themes``.
  115. .. _extensions-1:
  116. extensions
  117. ''''''''''
  118. The ``extensions`` directory has the packed tarballs for each of the
  119. installed extensions for the app. If the application directory is not
  120. the same as the ``sys-prefix`` directory, the extensions installed in
  121. the ``sys-prefix`` directory will be used in the app directory. If an
  122. extension is installed in the app directory that exists in the
  123. ``sys-prefix`` directory, it will shadow the ``sys-prefix`` version.
  124. Uninstalling an extension will first uninstall the shadowed extension,
  125. and then attempt to uninstall the ``sys-prefix`` version if called
  126. again. If the ``sys-prefix`` version cannot be uninstalled, its plugins
  127. can still be ignored using ``ignoredPackages`` metadata in ``settings``.
  128. schemas
  129. '''''''
  130. The ``schemas`` directory contains `JSON
  131. Schemas <http://json-schema.org/>`__ that describe the settings used by
  132. individual extensions. Users may edit these settings using the
  133. JupyterLab Settings Editor.
  134. settings
  135. ''''''''
  136. The ``settings`` directory contains ``page_config.json`` and
  137. ``build_config.json`` files.
  138. .. _page_configjson:
  139. page_config.json
  140. The ``page_config.json`` data is used to provide config data to the
  141. application environment.
  142. Two important fields in the ``page_config.json`` file enable control of
  143. which plugins load:
  144. 1. ``disabledExtensions`` for extensions that should not load at all.
  145. 2. ``deferredExtensions`` for extensions that do not load until they are
  146. required by something, irrespective of whether they set ``autostart``
  147. to ``true``.
  148. The value for each field is an array of strings. The following sequence
  149. of checks are performed against the patterns in ``disabledExtensions``
  150. and ``deferredExtensions``.
  151. - If an identical string match occurs between a config value and a
  152. package name (e.g., ``"@jupyterlab/apputils-extension"``), then the
  153. entire package is disabled (or deferred).
  154. - If the string value is compiled as a regular expression and tests
  155. positive against a package name (e.g.,
  156. ``"disabledExtensions": ["@jupyterlab/apputils*$"]``), then the
  157. entire package is disabled (or deferred).
  158. - If an identical string match occurs between a config value and an
  159. individual plugin ID within a package (e.g.,
  160. ``"disabledExtensions": ["@jupyterlab/apputils-extension:settings"]``),
  161. then that specific plugin is disabled (or deferred).
  162. - If the string value is compiled as a regular expression and tests
  163. positive against an individual plugin ID within a package (e.g.,
  164. ``"disabledExtensions": ["^@jupyterlab/apputils-extension:set.*$"]``),
  165. then that specific plugin is disabled (or deferred).
  166. .. _build_configjson:
  167. build_config.json
  168. The ``build_config.json`` file is used to track the local directories
  169. that have been installed using
  170. ``jupyter labextension install <directory>``, as well as core extensions
  171. that have been explicitly uninstalled. An example of a
  172. ``build_config.json`` file is:
  173. .. code:: json
  174. {
  175. "uninstalled_core_extensions": [
  176. "@jupyterlab/markdownwidget-extension"
  177. ],
  178. "local_extensions": {
  179. "@jupyterlab/python-tests": "/path/to/my/extension"
  180. }
  181. }
  182. staging and static
  183. ''''''''''''''''''
  184. The ``static`` directory contains the assets that will be loaded by the
  185. JuptyerLab application. The ``staging`` directory is used to create the
  186. build and then populate the ``static`` directory.
  187. Running ``jupyter lab`` will attempt to run the ``static`` assets in the
  188. application directory if they exist. You can run
  189. ``jupyter lab --core-mode`` to load the core JupyterLab application
  190. (i.e., the application without any extensions) instead.
  191. themes
  192. ''''''
  193. The ``themes`` directory contains assets (such as CSS and icons) for
  194. JupyterLab theme extensions.