How can I list all existing workspaces in JupyterLab?
I know that one can view the current workspace name in the URL:
How can I list all existing workspaces in JupyterLab?
I know that one can view the current workspace name in the URL:
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
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
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