IPython Kernel for Jupyter - provides the core communication layer between Jupyter frontends and the Python interpreter
—
Core kernel application framework for launching, configuring, and managing IPython kernel instances within the Jupyter ecosystem. Provides the essential infrastructure for kernel startup, configuration, and integration with Jupyter's architecture.
Main application class that manages kernel lifecycle, configuration, and startup procedures.
class IPKernelApp:
"""
Main application for launching IPython kernels.
Handles configuration, connection setup, and kernel initialization.
"""
def initialize(self, argv=None):
"""
Initialize the application with configuration and command-line arguments.
Parameters:
- argv (list, optional): Command-line arguments for configuration
"""
def start(self):
"""
Start the kernel application and begin message processing.
"""
# Configuration attributes
connection_file: str # Path to connection file
ip: str # IP address for kernel connections
shell_port: int # Port for shell messages
iopub_port: int # Port for IOPub messages
stdin_port: int # Port for stdin messages
control_port: int # Port for control messages
hb_port: int # Port for heartbeatPrimary entry point for starting new kernel instances with proper configuration and connection setup.
def launch_new_instance(argv=None, **kwargs):
"""
Launch a new IPython kernel instance.
This is the main entry point used by Jupyter to start kernels.
Parameters:
- argv (list, optional): Command-line arguments
- **kwargs: Additional configuration options
Returns:
None (runs kernel until termination)
"""Tools for installing and managing kernel specifications that tell Jupyter how to launch the IPython kernel.
KERNEL_NAME: str # Default kernel name based on Python version
def make_ipkernel_cmd(mod='ipykernel_launcher', **kwargs):
"""
Build command list for launching IPython kernel.
Parameters:
- mod (str): Module name for kernel launcher
- **kwargs: Additional command-line options
Returns:
list: Command arguments for kernel launch
"""
def get_kernel_dict(**kwargs):
"""
Construct kernel.json dictionary for kernel specification.
Parameters:
- **kwargs: Kernel specification options
Returns:
dict: Kernel specification dictionary
"""
def write_kernel_spec(path=None, overrides=None, **kwargs):
"""
Write kernel specification to specified directory.
Parameters:
- path (str, optional): Directory to write kernel spec
- overrides (dict, optional): Override default kernel spec values
- **kwargs: Additional kernel spec options
Returns:
str: Path to written kernel specification
"""
def install(kernel_spec_manager=None, user=False, kernel_name=None,
display_name=None, profile=None, prefix=None, **kwargs):
"""
Install IPython kernelspec for Jupyter.
Parameters:
- kernel_spec_manager: Kernel spec manager instance
- user (bool): Install for current user only
- kernel_name (str, optional): Name for installed kernel
- display_name (str, optional): Display name for kernel
- profile (str, optional): IPython profile to use
- prefix (str, optional): Installation prefix
- **kwargs: Additional installation options
Returns:
str: Path to installed kernel specification
"""Application class for installing kernel specifications from command line.
class InstallIPythonKernelSpecApp:
"""
Application for installing IPython kernel specifications.
Provides command-line interface for kernel spec installation.
"""
def start(self):
"""Start the kernel spec installation process."""
# Configuration options
user: bool # Install for user only
kernel_name: str # Name for kernel specification
display_name: str # Display name for kernel
profile: str # IPython profile to usefrom ipykernel.kernelapp import launch_new_instance
# Launch kernel with default configuration
launch_new_instance()
# Launch with custom configuration
launch_new_instance(argv=['--ip=127.0.0.1', '--shell-port=12345'])from ipykernel.kernelspec import install, get_kernel_dict
# Install default IPython kernel
install()
# Install with custom name and display name
install(
user=True,
kernel_name='python3-custom',
display_name='Python 3 (Custom)'
)
# Get kernel specification dictionary
kernel_dict = get_kernel_dict(
display_name='Python 3',
interrupt_mode='message'
)
print(kernel_dict)from ipykernel.kernelapp import IPKernelApp
# Create and configure kernel application
app = IPKernelApp()
app.initialize(['--ip=0.0.0.0', '--shell-port=54321'])
# Start the kernel
app.start() # Runs until kernel shutdownInstall with Tessl CLI
npx tessl i tessl/pypi-ipykernel