Jupyter Notebook - A web-based notebook environment for interactive computing
—
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.
Functions that allow Jupyter Server to discover and load the notebook as a server extension.
def _jupyter_server_extension_paths() -> list[dict[str, str]]:
"""
Return server extension path configuration.
This function is called by Jupyter Server during extension discovery
to identify the notebook module as a server extension.
Returns:
list[dict[str, str]]: Extension path configuration
Returns: [{"module": "notebook"}]
The returned configuration tells Jupyter Server that the "notebook"
module contains a server extension that should be loaded.
"""
def _jupyter_server_extension_points() -> list[dict[str, Any]]:
"""
Return server extension entry points configuration.
This function provides the actual extension application class
that Jupyter Server should instantiate when loading the extension.
Returns:
list[dict[str, Any]]: Extension entry point configuration
Returns: [{"module": "notebook", "app": JupyterNotebookApp}]
The returned configuration specifies that the JupyterNotebookApp
class from the notebook module should be used as the extension
application.
"""Function that allows JupyterLab to discover and load the notebook frontend extension.
def _jupyter_labextension_paths() -> list[dict[str, str]]:
"""
Return lab extension path configuration.
This function is called by JupyterLab during extension discovery
to identify the notebook frontend extension components.
Returns:
list[dict[str, str]]: Lab extension path configuration
Returns: [{"src": "labextension", "dest": "@jupyter-notebook/lab-extension"}]
The returned configuration tells JupyterLab where to find the
frontend extension files and what name to use for the extension.
The "src" path is relative to the notebook package directory.
"""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.
Discovery Process:
_jupyter_server_extension_paths() during startup_jupyter_server_extension_points() to get the application classJupyterNotebookApp as the extension applicationBenefits:
The lab extension integration allows the notebook frontend components to be discovered and loaded by JupyterLab, enabling integration with the JupyterLab frontend ecosystem.
Discovery Process:
_jupyter_labextension_paths() during frontend buildComponents Integrated:
from notebook import (
_jupyter_server_extension_paths,
_jupyter_server_extension_points,
_jupyter_labextension_paths
)
# Server extension discovery
server_paths = _jupyter_server_extension_paths()
print(f"Server extension paths: {server_paths}")
# Output: [{"module": "notebook"}]
server_points = _jupyter_server_extension_points()
print(f"Server extension points: {server_points}")
# Output: [{"module": "notebook", "app": <class 'notebook.app.JupyterNotebookApp'>}]
# Lab extension discovery
lab_paths = _jupyter_labextension_paths()
print(f"Lab extension paths: {lab_paths}")
# Output: [{"src": "labextension", "dest": "@jupyter-notebook/lab-extension"}]from notebook import _jupyter_server_extension_points
from jupyter_server.serverapp import ServerApp
# Get extension points
extension_points = _jupyter_server_extension_points()
extension_point = extension_points[0]
# Access the extension application class
notebook_app_class = extension_point["app"]
print(f"Extension app class: {notebook_app_class}")
# The extension would typically be loaded automatically by Jupyter Server,
# but you can access the class for inspection or manual instantiation
app = notebook_app_class()
print(f"Extension name: {app.name}")
print(f"Extension description: {app.description}")import os
from pathlib import Path
from notebook import _jupyter_labextension_paths
# Get lab extension paths
lab_paths = _jupyter_labextension_paths()
extension_config = lab_paths[0]
# Resolve the actual filesystem path
notebook_package_dir = Path(__file__).parent.parent # notebook package directory
extension_src_path = notebook_package_dir / extension_config["src"]
extension_name = extension_config["dest"]
print(f"Extension source path: {extension_src_path}")
print(f"Extension name: {extension_name}")
print(f"Extension exists: {extension_src_path.exists()}")
# List extension files (if path exists)
if extension_src_path.exists():
extension_files = list(extension_src_path.rglob("*"))
print(f"Extension files: {len(extension_files)} files found")from notebook.app import JupyterNotebookApp
# Create application instance
app = JupyterNotebookApp()
app.initialize()
# Check if the extension is properly loaded
if hasattr(app, 'serverapp') and app.serverapp:
extension_manager = app.serverapp.extension_manager
if extension_manager and hasattr(extension_manager, 'extensions'):
notebook_extension = extension_manager.extensions.get('notebook')
if notebook_extension:
print(f"Extension enabled: {notebook_extension.enabled}")
print(f"Extension app: {notebook_extension.app}")
else:
print("Notebook extension not found in extension manager")
else:
print("Extension manager not available")
else:
print("Server app not initialized")Install with Tessl CLI
npx tessl i tessl/pypi-notebook