### Setup Jupyverse Server 2 (Kernels API) Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/microservices.md Sets up the second Jupyverse environment, installing plugins specifically for the kernels API and an example kernel (ipykernel). ```bash micromamba create -n jupyverse2 micromamba activate jupyverse2 micromamba install -c conda-forge python pip install fps-kernels pip install fps-auth pip install fps-frontend pip install ipykernel ``` -------------------------------- ### Setup Jupyverse Server 1 (Content & Frontend) Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/microservices.md Sets up the first Jupyverse environment, installing necessary plugins for content, frontend, and authentication. This server handles everything except the kernels API. ```bash micromamba create -n jupyverse1 micromamba activate jupyverse1 micromamba install -c conda-forge python pip install fps-auth pip install fps-contents pip install fps-frontend pip install fps-lab pip install fps-jupyterlab pip install fps-login ``` -------------------------------- ### Install and initialize micromamba Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/standalone_jupyverse_deployment.md Install the micromamba package manager and initialize the shell environment. ```console $ sudo apt install bzip2 $ curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba $ bin/micromamba shell init --shell bash --root-prefix=~/micromamba $ exec bash ``` -------------------------------- ### Start Jupyverse Server with Default Settings Source: https://context7.com/jupyter-server/jupyverse/llms.txt Launch Jupyverse with default settings, which includes token authentication and automatically opens the browser. This is a basic command to get the server running. ```bash jupyverse --open-browser ``` -------------------------------- ### Install development dependencies with uv Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/install.md Create a virtual environment and install Jupyverse with all plugins for testing. ```bash uv venv uv pip install --group test -e ".[ \ jupyterlab, \ notebook, \ auth, \ auth-fief, \ auth-jupyterhub, \ noauth, \ file-watcher-poll, \ kernel-web-worker, \ resource-usage, \ webdav \ ]" ``` -------------------------------- ### Install Nginx Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/microservices.md Installs Nginx in a dedicated micromamba environment. This is the first step in setting up the reverse proxy. ```bash micromamba create -n nginx micromamba activate nginx micromamba install -c conda-forge nginx ``` -------------------------------- ### Running Separate Jupyverse Server Instances Source: https://context7.com/jupyter-server/jupyverse/llms.txt Launch multiple Jupyverse instances with distinct plugins for a microservices architecture. This example shows starting a UI/Contents server on port 8001 and a Kernels server on port 8002, then starting NGINX. ```bash # Terminal 1: UI and Contents Server (port 8001) pip install fps-auth fps-contents fps-frontend fps-lab fps-jupyterlab fps-login jupyverse --port=8001 --set auth.token=shared_secret_token # Terminal 2: Kernels Server (port 8002) pip install fps-kernels fps-auth fps-frontend ipykernel jupyverse --port=8002 --set auth.token=shared_secret_token # Terminal 3: Start NGINX reverse proxy nginx # Access the combined API at http://localhost:8000 ``` -------------------------------- ### Install Jupyverse with Micromamba Source: https://context7.com/jupyter-server/jupyverse/llms.txt Create a conda environment and install Jupyverse with required plugins using micromamba. This example shows installation for both JupyterLab and Jupyter Notebook frontends. ```bash # Create and activate environment micromamba create -n jupyverse micromamba activate jupyverse # Install for JupyterLab micromamba install -c conda-forge jupyverse fps-jupyterlab fps-auth # Or install for Jupyter Notebook micromamba install -c conda-forge jupyverse fps-notebook fps-auth ``` -------------------------------- ### Install JupyterHub and Jupyverse Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/jupyterhub_jupyverse_deployment.md Installs the core packages and proxy required for the server deployment. ```bash pip install jupyverse[jupyterlab,auth-jupyterhub] pip install jupyter-collaboration pip install oauthenticator pip install https://github.com/davidbrochart/jupyterhub/archive/jupyverse.zip npm install -g configurable-http-proxy ``` -------------------------------- ### Install and initialize micromamba Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/jupyterhub_jupyverse_deployment.md Downloads and sets up the micromamba package manager for environment management. ```bash sudo apt install bzip2 curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba bin/micromamba shell init --shell bash --root-prefix=~/micromamba exec bash ``` -------------------------------- ### Install NGINX and Certbot Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/standalone_jupyverse_deployment.md Install the necessary packages for web serving and automated SSL certificate management. ```console $ sudo apt install certbot nginx python3-certbot-nginx ``` -------------------------------- ### Install Jupyverse with JupyterLab and Auth Source: https://github.com/jupyter-server/jupyverse/blob/main/README.md Installs jupyverse with the JupyterLab frontend and the auth plugin from PyPI. Use this for a standard installation with specific features. ```bash pip install "jupyverse[jupyterlab,auth]" ``` -------------------------------- ### Start Nginx Server Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/microservices.md Starts the Nginx reverse proxy server after its configuration is complete. This makes the proxy accessible to clients. ```bash nginx ``` -------------------------------- ### Install Jupyverse Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/standalone_jupyverse_deployment.md Install Jupyverse with JupyterLab, Fief authentication, and collaboration support. ```console $ pip install jupyverse[jupyterlab,auth-fief] jupyter-collaboration ``` -------------------------------- ### Start Jupyverse Server with a Specific Authentication Token Source: https://context7.com/jupyter-server/jupyverse/llms.txt Start Jupyverse and set a specific authentication token for access. Replace 'my_secure_token_here' with your actual token. ```bash jupyverse --set auth.token=my_secure_token_here --open-browser ``` -------------------------------- ### Install Jupyverse with pip Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/install.md Use pip to install Jupyverse with specific frontend and authentication plugins. ```bash pip install "jupyverse[jupyterlab,auth]" ``` ```bash pip install "jupyverse[notebook,auth]" ``` -------------------------------- ### Install and configure Certbot Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/jupyterhub_jupyverse_deployment.md Sets up Certbot to manage SSL/TLS certificates for HTTPS support. ```bash sudo snap install --classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot sudo certbot certonly --standalone ``` -------------------------------- ### Start Jupyverse Server with User Authentication Source: https://context7.com/jupyter-server/jupyverse/llms.txt Start the Jupyverse server using user authentication. This mode requires user registration to access the server. ```bash jupyverse --set auth.mode=user --open-browser ``` -------------------------------- ### Install Jupyverse with micromamba Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/install.md Install Jupyverse and required plugins from the conda-forge channel. ```bash micromamba install -c conda-forge jupyverse fps-jupyterlab fps-auth ``` ```bash micromamba install -c conda-forge jupyverse fps-notebook fps-auth ``` -------------------------------- ### View Server Access URL Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/single_user.md Example of the terminal output containing the server URL and authentication token. ```text [2023-04-05 16:22:39,137 INFO] To access the server, copy and paste this URL: [2023-04-05 16:22:39,137 INFO] http://127.0.0.1:8000/?token=69ce8ccee10d4388b00b3df0d9849700 ``` -------------------------------- ### Launch JupyterHub with Environment Variables Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/jupyterhub_jupyverse_deployment.md Commands to prepare the directory and start JupyterHub with GitHub OAuth credentials provided via environment variables. ```bash sudo mkdir /srv/jupyterhub chmod -R o+rx /home/ubuntu mkdir jupyterhub cd jupyterhub sudo env "PATH=$PATH" \ "OAUTH_CALLBACK_URL=https://my.jupyverse.com/hub/oauth_callback" \ "GITHUB_CLIENT_ID=github_id" \ "GITHUB_CLIENT_SECRET=github_secret" \ jupyterhub -f /etc/jupyterhub/jupyterhub_config.py ``` -------------------------------- ### Create and activate conda environment Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/standalone_jupyverse_deployment.md Set up a dedicated environment for Jupyverse and install Python. ```console $ micromamba create -n jupyverse $ micromamba activate jupyverse $ micromamba install -c conda-forge python ``` -------------------------------- ### Launch Jupyverse with Token Authentication Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/single_user.md The default authentication mode requires a token for access. Use these commands to start the server and automatically open the browser. ```bash jupyverse --open-browser # same as: jupyverse --set auth.mode=token --open-browser ``` -------------------------------- ### Start Jupyverse Server with Custom Browser URL Query Parameters Source: https://context7.com/jupyter-server/jupyverse/llms.txt Configure Jupyverse to include custom query parameters in the browser URL when the server starts. This can be used to pass settings like theme preferences to the frontend. ```bash jupyverse --query-param "theme=dark" --open-browser ``` -------------------------------- ### Install Jupyter Collaboration Package Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/multi_user.md Install the necessary package to enable collaborative features in Jupyverse. ```bash pip install jupyter-collaboration ``` -------------------------------- ### Start Jupyverse Server with Explicit Token Authentication Source: https://context7.com/jupyter-server/jupyverse/llms.txt Start the Jupyverse server and explicitly set the authentication mode to token. This command ensures token-based authentication is used. ```bash jupyverse --set auth.mode=token --open-browser ``` -------------------------------- ### Install Jupyverse Plugins in Editable Mode with uv Source: https://github.com/jupyter-server/jupyverse/blob/main/README.md Installs all Jupyverse API and plugin modules in editable mode using uv. This allows for direct code changes to be reflected without reinstallation. Includes installing the main package for testing. ```bash uv venv for dir in ./api/*; do dirname=$(basename "$dir"); uv pip install -e "jupyverse-$dirname @ ./api/$dirname"; done for dir in ./plugins/*; do dirname=$(basename "$dir"); uv pip install -e "fps-$dirname @ ./plugins/$dirname"; done uv pip install --group test -e . ``` -------------------------------- ### Launch Jupyverse in Collaborative Mode Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/multi_user.md Start the Jupyverse server with collaborative editing enabled. ```bash jupyverse --set frontend.collaborative=true ``` -------------------------------- ### Example User Response from /api/me Source: https://context7.com/jupyter-server/jupyverse/llms.txt This JSON object represents a typical response from the /api/me endpoint, detailing user identity and permissions. ```json { "identity": { "username": "john.doe", "name": "John Doe", "display_name": "John Doe", "initials": "JD", "avatar_url": "https://example.com/avatar.png", "color": "#ff5733" }, "permissions": { "contents": ["read", "write"], "kernels": ["read", "write", "execute"] } } ``` -------------------------------- ### Start Jupyverse with Specific Plugins Disabled using uv Source: https://github.com/jupyter-server/jupyverse/blob/main/README.md Starts the Jupyverse server using uv, explicitly disabling certain authentication and frontend plugins. This is useful for testing specific configurations or isolating plugin behavior. ```bash uv run jupyverse \ --disable auth_fief \ --disable auth_jupyterhub \ --disable noauth \ --disable file_watcher_poll \ --disable notebook ``` -------------------------------- ### Create conda environment Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/jupyterhub_jupyverse_deployment.md Sets up a dedicated environment and installs necessary dependencies for JupyterHub. ```bash micromamba create -n jupyterhub micromamba activate jupyterhub micromamba install -c conda-forge python nodejs ``` -------------------------------- ### Manage JupyterLab Settings via API Source: https://context7.com/jupyter-server/jupyverse/llms.txt Use these examples to read or update JupyterLab extension settings. Requires an authorization token in the request header. ```bash # Get all settings curl -X GET "http://127.0.0.1:8000/lab/api/settings" \ -H "Authorization: Bearer " # Get specific extension settings curl -X GET "http://127.0.0.1:8000/lab/api/settings/@jupyterlab/apputils-extension:themes" \ -H "Authorization: Bearer " # Update settings curl -X PUT "http://127.0.0.1:8000/lab/api/settings/@jupyterlab/apputils-extension:themes" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d '{"raw": "{\"theme\": \"JupyterLab Dark\"}"}' ``` ```python import httpx import json # Get current theme settings response = httpx.get( "http://127.0.0.1:8000/lab/api/settings/@jupyterlab/apputils-extension:themes" ) settings = response.json() print(f"Current theme: {settings['raw']}") # Update to dark theme new_settings = {"raw": '{"theme": "JupyterLab Dark"}'} response = httpx.put( "http://127.0.0.1:8000/lab/api/settings/@jupyterlab/apputils-extension:themes", content=json.dumps(new_settings) ) assert response.status_code == 204 ``` -------------------------------- ### Get Available Export Formats in Bash Source: https://context7.com/jupyter-server/jupyverse/llms.txt Query the nbconvert API to retrieve a list of all supported notebook export formats. ```bash # Get available export formats curl -X GET "http://127.0.0.1:8000/api/nbconvert" \ -H "Authorization: Bearer " ``` -------------------------------- ### GET /nbconvert/{format}/{path} Source: https://context7.com/jupyter-server/jupyverse/llms.txt Exports a notebook to a specified format such as HTML, PDF, or Python script. ```APIDOC ## GET /nbconvert/{format}/{path} ### Description Converts a notebook file at the given path into the requested format. ### Method GET ### Endpoint /nbconvert/{format}/{path} ### Parameters #### Path Parameters - **format** (string) - Required - The target export format (e.g., html, pdf, python). - **path** (string) - Required - The path to the notebook file. #### Query Parameters - **download** (boolean) - Optional - If true, triggers a file download. ``` -------------------------------- ### Start Jupyverse Server on Custom Host and Port Source: https://context7.com/jupyter-server/jupyverse/llms.txt Configure Jupyverse to run on a specific host and port. This is useful for custom network configurations or avoiding port conflicts. ```bash jupyverse --host 0.0.0.0 --port 8888 --open-browser ``` -------------------------------- ### Run Jupyverse Tests with uv Source: https://github.com/jupyter-server/jupyverse/blob/main/README.md Executes the test suite for Jupyverse using uv. Ensure all development dependencies are installed before running. ```bash uv run pytest -v ``` -------------------------------- ### Define Session and Kernel Models Source: https://context7.com/jupyter-server/jupyverse/llms.txt Pydantic models for managing kernel sessions and an example JSON response for a session. ```python from pydantic import BaseModel class Kernel(BaseModel): id: str # Unique kernel ID name: str # Kernel name (e.g., "python3") last_activity: str # ISO 8601 timestamp execution_state: str # "idle", "busy", "starting" connections: int # Number of active connections class Session(BaseModel): id: str # Unique session ID path: str # Document path name: str # Document name type: str # "notebook" or "console" kernel: Kernel # Associated kernel notebook: Notebook # Notebook reference class Notebook(BaseModel): path: str # Notebook file path name: str # Notebook name ``` ```json { "id": "abc123-session-uuid", "path": "work/analysis.ipynb", "name": "analysis.ipynb", "type": "notebook", "kernel": { "id": "xyz789-kernel-uuid", "name": "python3", "last_activity": "2024-01-01T12:30:00.000000Z", "execution_state": "idle", "connections": 1 }, "notebook": { "path": "work/analysis.ipynb", "name": "analysis.ipynb" } } ``` -------------------------------- ### Clone Jupyverse Repository Source: https://github.com/jupyter-server/jupyverse/blob/main/README.md Clones the Jupyverse repository to set up for development. This is the first step before installing in editable mode. ```bash git clone https://github.com/jupyter-server/jupyverse.git cd jupyverse ``` -------------------------------- ### Programmatic Module Configuration in Jupyverse Source: https://context7.com/jupyter-server/jupyverse/llms.txt Configure Jupyverse modules programmatically for testing or custom deployments. This example demonstrates setting up various modules like app, auth, contents, and kernels, and then making requests to the FastAPI app. ```python import asyncio from fps import get_root_module, merge_config from httpx import AsyncClient CONFIG = { "jupyverse": { "type": "jupyverse", "config": { "start_server": False, # Don't start built-in server }, "modules": { "app": {"type": "app"}, "auth": { "type": "auth", "config": { "mode": "noauth", "test": True, }, }, "contents": {"type": "contents"}, "frontend": { "type": "frontend", "config": { "collaborative": True, }, }, "kernels": { "type": "kernels", "config": { "default_kernel": "python3", "require_yjs": True, }, }, "kernel_subprocess": {"type": "kernel_subprocess"}, "lab": {"type": "lab"}, "jupyterlab": {"type": "jupyterlab"}, "file_watcher": {"type": "file_watcher"}, }, } } async def run_jupyverse(): root_module = get_root_module(CONFIG) root_module._global_start_timeout = 10 async with root_module as module: app = module.app # Use the FastAPI app directly async with AsyncClient(app=app, base_url="http://test") as client: # Make requests response = await client.get("/api/contents") print(response.json()) # Create a session response = await client.post( "/api/sessions", json={ "kernel": {"name": "python3"}, "name": "test.ipynb", "path": "test.ipynb", "type": "notebook", } ) session = response.json() print(f"Created session: {session['id']}") asyncio.run(run_jupyverse()) ``` -------------------------------- ### Start Jupyverse Server in Collaborative Mode Source: https://context7.com/jupyter-server/jupyverse/llms.txt Launch Jupyverse with collaborative editing enabled. This setting allows multiple users to work on documents simultaneously. ```bash jupyverse --set frontend.collaborative=true --open-browser ``` -------------------------------- ### Start Jupyverse with Specific Plugins Disabled using pip Source: https://github.com/jupyter-server/jupyverse/blob/main/README.md Launches the Jupyverse server using pip, disabling specified authentication and frontend plugins. This is useful for targeted testing and configuration validation. ```bash jupyverse \ --disable auth_fief \ --disable auth_jupyterhub \ --disable noauth \ --disable file_watcher_poll \ --disable notebook ``` -------------------------------- ### Initialize and Display Switch Source: https://github.com/jupyter-server/jupyverse/blob/main/tests/data/notebook1.ipynb Create an instance of the Switch widget and display it in the notebook environment. ```python switch = Switch() switch ``` -------------------------------- ### Prepare JupyterHub configuration directory Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/jupyterhub_jupyverse_deployment.md Creates the directory and opens the configuration file for editing. ```bash sudo mkdir /etc/jupyterhub sudo vim /etc/jupyterhub/jupyterhub_config.py ``` -------------------------------- ### Show All Available Jupyverse Configuration Options Source: https://context7.com/jupyter-server/jupyverse/llms.txt Display all available configuration options for the Jupyverse server. This command provides a comprehensive list of settings that can be modified. ```bash jupyverse --help-all ``` -------------------------------- ### Install Jupyverse using Conda-Forge Source: https://github.com/jupyter-server/jupyverse/blob/main/README.md Installs Jupyverse and related packages using micromamba. This is useful for managing environments and dependencies with conda. ```bash micromamba create -n jupyverse micromamba activate jupyverse micromamba install jupyverse fps-jupyterlab fps-auth ``` -------------------------------- ### Launch Jupyverse with Fief configuration Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/standalone_jupyverse_deployment.md Executes the Jupyverse server with necessary Fief authentication settings. Replace placeholders with your specific Fief client credentials and API keys. ```console $ mkdir jupyverse && cd jupyverse $ jupyverse \ --set auth_fief.base_url=https://jupyverse.fief.dev \ --set auth_fief.client_id=fief_client_id \ --set auth_fief.client_secret=fief_client_secret \ --set auth_fief.admin_api_key=fief_admin_api \ --set auth_fief.oauth_provider_id=fief_oauth_provider_id \ --set auth_fief.callback_url=https://my.jupyverse.com/auth-callback ``` -------------------------------- ### Install Jupyverse Plugins in Editable Mode with pip Source: https://github.com/jupyter-server/jupyverse/blob/main/README.md Installs Jupyverse API and plugin modules in editable mode using pip. This method offers more control, especially when integrating third-party libraries. A virtual environment is recommended. ```bash for dir in ./api/*; do dirname=$(basename "$dir"); pip install -e "./api/$dirname"; done for dir in ./plugins/*; do dirname=$(basename "$dir"); pip install -e "./plugins/$dirname"; done pip install --group test -e . ``` -------------------------------- ### Configure User Authentication Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/multi_user.md Enable user-based authentication requiring registration and credentials. ```bash jupyverse --set frontend.collaborative=true --set auth.mode=user ``` -------------------------------- ### GET /api/nbconvert Source: https://context7.com/jupyter-server/jupyverse/llms.txt Retrieves the list of supported export formats for notebooks. ```APIDOC ## GET /api/nbconvert ### Description Returns a list of available formats that notebooks can be exported to. ### Method GET ### Endpoint /api/nbconvert ``` -------------------------------- ### Connect to instance via SSH Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/jupyterhub_jupyverse_deployment.md Establishes a remote connection to the provisioned instance using its public IP address. ```bash ssh ubuntu@1.2.3.4 # The authenticity of host '1.2.3.4 (1.2.3.4)' can't be established. # ED25519 key fingerprint is SHA256:Q1&tbgX3fp9+7J90zyK0ctuKe1aqPoEY76Qi58uoSnA. # This key is not known by any other names # Are you sure you want to continue connecting (yes/no/[fingerprint])? ``` -------------------------------- ### Verify and Reload NGINX Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/standalone_jupyverse_deployment.md Check configuration syntax and apply changes to the running NGINX service. ```console $ sudo nginx -t && sudo nginx -s reload ``` -------------------------------- ### Connect to instance via SSH Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/tutorials/standalone_jupyverse_deployment.md Establish a remote connection to the provisioned instance using its public IP address. ```console $ ssh ubuntu@1.2.3.4 The authenticity of host '1.2.3.4 (1.2.3.4)' can't be established. ED25519 key fingerprint is SHA256:Q1&tbgX3fp9+7J90zyK0ctuKe1aqPoEY76Qi58uoSnA. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? ``` -------------------------------- ### Launch Jupyverse Server 1 Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/microservices.md Launches the first Jupyverse server on port 8001 with a specified authentication token. This server provides the UI and content management but not kernel execution. ```bash jupyverse --port=8001 --set auth.token=5e9b01f993bc4fb48b2bf6958fd22981 ``` -------------------------------- ### POST /api/contents Source: https://context7.com/jupyter-server/jupyverse/llms.txt Create a new file, directory, or notebook at the specified path. ```APIDOC ## POST /api/contents/{path} ### Description Create new files, notebooks, or directories. ### Method POST ### Endpoint /api/contents/{path} ### Parameters #### Path Parameters - **path** (string) - Required - The directory path where the new content should be created. #### Request Body - **type** (string) - Required - The type of content to create (e.g., 'notebook', 'directory', 'file'). ### Request Example { "type": "notebook" } ``` -------------------------------- ### Run Jupyverse Tests with pip Source: https://github.com/jupyter-server/jupyverse/blob/main/README.md Executes the Jupyverse test suite. This command assumes pytest is installed and configured in the environment. ```bash pytest -v ``` -------------------------------- ### Create Content via REST API Source: https://context7.com/jupyter-server/jupyverse/llms.txt Use POST requests to create new files or directories at a specified path. ```bash curl -X POST "http://127.0.0.1:8000/api/contents/path/to/directory" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d '{"type": "file", "ext": ".py"}' ``` ```bash curl -X POST "http://127.0.0.1:8000/api/contents/path/to/parent" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d '{"type": "directory"}' ``` -------------------------------- ### Define Content Model Source: https://context7.com/jupyter-server/jupyverse/llms.txt Pydantic model for representing files, directories, and notebooks, along with an example JSON response for a directory. ```python from pydantic import BaseModel class Content(BaseModel): name: str # File or directory name path: str # Full path from root last_modified: str | None = None # ISO 8601 timestamp created: str | None = None # ISO 8601 timestamp content: list[dict] | str | dict | None = None # File content format: str | None = None # "text", "json", or "base64" mimetype: str | None = None # MIME type size: int | None = None # File size in bytes writable: bool # Write permission type: str # "file", "directory", or "notebook" ``` ```json { "name": "notebooks", "path": "notebooks", "last_modified": "2024-01-01T12:00:00.000000Z", "created": "2024-01-01T10:00:00.000000Z", "content": [ {"name": "example.ipynb", "type": "notebook", ...}, {"name": "data.csv", "type": "file", ...} ], "format": "json", "mimetype": None, "size": None, "writable": True, "type": "directory" } ``` -------------------------------- ### Configure Authentication via CLI Source: https://context7.com/jupyter-server/jupyverse/llms.txt Sets authentication modes and parameters for the Jupyverse server using the --set flag. ```bash # Token authentication (default) jupyverse --set auth.mode=token # No authentication jupyverse --set auth.mode=noauth # User authentication with registration jupyverse --set auth.mode=user # Set a specific token jupyverse --set auth.token=my_custom_token_12345 # Clear user database on startup jupyverse --set auth.clear_users=true # Configure with Fief authentication jupyverse \ --set auth_fief.base_url=https://your-workspace.fief.dev \ --set auth_fief.client_id=your_client_id \ --set auth_fief.client_secret=your_client_secret \ --set auth_fief.callback_url=https://your-domain.com/auth-callback ``` -------------------------------- ### List Sessions and Kernels via REST API Source: https://context7.com/jupyter-server/jupyverse/llms.txt Retrieve information about active sessions, running kernels, and available kernelspecs. ```bash curl -X GET "http://127.0.0.1:8000/api/sessions" \ -H "Authorization: Bearer " ``` ```bash curl -X GET "http://127.0.0.1:8000/api/kernels" \ -H "Authorization: Bearer " ``` ```bash curl -X GET "http://127.0.0.1:8000/api/kernelspecs" \ -H "Authorization: Bearer " ``` ```bash curl -X GET "http://127.0.0.1:8000/api/kernels/" \ -H "Authorization: Bearer " ``` -------------------------------- ### GET /api/contents Source: https://context7.com/jupyter-server/jupyverse/llms.txt Retrieve the contents of a directory or a specific file. The 'content' parameter determines whether the actual file data is returned. ```APIDOC ## GET /api/contents ### Description Retrieve directory or file contents from the server. ### Method GET ### Endpoint /api/contents/{path} ### Parameters #### Path Parameters - **path** (string) - Optional - The path to the file or directory. #### Query Parameters - **content** (integer) - Optional - Set to 1 to fetch file content, 0 to fetch only metadata/listing. ### Response #### Success Response (200) - **name** (string) - Name of the file or directory - **path** (string) - Path relative to root - **type** (string) - Type of content (directory, notebook, file) - **writable** (boolean) - Whether the content is writable - **format** (string) - Format of the content - **content** (array/object) - The actual content or list of children #### Response Example { "name": "", "path": ".", "type": "directory", "writable": true, "format": "json", "content": [ {"name": "notebook.ipynb", "type": "notebook", "path": "notebook.ipynb"}, {"name": "data", "type": "directory", "path": "data"} ] } ``` -------------------------------- ### Apply license banner to source files Source: https://github.com/jupyter-server/jupyverse/blob/main/COPYING.md Use this standard banner in source code files to indicate copyright and license terms. ```text # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. ``` -------------------------------- ### Run Jupyverse with Uvicorn Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/external_server.md Command to execute the custom application using the Uvicorn ASGI server. ```bash uvicorn main:app ``` -------------------------------- ### Get or Create Room ID for Collaboration in Bash Source: https://context7.com/jupyter-server/jupyverse/llms.txt Use this cURL command to request a room ID for a specific notebook path, enabling real-time document collaboration. ```bash # Get or create room ID for a document curl -X PUT "http://127.0.0.1:8000/api/collaboration/session/path/to/notebook.ipynb" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -d '{"format": "json", "type": "notebook"}' ``` -------------------------------- ### Get Specific File or Directory Contents using Curl Source: https://context7.com/jupyter-server/jupyverse/llms.txt Retrieve the contents of a specific file or directory within Jupyverse using curl. Replace `path/to/file.ipynb` with the desired path. ```bash curl -X GET "http://127.0.0.1:8000/api/contents/path/to/file.ipynb?content=1" \ -H "Authorization: Bearer " ``` -------------------------------- ### Create and activate micromamba environment Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/install.md Initialize a new conda-forge environment for Jupyverse. ```bash micromamba create -n jupyverse micromamba activate jupyverse ``` -------------------------------- ### Get Root Directory Contents using Curl Source: https://context7.com/jupyter-server/jupyverse/llms.txt Retrieve the contents of the root directory from the Jupyverse server using curl. The `content=1` parameter includes file and directory details. ```bash curl -X GET "http://127.0.0.1:8000/api/contents?content=1" \ -H "Authorization: Bearer " ``` -------------------------------- ### Start Jupyverse Server with CORS Enabled Source: https://context7.com/jupyter-server/jupyverse/llms.txt Launch Jupyverse with Cross-Origin Resource Sharing (CORS) enabled for specific origins. This allows web clients from specified domains to interact with the server. ```bash jupyverse --allow-origin "https://example.com" --open-browser ``` -------------------------------- ### Get Directory Contents using httpx Source: https://context7.com/jupyter-server/jupyverse/llms.txt Retrieve directory contents from the Jupyverse server using the httpx Python library. The response is a JSON object containing information about files and subdirectories. ```python import httpx # Get directory contents response = httpx.get( "http://127.0.0.1:8000/api/contents", params={"content": 1} ) contents = response.json() # Response structure: # { # "name": "", # "path": ".", # "type": "directory", # "writable": True, # "format": "json", # "content": [ # {"name": "notebook.ipynb", "type": "notebook", "path": "notebook.ipynb", ...}, # {"name": "data", "type": "directory", "path": "data", ...} # ] # } ``` -------------------------------- ### PUT /api/collaboration/session/{path} Source: https://context7.com/jupyter-server/jupyverse/llms.txt Initializes a collaboration session for a specific notebook file to obtain a room ID. ```APIDOC ## PUT /api/collaboration/session/{path} ### Description Creates or retrieves a session room ID for a document to enable real-time collaborative editing. ### Method PUT ### Endpoint /api/collaboration/session/{path} ### Parameters #### Path Parameters - **path** (string) - Required - The file path to the notebook. #### Request Body - **format** (string) - Required - The document format (e.g., "json"). - **type** (string) - Required - The document type (e.g., "notebook"). ### Response #### Success Response (200) - **fileId** (string) - The unique identifier for the collaboration session. ``` -------------------------------- ### NGINX Reverse Proxy for Jupyverse Microservices Source: https://context7.com/jupyter-server/jupyverse/llms.txt Configure NGINX to route requests to separate Jupyverse instances for a microservices deployment. This setup directs traffic to different ports based on the API endpoint. ```nginx # /etc/nginx/conf.d/jupyverse.conf server { listen 8000; server_name localhost; # Default: route to main server (UI, contents, etc.) location / { proxy_pass http://localhost:8001; } # Kernelspecs API location /api/kernelspecs { proxy_pass http://localhost:8002; } # Kernels API location /api/kernels { proxy_pass http://localhost:8002; } # Kernel WebSocket channels (requires special headers) location ~ \/api\/kernels\/.+\/channels { proxy_pass http://localhost:8002; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } # Sessions API location /api/sessions { proxy_pass http://localhost:8002; } # Terminals WebSocket location ~ \/terminals\/websocket\/.+ { proxy_pass http://localhost:8001; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } # Collaboration WebSocket location ~ \/api\/collaboration\/room\/.+ { proxy_pass http://localhost:8001; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } } ``` -------------------------------- ### Show Jupyverse Current Configuration Source: https://context7.com/jupyter-server/jupyverse/llms.txt Display the current configuration settings of the Jupyverse server. This command is useful for verifying active settings. ```bash jupyverse --show-config ``` -------------------------------- ### Get Directory Listing Without File Contents using Curl Source: https://context7.com/jupyter-server/jupyverse/llms.txt Fetch a directory listing from Jupyverse using curl, but exclude the actual content of files by setting `content=0`. This is useful for quickly listing directory structures. ```bash curl -X GET "http://127.0.0.1:8000/api/contents/my_folder?content=0" \ -H "Authorization: Bearer " ``` -------------------------------- ### Collaborate on Notebook with Yjs in Python Source: https://context7.com/jupyter-server/jupyverse/llms.txt This Python script demonstrates connecting to a collaboration room, creating a Yjs document, and listening for changes to a notebook's cells. ```python import asyncio from pycrdt import Doc, Array, Map from httpx import AsyncClient from httpx_ws import aconnect_ws import json async def collaborate_on_notebook(): url = "http://127.0.0.1:8000" path = "notebooks/shared.ipynb" async with AsyncClient() as http: # Get room ID for the document response = await http.put( f"{url}/api/collaboration/session/{path}", content=json.dumps({"format": "json", "type": "notebook"}) ) file_id = response.json()["fileId"] document_id = f"json:notebook:{file_id}" # Create Yjs document ydoc = Doc() ycells = ydoc.get("cells", type=Array) # Connect to collaboration room async with aconnect_ws( f"{url}/api/collaboration/room/{document_id}", http ) as websocket: # Listen for document changes async for event in ydoc.events(): print(f"Document updated, cells: {len(ycells)}") # Process collaborative changes for cell in ycells: print(f"Cell: {cell}") asyncio.run(collaborate_on_notebook()) ``` -------------------------------- ### Launch Jupyverse Server 2 Source: https://github.com/jupyter-server/jupyverse/blob/main/docs/usage/microservices.md Launches the second Jupyverse server on port 8002 with the same authentication token. This server is dedicated to handling kernel operations. ```bash jupyverse --port=8002 --set auth.token=5e9b01f993bc4fb48b2bf6958fd22981 ```