10

How can I list all existing workspaces in JupyterLab?

I know that one can view the current workspace name in the URL:

enter image description here

enter image description here

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501

4 Answers4

11

When you create a workspace, this creates a file in ~/.jupyter/lab/workspaces. The name of your workspace is in the ['metadata']['id'] key of the corresponding JSON file.

a simple code to list all workspaces is therefore:

import os, glob, json
for fname in glob.glob(os.path.join(os.environ['HOME'], ".jupyter/lab/workspaces/*")):
     with open (fname, "r") as read_file:
         print (json.load(read_file)['metadata']['id'])

For convenience, I created a gist with that bit of code. I have also added some cosmetics to directly generate the different URLs:

$ list_workspaces.py -u
http://10.164.5.234:8888/lab
http://10.164.5.234:8888/lab/workspaces/BBCP
http://10.164.5.234:8888/lab/workspaces/blog
meduz
  • 3,903
  • 1
  • 28
  • 40
  • 3
    Is there a way to disable workspaces, i.e. limit the workspace creation process to just one workspace? – Evgeny Bobkin Dec 27 '19 at 15:08
  • to limit to one workspace, do *not* use them but just the http://localhost:8888/lab URI – meduz May 05 '21 at 07:58
  • I have updated the script in the gist which allows you to use that in a script - generates for instance a list of URLs which you can click on (in a *modern* terminal emulator) – meduz Sep 01 '21 at 10:10
  • There seems to be a lot of auto-x workspaces, polluting the list. – creanion Oct 22 '21 at 19:07
8

I think you could try

ls ~/.jupyter/lab/workspaces

Each time u create a new workspace, there will be a corresponding file generated here. More detailed docs are here

Yuze Ma
  • 357
  • 1
  • 9
4

As others have pointed out, workspace files are located at ~/.jupyter/lab/workspaces. Each workspace is represented by a .jupyterlab-workspace, which is actually just a JSON file.

If you have the CLI tool jq installed, the following one-liner gives you a quick list of workspaces:

cat ~/.jupyter/lab/workspaces/* | jq -r '.metadata.id'

Sample output:

/lab
/lab/workspaces/aaaaaaaaaaaa
/lab/workspaces/xxxxxxxxxx
Gustavo Bezerra
  • 9,984
  • 4
  • 40
  • 48
  • As a side note: you do not need to use `cat`: you can simply do: `< $JUPYTER_CONFIG_DIR/lab/workspaces/* jq -r ".metadata.id"` (you do not need to set `JUPYTER_CONFIG_DIR`, of course) – baggiponte Aug 23 '21 at 08:14
1

With most basic shell commands:

grep metadata ~/.jupyter/lab/workspaces/* | sed -e 's/"/ /g' | awk '{print $(NF-1)}'

Output will look like:

/lab
/lab/workspaces/auto-x
/lab/workspaces/foo