Last active
March 8, 2021 16:33
-
-
Save laurentperrinet/780e73753f7abdcf73dfefdbfbb639be to your computer and use it in GitHub Desktop.
How can I list all existing workspaces in JupyterLab?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
How can I list all existing workspaces in JupyterLab? | |
as answered @ | |
https://stackoverflow.com/questions/52656747/how-can-i-list-all-existing-workspaces-in-jupyterlab/53011827#53011827 | |
""" | |
import argparse | |
# construct the argument parse and parse the arguments | |
ap = argparse.ArgumentParser() | |
ap.add_argument("-f", "--full", action="store_true", required=False, | |
help="prints full path") | |
ap.add_argument("-u", "--url", action="store_true", required=False, | |
help="prints full path") | |
ap.add_argument("-H", "--host", required=False, help="use the given host", default='10.164.5.234') | |
ap.add_argument("-P", "--port", required=False, help="use the given port", default='8888') | |
args = vars(ap.parse_args()) | |
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: | |
id = json.load(read_file)['metadata']['id'] | |
if args['full']: | |
print('id', id, '/ fname', fname) | |
elif args['url']: | |
print(f"http://{args['host']}:{args['port']}/lab/workspaces/{id}") | |
else: | |
print('id', id) |
You can now specify a different host / port:
$ list_workspaces.py -u --host=127.0.0.1
http://127.0.0.1:8888/lab/workspaces/Unistellar
http://127.0.0.1:8888/lab/workspaces/hulk
http://127.0.0.1:8888/lab/workspaces/itwist
http://127.0.0.1:8888/lab/workspaces/TimeWarp
http://127.0.0.1:8888/lab/workspaces/NaturalPatterns
http://127.0.0.1:8888/lab/workspaces/MotionClouds
http://127.0.0.1:8888/lab/workspaces/laconeu
http://127.0.0.1:8888/lab/workspaces/pyavfcam
http://127.0.0.1:8888/lab/workspaces/LeCheap
http://127.0.0.1:8888/lab
http://127.0.0.1:8888/lab/workspaces/bbcp
http://127.0.0.1:8888/lab/workspaces/CODE
http://127.0.0.1:8888/lab/workspaces/blog
http://127.0.0.1:8888/lab/workspaces/test
http://127.0.0.1:8888/lab/workspaces/Where
http://127.0.0.1:8888/lab/workspaces/SDPC
$ list_workspaces.py -u --host=localhost
http://localhost:8888/lab/workspaces/Unistellar
http://localhost:8888/lab/workspaces/hulk
http://localhost:8888/lab/workspaces/itwist
http://localhost:8888/lab/workspaces/TimeWarp
http://localhost:8888/lab/workspaces/NaturalPatterns
http://localhost:8888/lab/workspaces/MotionClouds
http://localhost:8888/lab/workspaces/laconeu
http://localhost:8888/lab/workspaces/pyavfcam
http://localhost:8888/lab/workspaces/LeCheap
http://localhost:8888/lab
http://localhost:8888/lab/workspaces/bbcp
http://localhost:8888/lab/workspaces/CODE
http://localhost:8888/lab/workspaces/blog
http://localhost:8888/lab/workspaces/test
http://localhost:8888/lab/workspaces/Where
http://localhost:8888/lab/workspaces/SDPC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
now with URLs:
allows right-clicking and directly opening it