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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can now specify a different host / port: