Jupyter Contrib Core

0.4.2 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically enable and disable a hypothetical Python nbextension using the compatibility functions provided by `jupyter-contrib-core`. This is typically used by other `jupyter-contrib` projects or advanced setup scripts, rather than directly by end-users. The functions interact with Jupyter's configuration.

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}")

view raw JSON →