0
# Extension Integration
1
2
The extension integration system provides hooks that enable Jupyter Notebook to integrate with the broader Jupyter ecosystem. These functions allow Jupyter Server and JupyterLab to discover and load the notebook extension, enabling seamless integration with other Jupyter applications and extensions.
3
4
## Capabilities
5
6
### Server Extension Discovery
7
8
Functions that allow Jupyter Server to discover and load the notebook as a server extension.
9
10
```python { .api }
11
def _jupyter_server_extension_paths() -> list[dict[str, str]]:
12
"""
13
Return server extension path configuration.
14
15
This function is called by Jupyter Server during extension discovery
16
to identify the notebook module as a server extension.
17
18
Returns:
19
list[dict[str, str]]: Extension path configuration
20
Returns: [{"module": "notebook"}]
21
22
The returned configuration tells Jupyter Server that the "notebook"
23
module contains a server extension that should be loaded.
24
"""
25
26
def _jupyter_server_extension_points() -> list[dict[str, Any]]:
27
"""
28
Return server extension entry points configuration.
29
30
This function provides the actual extension application class
31
that Jupyter Server should instantiate when loading the extension.
32
33
Returns:
34
list[dict[str, Any]]: Extension entry point configuration
35
Returns: [{"module": "notebook", "app": JupyterNotebookApp}]
36
37
The returned configuration specifies that the JupyterNotebookApp
38
class from the notebook module should be used as the extension
39
application.
40
"""
41
```
42
43
### Lab Extension Discovery
44
45
Function that allows JupyterLab to discover and load the notebook frontend extension.
46
47
```python { .api }
48
def _jupyter_labextension_paths() -> list[dict[str, str]]:
49
"""
50
Return lab extension path configuration.
51
52
This function is called by JupyterLab during extension discovery
53
to identify the notebook frontend extension components.
54
55
Returns:
56
list[dict[str, str]]: Lab extension path configuration
57
Returns: [{"src": "labextension", "dest": "@jupyter-notebook/lab-extension"}]
58
59
The returned configuration tells JupyterLab where to find the
60
frontend extension files and what name to use for the extension.
61
The "src" path is relative to the notebook package directory.
62
"""
63
```
64
65
## Integration Architecture
66
67
### Server Extension Integration
68
69
The server extension integration allows Jupyter Notebook to run as part of a larger Jupyter Server instance, enabling it to coexist with other server extensions and share resources.
70
71
**Discovery Process:**
72
1. Jupyter Server calls `_jupyter_server_extension_paths()` during startup
73
2. Server identifies "notebook" module as containing an extension
74
3. Server calls `_jupyter_server_extension_points()` to get the application class
75
4. Server instantiates `JupyterNotebookApp` as the extension application
76
5. Extension is loaded and integrated into the server's request handling
77
78
**Benefits:**
79
- Shared authentication and session management
80
- Unified configuration system
81
- Resource sharing with other extensions
82
- Consistent URL routing and request handling
83
84
### Lab Extension Integration
85
86
The lab extension integration allows the notebook frontend components to be discovered and loaded by JupyterLab, enabling integration with the JupyterLab frontend ecosystem.
87
88
**Discovery Process:**
89
1. JupyterLab calls `_jupyter_labextension_paths()` during frontend build
90
2. JupyterLab identifies the notebook labextension directory
91
3. Frontend components are integrated into the JupyterLab build system
92
4. Extension is available in the JupyterLab frontend environment
93
94
**Components Integrated:**
95
- Notebook-specific UI components
96
- Custom handlers and plugins
97
- Styling and themes
98
- JavaScript/TypeScript modules
99
100
## Usage Examples
101
102
### Extension Discovery
103
104
```python
105
from notebook import (
106
_jupyter_server_extension_paths,
107
_jupyter_server_extension_points,
108
_jupyter_labextension_paths
109
)
110
111
# Server extension discovery
112
server_paths = _jupyter_server_extension_paths()
113
print(f"Server extension paths: {server_paths}")
114
# Output: [{"module": "notebook"}]
115
116
server_points = _jupyter_server_extension_points()
117
print(f"Server extension points: {server_points}")
118
# Output: [{"module": "notebook", "app": <class 'notebook.app.JupyterNotebookApp'>}]
119
120
# Lab extension discovery
121
lab_paths = _jupyter_labextension_paths()
122
print(f"Lab extension paths: {lab_paths}")
123
# Output: [{"src": "labextension", "dest": "@jupyter-notebook/lab-extension"}]
124
```
125
126
### Manual Extension Loading
127
128
```python
129
from notebook import _jupyter_server_extension_points
130
from jupyter_server.serverapp import ServerApp
131
132
# Get extension points
133
extension_points = _jupyter_server_extension_points()
134
extension_point = extension_points[0]
135
136
# Access the extension application class
137
notebook_app_class = extension_point["app"]
138
print(f"Extension app class: {notebook_app_class}")
139
140
# The extension would typically be loaded automatically by Jupyter Server,
141
# but you can access the class for inspection or manual instantiation
142
app = notebook_app_class()
143
print(f"Extension name: {app.name}")
144
print(f"Extension description: {app.description}")
145
```
146
147
### Extension Path Resolution
148
149
```python
150
import os
151
from pathlib import Path
152
from notebook import _jupyter_labextension_paths
153
154
# Get lab extension paths
155
lab_paths = _jupyter_labextension_paths()
156
extension_config = lab_paths[0]
157
158
# Resolve the actual filesystem path
159
notebook_package_dir = Path(__file__).parent.parent # notebook package directory
160
extension_src_path = notebook_package_dir / extension_config["src"]
161
extension_name = extension_config["dest"]
162
163
print(f"Extension source path: {extension_src_path}")
164
print(f"Extension name: {extension_name}")
165
print(f"Extension exists: {extension_src_path.exists()}")
166
167
# List extension files (if path exists)
168
if extension_src_path.exists():
169
extension_files = list(extension_src_path.rglob("*"))
170
print(f"Extension files: {len(extension_files)} files found")
171
```
172
173
### Server Extension Status
174
175
```python
176
from notebook.app import JupyterNotebookApp
177
178
# Create application instance
179
app = JupyterNotebookApp()
180
app.initialize()
181
182
# Check if the extension is properly loaded
183
if hasattr(app, 'serverapp') and app.serverapp:
184
extension_manager = app.serverapp.extension_manager
185
if extension_manager and hasattr(extension_manager, 'extensions'):
186
notebook_extension = extension_manager.extensions.get('notebook')
187
if notebook_extension:
188
print(f"Extension enabled: {notebook_extension.enabled}")
189
print(f"Extension app: {notebook_extension.app}")
190
else:
191
print("Notebook extension not found in extension manager")
192
else:
193
print("Extension manager not available")
194
else:
195
print("Server app not initialized")
196
```