extensions.rst 8.1 KB

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