extensions.rst 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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/>`__ version 4 or later 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. The JupyterLab application directory (where the application assets are
  86. built and the settings reside) can be overridden using ``--app-dir`` in
  87. any of the JupyterLab commands, or by setting the ``JUPYTERLAB_DIR``
  88. environment variable. If not specified, it will default to
  89. ``<sys-prefix>/share/jupyter/lab``, where ``<sys-prefix>`` is the
  90. site-specific directory prefix of the current Python environment. You
  91. can query the current application path by running ``jupyter lab path``.
  92. JupyterLab Build Process
  93. ^^^^^^^^^^^^^^^^^^^^^^^^
  94. To rebuild the app directory, run ``jupyter lab build``. By default, the
  95. ``jupyter labextension install`` command builds the application, so you
  96. typically do not need to call ``build`` directly.
  97. Building consists of:
  98. - Populating the ``staging/`` directory using template files
  99. - Handling any locally installed packages
  100. - Ensuring all installed assets are available
  101. - Bundling the assets
  102. - Copying the bundled assets to the ``static`` directory
  103. Note that building will always use the latest JavaScript packages that meet
  104. the dependency requirements of JupyterLab itself and any installed extensions.
  105. If you wish to run JupyterLab with the set of pinned requirements that was
  106. shipped with the Python package, you can launch as `jupyter lab --core-mode`.
  107. JupyterLab Application Directory
  108. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  109. The JupyterLab application directory contains the subdirectories
  110. ``extensions``, ``schemas``, ``settings``, ``staging``, ``static``, and
  111. ``themes``.
  112. .. _extensions-1:
  113. extensions
  114. ''''''''''
  115. The ``extensions`` directory has the packed tarballs for each of the
  116. installed extensions for the app. If the application directory is not
  117. the same as the ``sys-prefix`` directory, the extensions installed in
  118. the ``sys-prefix`` directory will be used in the app directory. If an
  119. extension is installed in the app directory that exists in the
  120. ``sys-prefix`` directory, it will shadow the ``sys-prefix`` version.
  121. Uninstalling an extension will first uninstall the shadowed extension,
  122. and then attempt to uninstall the ``sys-prefix`` version if called
  123. again. If the ``sys-prefix`` version cannot be uninstalled, its plugins
  124. can still be ignored using ``ignoredPackages`` metadata in ``settings``.
  125. schemas
  126. '''''''
  127. The ``schemas`` directory contains `JSON
  128. Schemas <http://json-schema.org/>`__ that describe the settings used by
  129. individual extensions. Users may edit these settings using the
  130. JupyterLab Settings Editor.
  131. settings
  132. ''''''''
  133. The ``settings`` directory contains ``page_config.json`` and
  134. ``build_config.json`` files.
  135. .. _page_configjson:
  136. page_config.json
  137. The ``page_config.json`` data is used to provide config data to the
  138. application environment.
  139. Two important fields in the ``page_config.json`` file enable control of
  140. which plugins load:
  141. 1. ``disabledExtensions`` for extensions that should not load at all.
  142. 2. ``deferredExtensions`` for extensions that do not load until they are
  143. required by something, irrespective of whether they set ``autostart``
  144. to ``true``.
  145. The value for each field is an array of strings. The following sequence
  146. of checks are performed against the patterns in ``disabledExtensions``
  147. and ``deferredExtensions``.
  148. - If an identical string match occurs between a config value and a
  149. package name (e.g., ``"@jupyterlab/apputils-extension"``), then the
  150. entire package is disabled (or deferred).
  151. - If the string value is compiled as a regular expression and tests
  152. positive against a package name (e.g.,
  153. ``"disabledExtensions": ["@jupyterlab/apputils*$"]``), then the
  154. entire package is disabled (or deferred).
  155. - If an identical string match occurs between a config value and an
  156. individual plugin ID within a package (e.g.,
  157. ``"disabledExtensions": ["@jupyterlab/apputils-extension:settings"]``),
  158. then that specific plugin is disabled (or deferred).
  159. - If the string value is compiled as a regular expression and tests
  160. positive against an individual plugin ID within a package (e.g.,
  161. ``"disabledExtensions": ["^@jupyterlab/apputils-extension:set.*$"]``),
  162. then that specific plugin is disabled (or deferred).
  163. .. _build_configjson:
  164. build_config.json
  165. The ``build_config.json`` file is used to track the local directories
  166. that have been installed using
  167. ``jupyter labextension install <directory>``, as well as core extensions
  168. that have been explicitly uninstalled. An example of a
  169. ``build_config.json`` file is:
  170. .. code:: json
  171. {
  172. "uninstalled_core_extensions": [
  173. "@jupyterlab/markdownwidget-extension"
  174. ],
  175. "local_extensions": {
  176. "@jupyterlab/python-tests": "/path/to/my/extension"
  177. }
  178. }
  179. staging and static
  180. ''''''''''''''''''
  181. The ``static`` directory contains the assets that will be loaded by the
  182. JuptyerLab application. The ``staging`` directory is used to create the
  183. build and then populate the ``static`` directory.
  184. Running ``jupyter lab`` will attempt to run the ``static`` assets in the
  185. application directory if they exist. You can run
  186. ``jupyter lab --core-mode`` to load the core JupyterLab application
  187. (i.e., the application without any extensions) instead.
  188. themes
  189. ''''''
  190. The ``themes`` directory contains assets (such as CSS and icons) for
  191. JupyterLab theme extensions.