Jupyter Server
Jupyter Server provides the backend services, APIs, and REST endpoints for Jupyter web applications like Jupyter Notebook, JupyterLab, and Voila. It is a replacement for the Tornado Web Server in older Jupyter Notebook installations. Currently at version 2.17.0, it maintains an active release cadence with frequent minor updates and bug fixes.
Warnings
- breaking Migrating from Jupyter Notebook (pre-7) to Jupyter Server (v2+) involves significant breaking changes. Configuration files moved from `jupyter_notebook_config.py` to `jupyter_server_config.py`, and server-related imports from the `notebook` package should be updated to `jupyter_server`.
- gotcha Jupyter Server defaults to token-based authentication for security. If you try to access the server without a token or a configured password, you will be prompted for authentication. Direct password login is not enabled by default when token authentication is active.
- gotcha Mismatches between the Python environment where Jupyter Server is running and the environment where kernels are sourced can lead to `ImportError` or `ModuleNotFound` exceptions within notebooks.
- gotcha Jupyter Server (and its kernels) can crash due to excessive memory usage, often caused by very large datasets, long-running computations, or extensive cell outputs.
- gotcha For remote access or specific deployments, firewall configuration is essential. The server's main port (`ServerApp.port`) must be open, as well as a range of ephemeral ports (typically 49152 to 65535) used by ZeroMQ for kernel communication.
Install
-
pip install jupyter_server
Imports
- ServerApp
from jupyter_server.serverapp import ServerApp
- ExtensionApp
from jupyter_server.extension.application import ExtensionApp
Quickstart
import asyncio
import os
from jupyter_server.serverapp import ServerApp
async def start_jupyter_server():
# Instantiate the server application
# For a quickstart, we disable browser opening and token/password for simplicity.
# In production, ALWAYS secure your Jupyter Server with tokens/passwords.
app = ServerApp(
open_browser=False,
port=os.environ.get("JUPYTER_SERVER_PORT", 8888),
port_retries=0,
token="", # IMPORTANT: Do NOT use empty token in production.
password="" # IMPORTANT: Do NOT use empty password in production.
)
await app.initialize()
await app.start()
print(f"Jupyter Server running at: {app.url} (Access via web browser if not using --no-browser, use the printed URL including token if applicable)")
print("Press Ctrl+C to stop the server.")
try:
# Keep the server running until interrupted
await asyncio.Event().wait()
except KeyboardInterrupt:
print("\nServer stopping...")
finally:
await app.stop()
if __name__ == "__main__":
# To run this, save as a Python file (e.g., `run_server.py`) and execute `python run_server.py`.
# Alternatively, for a basic command-line start, simply run `jupyter server` in your terminal.
asyncio.run(start_jupyter_server())