jupyterlab_pioneer package
jupyterlab_pioneer.default_exporters module
This module provides 5 default exporters for the extension. If the exporter function name is mentioned in the configuration file or in the notebook metadata, the extension will use the corresponding exporter function when the jupyter lab event is fired.
- jupyterlab_pioneer.default_exporters.default_exporters
a map from function names to callable exporter functions:
default_exporters: dict[str, Callable[[dict], dict or Awaitable[dict]]] = { "console_exporter": console_exporter, "command_line_exporter": command_line_exporter, "file_exporter": file_exporter, "remote_exporter": remote_exporter, "opentelemetry_exporter": opentelemetry_exporter, }
- Type:
dict[str, collections.abc.Callable[[dict], dict]]
- jupyterlab_pioneer.default_exporters.command_line_exporter(args: dict) dict[source]
This exporter sends telemetry data to the python console jupyter is running on.
- Parameters:
args (dict) –
arguments to pass to the exporter function, defined in the configuration file (except ‘data’, which is gathered by the extension). It has the following structure:
{ 'id': # (optional) exporter id, 'data': # telemetry data }
- Returns:
{ 'exporter': # exporter id or 'CommandLineExporter', }
- Return type:
dict
- jupyterlab_pioneer.default_exporters.console_exporter(args: dict) dict[source]
This exporter sends telemetry data to the browser console.
- Parameters:
args (dict) –
arguments to pass to the exporter function, defined in the configuration file (except ‘data’, which is gathered by the extension). It has the following structure:
{ 'id': # (optional) exporter id, 'data': # telemetry data }
- Returns:
{ 'exporter': # exporter id or 'ConsoleExporter', 'message': # telemetry data }
- Return type:
dict
- jupyterlab_pioneer.default_exporters.file_exporter(args: dict) dict[source]
This exporter writes telemetry data to local file.
- Parameters:
args (dict) –
arguments to pass to the exporter function, defined in the configuration file (except ‘data’, which is gathered by the extension). It has the following structure:
{ 'id': # (optional) exporter id, 'path': # local file path, 'data': # telemetry data }
- Returns:
{ 'exporter': # exporter id or 'FileExporter', }
- Return type:
dict
- jupyterlab_pioneer.default_exporters.opentelemetry_exporter(args: dict) dict[source]
This exporter sends telemetry data via otlp
- async jupyterlab_pioneer.default_exporters.remote_exporter(args: dict) dict[source]
This exporter sends telemetry data to a remote http endpoint.
- Parameters:
args (dict) –
arguments to pass to the exporter function, defined in the configuration file (except ‘data’, which is gathered by the extension). It has the following structure:
{ 'id': # (optional) exporter id, 'url': # http endpoint url, 'params': # (optional) additional parameters to pass to the http endpoint, 'env': # (optional) environment variables to pass to the http endpoint, 'data': # telemetry data }
- Returns:
{ 'exporter': exporter id or 'RemoteExporter', 'message': { 'code': http response code, 'reason': http response reason, 'body': http response body } }
- Return type:
dict
jupyterlab_pioneer.handlers module
This module defines the extra request handlers the pioneer extension needs
- class jupyterlab_pioneer.handlers.RouteHandler(*args, **kwargs)[source]
Bases:
ExtensionHandlerMixin,JupyterHandler- async export()[source]
This function exports telemetry data with requested exporters.
The function first parse the request body to get the event data and the corresponding exporter requested for the event. Then base on the exporter type, the function either calls the default exporters or tries to access the custom exporter defined in the configuration file.
- Returns:
{ "exporter": # exporter type, "message": # execution message of the exporter function }
- Return type:
dict
- get(resource)[source]
GET method
- Parameters:
resource (str) – the name of the resource requested. It is expected to be one of “version”, “environ”, or “config”.
- Returns:
If resource is “version”, the server responses with a json serialized obj of the version string.
If resource is “environ”, the server responses with a json serialized obj of current environment variables.
If resource is “config”, the server responses with a json serialized obj containing “activeEvents” and “exporters” configurations from the configuration file.
For other resources, set the status code to 404 not found.
- Return type:
str(json)
- post(resource)[source]
POST method
- Parameters:
resource (str) – the name of the resource requested. It is expected to be “export”.
- Returns:
If resource is “export”, the server calls the asynchronous export function
export(), and responses with the json serialized export result.For other resources, set the status code to 404 not found.
- Return type:
str(json)
jupyterlab_pioneer.application module
This module defines the extension app name, reads configurable variables from the configuration file, and adds the extra request handlers from handlers module to Jupyter Server’s Tornado Web Application.
- class jupyterlab_pioneer.application.JupyterLabPioneerApp(**kwargs: Any)[source]
Bases:
ExtensionApp- activeEvents
An array of active events defined in the configuration file.
Global config, could be override by activeEvents defined inside of individual exporter configs.
The extension would only generate and export data for valid events ( 1. that have an id associated with the event class, 2. the event name is included in activeEvents ).
The extension will export the entire notebook content only for valid events when the logWholeNotebook flag is True. The extension will export the cell metadata only for cell related valid events when the logCellMetadata flag is True.
Examples
# in the configuration file c.JupyterLabPioneerApp.activeEvents = [ {"name": "ActiveCellChangeEvent", "logWholeNotebook": False}, {"name": "CellAddEvent", "logWholeNotebook": False}, # {"name": "CellEditEvent", "logWholeNotebook": False}, {"name": "CellExecuteEvent", "logWholeNotebook": False}, {"name": "CellRemoveEvent", "logWholeNotebook": False}, # {"name": "ClipboardCopyEvent", "logWholeNotebook": False}, # {"name": "ClipboardCutEvent", "logWholeNotebook": False}, # {"name": "ClipboardPasteEvent", "logWholeNotebook": False}, # {"name": "NotebookHiddenEvent", "logWholeNotebook": False}, # {"name": "NotebookOpenEvent", "logWholeNotebook": False}, # {"name": "NotebookSaveEvent", "logWholeNotebook": False}, # {"name": "NotebookScrollEvent", "logWholeNotebook": False}, # {"name": "NotebookVisibleEvent", "logWholeNotebook": False}, ]
- custom_exporter
A dictionary of custom exporter defined in the configuration file
Examples
# in the configuration file def my_custom_exporter(args): # write your own exporter logic here return { "exporter": args.get("id"), "message": "" } c.JupyterLabPioneerApp.exporters = [ { "type": "custom_exporter", "args": { "id": "MyCustomExporter" # add additional args for your exporter function here }, } ] c.JupyterLabPioneerApp.custom_exporter = { 'MyCustomExporter': my_custom_exporter, }
- exporters
An array of the exporters defined in the configuration file.
This extension provides 5 default exporters in the
default_exportersmodule:default_exporters.console_exporter(), which sends telemetry data to the browser console.default_exporters.command_line_exporter(), which sends telemetry data to the python console jupyter is running on.default_exporters.file_exporter(), which saves telemetry data to local file.default_exporters.remote_exporter(), which sends telemetry data to a remote http endpoint.default_exporters.opentelemetry_exporter(), which sends telemetry data via otlp.Additionally, users can import default exporters or write customized exporters in the configuration file.
Examples
# in the configuration file c.JupyterLabPioneerApp.exporters = [ { "type": "console_exporter", }, { "type": "command_line_exporter", }, ]
- initialize_handlers()[source]
This function adds the extra request handlers from
handlersmodule to Jupyter Server’s Tornado Web Application.
- name: str | Unicode[str, str] = 'jupyterlab_pioneer'
Extension app name