extensions.rst 9.4 KB

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