List Jupyter workspaces and spot unused ones¶
The goal: list every Jupyter workspace in your instance with its size and last run time, and flag the ones that have never run.
The Managing Jupyter Workspaces guide already covers
fetching and listing workspaces with the DomoJupyterWorkspace classes, caching, and
the error to expect for a missing workspace. This recipe does one new job with the
route functions, so you see the raw answer from Domo. A workspace here is the Domo
object you see under Jupyter Workspaces, not a notebook inside it.
Before you start¶
crew-dcs is installed, and your .env file holds
DOMO_INSTANCE and DOMO_ACCESS_TOKEN (how). The script
only reads. It changes nothing in Domo.
The script¶
Save this as unused_workspaces.py next to your .env file:
import asyncio
import os
from dotenv import load_dotenv
from crew_dcs.auth import DomoTokenAuth
from crew_dcs.routes import jupyter as jupyter_routes
load_dotenv() # copies the lines in .env into environment variables
async def main():
async with DomoTokenAuth(
domo_instance=os.environ["DOMO_INSTANCE"],
domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
) as auth:
# 1. List the workspaces. Each one is a dictionary.
res = await jupyter_routes.get_jupyter_workspaces(auth=auth)
workspaces = res.response
print(len(workspaces), "workspaces")
# 2. Print the size and last run of each, and note the ones that never ran.
never_run = [] # an empty list we add names to
for ws in workspaces: # "for" repeats the lines below once per workspace
# .get() gives None, instead of an error, when a field is missing.
last_run = ws.get("lastRun")
print(ws["id"], ws.get("name"), "- memory", ws.get("memory"), "- cpu", ws.get("cpu"), "- last run", last_run)
if not last_run:
never_run.append(ws.get("name"))
print()
# ", ".join(...) glues the names together. "or" picks "none" when the list is empty.
print("Never run:", ", ".join(never_run) or "none")
# 3. Fetch one workspace in full by its id.
if workspaces:
res = await jupyter_routes.get_jupyter_workspace_by_id(
workspace_id=workspaces[0]["id"], auth=auth
)
print("First workspace in full:", res.response.get("name"))
asyncio.run(main())
Run it with uv run python unused_workspaces.py from the project folder where you
installed crew-dcs. (In a virtual environment, activate it and run
python unused_workspaces.py.)
What you should see¶
The script lists the workspaces the token's user can see. Yours will look like this. The last run is printed as Domo sends it, and the memory and cpu numbers depend on how each workspace was set up:
3 workspaces
a1b2c3 Churn model - memory 4.0 - cpu 0.5 - last run 2026-07-15T17:20:56.047+00:00
d4e5f6 Sales notebook - memory 2.0 - cpu 0.5 - last run None
g7h8i9 Scratch - memory 2.0 - cpu 0.5 - last run None
Never run: Sales notebook, Scratch
First workspace in full: Churn model
What the script does¶
get_jupyter_workspacestakes onlyauth. It fetches the workspaces in pages and gives you one list inres.response.- Each workspace is a dictionary.
lastRuncan be missing, which is why the script reads it with.get("lastRun"). A missing value is a workspace that has not run. get_jupyter_workspace_by_idfetches one workspace by its id.- A route given a bad id raises
Jupyter_GET_Error. The guide shows how to catch it.
The class version¶
If you want objects instead of dictionaries, DomoJupyterWorkspaces(auth=auth).get() does
the same listing of the workspaces the token's user can see. The guide shows it.
Check it in Domo¶
Open Jupyter Workspaces in Domo (under Data Center in some versions). The names should match the script's list. Open one workspace to see its size and when it last ran. (Menu names differ by Domo version.)
Errors you might hit¶
Each one is a kind of DomoError. The Errors page shows how to catch them.
Jupyter_GET_Error is importable from crew_dcs.routes.jupyter.exceptions.
| Error | Likely cause |
|---|---|
Jupyter_GET_Error |
Domo refused the read. For a single workspace, the id may be wrong or the token's user may not be able to see it. A wrong or expired token also lands here, with "Authentication required (HTTP 401)" in the message. |
To test a token on its own, use who_am_i() from Authenticating to Domo.