Jupyter Contrib Core
Jupyter Contrib Core provides common utilities for jupyter-contrib projects, primarily offering a `notebook-4.2`-compatible `nbextension` API to smooth over differences across various Jupyter Notebook versions. It includes shared application components, CLI scripts, and testing utilities for developers building Jupyter extensions. The current version is 0.4.2, and releases are generally driven by compatibility updates with newer Jupyter Notebook versions.
Warnings
- breaking Versions of `jupyter-contrib-core` prior to 0.3.2 may not be compatible with Jupyter Notebook 5.0 and later due to internal module structure changes in `notebook` (e.g., `ArgumentConflict` module moved).
- gotcha `jupyter-contrib-core` aims to smooth over differences in the `nbextension` API across various Jupyter Notebook versions. Directly interacting with Jupyter Notebook's internal `nbextensions` APIs, rather than using the shims provided by this library, can lead to unexpected behavior or breakage when upgrading `notebook` versions.
- breaking Significant changes in Jupyter's architecture (e.g., moving from `notebook` to `jupyter_server` for modern JupyterLab deployments) may introduce incompatibilities. While `jupyter-contrib-core` provides `notebook` compatibility, its direct utility for `jupyter_server`-based environments might be limited or require newer, dedicated compatibility layers.
Install
-
pip install jupyter-contrib-core
Imports
- enable_nbextension_python
from jupyter_contrib_core.notebook_compat.nbextensions import enable_nbextension_python
- disable_nbextension_python
from jupyter_contrib_core.notebook_compat.nbextensions import disable_nbextension_python
Quickstart
import logging
from jupyter_contrib_core.notebook_compat.nbextensions import enable_nbextension_python, disable_nbextension_python
# jupyter-contrib-core is primarily for developers building Jupyter extensions.
# This example demonstrates programmatic enabling/disabling of a hypothetical
# Python-based nbextension using its compatibility API.
# Set up a basic logger as it's a required argument for these functions.
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter('%(levelname)s: %(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)
dummy_extension_name = "my_dummy_jupyter_extension"
try:
print(f"\nAttempting to enable nbextension: {dummy_extension_name}")
# Note: This will update Jupyter's configuration, but won't
# physically install files. If the extension isn't present,
# it might still 'enable' it in config, but it won't load.
enable_nbextension_python(
dummy_extension_name,
user=True, # Apply for the current user
sys_prefix=False,
overwrite=False,
logger=log
)
print(f"Successfully (or attempted) to enable {dummy_extension_name}. Check your Jupyter config.")
print(f"\nAttempting to disable nbextension: {dummy_extension_name}")
disable_nbextension_python(
dummy_extension_name,
user=True,
logger=log
)
print(f"Successfully (or attempted) to disable {dummy_extension_name}.")
except Exception as e:
print(f"\nAn error occurred during nbextension management: {e}")