Jupyter Kernel Gateway

3.0.1 · active · verified Sat Apr 11

Jupyter Kernel Gateway is a web server for spawning and communicating with Jupyter kernels. It provides a REST API that allows execution of code in Jupyter Kernels and manages their lifecycle, often used to expose notebooks as RESTful APIs. The current version is 3.0.1, and the project maintains an active release cadence with several updates per year, now managed under the `jupyter-server` organization.

Warnings

Install

Quickstart

This quickstart demonstrates how to programmatically start the Jupyter Kernel Gateway server and make a simple API request to verify its operation. In typical use, Kernel Gateway is run directly from the command line using `jupyter kernelgateway`.

import subprocess
import sys
import time
import requests

# Start Kernel Gateway in a separate process
print("Starting Jupyter Kernel Gateway on port 9999...")
process = subprocess.Popen(
    [sys.executable, "-m", "jupyter_kernel_gateway.app",
     "--KernelGatewayApp.port=9999",
     "--KernelGatewayApp.ip=127.0.0.1",
     "--KernelGatewayApp.allow_origin='*'"],
    stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)

# Give it a moment to start up
time.sleep(5)

try:
    # Verify it's running by hitting an endpoint
    print("Attempting to connect to Kernel Gateway...")
    response = requests.get("http://127.0.0.1:9999/api/kernelspecs")
    response.raise_for_status()
    print("Kernel Gateway is running and accessible. Available kernelspecs:")
    print(response.json())
except Exception as e:
    print(f"Error connecting to Kernel Gateway: {e}")
    if process.poll() is not None:
        stdout, stderr = process.communicate()
        print("Server stdout:\n", stdout)
        print("Server stderr:\n", stderr)
finally:
    print("Stopping Kernel Gateway...")
    if process.poll() is None: # Check if still running
        process.terminate()
        process.wait(timeout=5)
    print("Kernel Gateway stopped.")

view raw JSON →