Jupyter Kernel Gateway
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
- breaking Starting from v2.5.2, `jupyter-kernel-gateway` removed its internal dependency on `ipython_genutils`. Custom extensions or deployment scripts that relied on this module might break upon upgrade.
- gotcha Versions of `jupyter-kernel-gateway` prior to 3.0.0 were pinned to `jupyter-client < 8`. Users with a newer `jupyter-client` version in their environment might encounter dependency conflicts or unexpected behavior.
- gotcha When deploying `jupyter-kernel-gateway` as a public-facing service, critical security configuration like CORS origins (`--KernelGatewayApp.allow_origin`) and authentication must be explicitly set. Default settings are not secure for production environments.
Install
-
pip install jupyter-kernel-gateway
Quickstart
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.")