Jupyter Routes

auth = dmda.DomoTokenAuth(
    domo_instance=os.environ["DOMO_DOJO_INSTANCE"],
    domo_access_token=os.environ["DOMO_DOJO_ACCESS_TOKEN"],
)


JUPYTER_TOKEN = " OT98Xy8sePH894pA7SgUhjEcjk1kHK"

![Tutorial Video pt 2 of 4]

GET Routes


source

JupyterAPI_WorkspaceStarted

 JupyterAPI_WorkspaceStarted (res, message:str=None)

base exception


source

JupyterAPI_Error

 JupyterAPI_Error (res, message:str=None)

base exception


source

get_jupyter_workspaces

 get_jupyter_workspaces (auth:domolibrary.client.DomoAuth.DomoAuth,
                         parent_class:str=None,
                         session:httpx.AsyncClient=None,
                         debug_num_stacks_to_drop=1, debug_api:bool=False,
                         debug_loop:bool=False)
workspaces = None
workspace_id = None

try:
    workspaces = (
        await get_jupyter_workspaces(auth, debug_loop=False, debug_api=False)
    ).response
    workspace = next((workspace for workspace in workspaces if workspace['name'] == 'learn_jupyter'))
    workspace_id = workspace["id"]

    print(workspace)
except Exception as e:
    print(e)
{'id': '1cfe9db4-5937-4889-beb3-a311fc42f246', 'name': 'learn_jupyter', 'description': '', 'created': '2024-02-22T17:13:54.653+00:00', 'updated': '2025-03-10T19:31:11.091+00:00', 'lastRun': '2025-03-10T19:31:11.091+00:00', 'instances': [{'started': '2025-03-10T18:51:52.386+00:00', 'lastActivity': '2025-03-10T19:28:47.690+00:00', 'url': 'https://domo-community.jupyter-prod1.domodatascience.com/hub/auth_refresh?domo_hostname=https%3A%2F%2Fdomo-community.domo.com&next=https%3A%2F%2Fdomo-community.jupyter-prod1.domodatascience.com%2Fuser%2Fdomo-community-1893952720%2F1cfe9db4%2F', 'status': 'RUNNING', 'userId': 1893952720}], 'inputConfiguration': [], 'outputConfiguration': [], 'owner': 1893952720, 'coOwners': [], 'bootstrapKernel': False, 'migrateFiles': False, 'jupyterKernel': 'PYTHON_3_9', 'cpu': 4.0, 'memory': 32.0, 'timeoutHours': 8, 'sharingEnabled': False, 'sharingEnabledBy': 0, 'accountConfiguration': [], 'collectionConfiguration': [], 'fileshareConfiguration': [], 'activityBasedTimeout': True}

source

get_jupyter_workspace_by_id

 get_jupyter_workspace_by_id (auth, workspace_id, parent_class:str=None,
                              session:httpx.AsyncClient=None,
                              debug_api:bool=False,
                              debug_num_stacks_to_drop=2)
(await get_jupyter_workspace_by_id(workspace_id=workspace_id, auth=auth)).response
{'id': '1cfe9db4-5937-4889-beb3-a311fc42f246',
 'name': 'learn_jupyter',
 'description': '',
 'created': '2024-02-22T17:13:54.653+00:00',
 'updated': '2025-03-10T19:31:11.091+00:00',
 'lastRun': '2025-03-10T19:31:11.091+00:00',
 'instances': [{'started': '2025-03-10T18:51:52.386+00:00',
   'lastActivity': '2025-03-10T19:28:47.690+00:00',
   'url': 'https://domo-community.jupyter-prod1.domodatascience.com/hub/auth_refresh?domo_hostname=https%3A%2F%2Fdomo-community.domo.com&next=https%3A%2F%2Fdomo-community.jupyter-prod1.domodatascience.com%2Fuser%2Fdomo-community-1893952720%2F1cfe9db4%2F',
   'status': 'RUNNING',
   'userId': 1893952720}],
 'inputConfiguration': [],
 'outputConfiguration': [{'dataSourceId': '84658e41-924e-499c-987b-f82dc10163cc',
   'alias': 'DomoStats - Accounts',
   'streamId': 1375}],
 'owner': 1893952720,
 'coOwners': [],
 'bootstrapKernel': False,
 'migrateFiles': False,
 'jupyterKernel': 'PYTHON_3_9',
 'cpu': 4.0,
 'memory': 32.0,
 'timeoutHours': 8,
 'instanceTypes': [{'cpu': 0.5, 'memory': 4.0},
  {'cpu': 1.0, 'memory': 8.0},
  {'cpu': 2.0, 'memory': 16.0},
  {'cpu': 4.0, 'memory': 32.0},
  {'cpu': 8.0, 'memory': 64.0},
  {'cpu': 16.0, 'memory': 128.0},
  {'cpu': 32.0, 'memory': 256.0}],
 'sharingEnabled': False,
 'accountConfiguration': [{'account_id': 92,
   'alias': 'username_password_auth'},
  {'account_id': 94,
   'alias': 'my_domo_community_access_token - updated 2024-02-23'},
  {'account_id': 100, 'alias': 'domo-community'},
  {'account_id': 88, 'alias': 'fake_account'}],
 'collectionConfiguration': [],
 'fileshareConfiguration': [],
 'activityBasedTimeout': True}

source

get_workspace_auth_token_params

 get_workspace_auth_token_params (workspace_id, auth,
                                  return_raw:bool=False)

params are needed for authenticating requests inside the workspace environment Note: you’ll also need a internally generated jupyter_token to authenticate requests returns { service_location , service_prefix}


source

parse_instance_service_location_and_prefix

 parse_instance_service_location_and_prefix (instance:dict, domo_instance)
try:
    print(await get_workspace_auth_token_params(workspace_id=workspace_id, auth=auth))

except JupyterAPI_WorkspaceStarted as e:
    print(e)
{'service_location': 'jupyter-prod1.domodatascience.com', 'service_prefix': '/user/domo-community-1893952720/1cfe9db4/'}

source

start_jupyter_workspace

 start_jupyter_workspace (workspace_id,
                          auth:domolibrary.client.DomoAuth.DomoAuth,
                          parent_class:str=None,
                          session:httpx.AsyncClient=None,
                          debug_num_stacks_to_drop=1,
                          debug_api:bool=False, return_raw:bool=False)
try:
    print(
        await start_jupyter_workspace(
            workspace_id=workspace_id,
            auth=auth,
            debug_api=False,
            return_raw=False,
        )
    )
except Exception as e:
    print(e)
🛑  JupyterAPI_Error 🛑 - function: get_traceback || status 500 || you may not have access to this workspace 1cfe9db4-5937-4889-beb3-a311fc42f246, is it shared with you? || OR may already be started -- Internal Server Error at domo-community

source

get_jupyter_content

 get_jupyter_content (auth:domolibrary.client.DomoAuth.DomoAuth,
                      content_path:str='', debug_api:bool=False,
                      debug_num_stacks_to_drop=1, parent_class:str=None,
                      session:httpx.AsyncClient=None)

sample implementation of get_jupyter_content

# currently must scrape from the API

workspace_params = await get_workspace_auth_token_params(
    workspace_id=workspace_id, auth=auth
)

dj_auth = dmda.DomoJupyterTokenAuth.convert_auth(
    auth=auth, jupyter_token=JUPYTER_TOKEN, **workspace_params
)

dj_auth
DomoJupyterTokenAuth(jupyter_token=' OT98Xy8sePH894pA7SgUhjEcjk1kHK', service_location='jupyter-prod1.domodatascience.com', service_prefix='/user/domo-community-1893952720/1cfe9db4/', domo_instance='domo-community', url_manual_login='https://domo-community.domo.com/auth/index?domoManualLogin=true', token_name='token_auth', user_id=1893952720, is_valid_token=True)
try:
    res = await get_jupyter_content(
        auth=dj_auth,
        debug_api=None,
    )

    print(res.response["content"])

except (JupyterAPI_Error, JupyterAPI_WorkspaceStarted, Exception) as e:
    print(e)
[{'name': 'tutorial', 'path': 'tutorial', 'last_modified': '2024-03-25T03:39:25.824000Z', 'created': '2024-03-25T03:39:25.824000Z', 'content': None, 'format': None, 'mimetype': None, 'size': None, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'directory'}, {'name': 'Untitled Folder 1', 'path': 'Untitled Folder 1', 'last_modified': '2025-03-10T19:31:12.296000Z', 'created': '2025-03-10T19:31:12.296000Z', 'content': None, 'format': None, 'mimetype': None, 'size': None, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'directory'}, {'name': 'admin', 'path': 'admin', 'last_modified': '2025-03-10T19:31:02.414000Z', 'created': '2025-03-10T19:31:02.414000Z', 'content': None, 'format': None, 'mimetype': None, 'size': None, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'directory'}, {'name': 'Untitled Folder', 'path': 'Untitled Folder', 'last_modified': '2025-03-10T19:30:41.339000Z', 'created': '2025-03-10T19:30:41.339000Z', 'content': None, 'format': None, 'mimetype': None, 'size': None, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'directory'}, {'name': 'new_folder', 'path': 'new_folder', 'last_modified': '2025-03-10T19:32:57.800000Z', 'created': '2025-03-10T19:32:57.800000Z', 'content': None, 'format': None, 'mimetype': None, 'size': None, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'directory'}, {'name': 'README.md', 'path': 'README.md', 'last_modified': '2025-03-10T18:54:29.252000Z', 'created': '2025-03-10T18:54:29.252000Z', 'content': None, 'format': None, 'mimetype': 'text/markdown', 'size': 3847, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'file'}, {'name': 'test_domolibrary', 'path': 'test_domolibrary', 'last_modified': '2024-06-04T00:59:23.527000Z', 'created': '2024-06-04T00:59:23.527000Z', 'content': None, 'format': None, 'mimetype': None, 'size': None, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'directory'}, {'name': 'domo_jupyter_examples', 'path': 'domo_jupyter_examples', 'last_modified': '2024-02-22T17:17:48.269000Z', 'created': '2024-02-22T17:17:48.269000Z', 'content': None, 'format': None, 'mimetype': None, 'size': None, 'writable': False, 'hash': None, 'hash_algorithm': None, 'type': 'directory'}]

update jupyter content

improve code maintenance by implementing a factory design patternx


source

generate_update_jupyter_body__new_content_path

 generate_update_jupyter_body__new_content_path (content_path)
tests = [
    './admin/hello_world.ipynb',
    './admin/new_folder',
    'admin',
    ''
]

for test in tests:
    print(f"{test} - {generate_update_jupyter_body__new_content_path(test)}")
./admin/hello_world.ipynb - admin
./admin/new_folder - admin
admin - 
 - 

source

generate_update_jupyter_body

 generate_update_jupyter_body (new_content, content_path:str)

factory to construct properly formed body

Type Details
new_content
content_path str my_folder/datatypes.ipynb

source

generate_update_jupyter_body_factory

 generate_update_jupyter_body_factory (value, names=None, module=None,
                                       qualname=None, type=None, start=1)

An enumeration.

generate_update_jupyter_body("hello world", "hi.md")
{'name': 'hi.md',
 'content': 'hello world',
 'path': '',
 'format': 'text',
 'type': 'file'}
generate_update_jupyter_body(None, "admin/new_folder")
{'name': 'new_folder',
 'content': None,
 'path': 'admin',
 'format': None,
 'type': 'directory'}

CRUD Routes


source

create_jupyter_obj

 create_jupyter_obj (auth:domolibrary.client.DomoAuth.DomoJupyterAuth,
                     new_content='', content_path:str='',
                     debug_api:bool=False, parent_class:str=None,
                     debug_num_stacks_to_drop=1,
                     session:httpx.AsyncClient=None)
Type Default Details
auth DomoJupyterAuth
new_content str
content_path str file name and location in jupyter
debug_api bool False
parent_class str None
debug_num_stacks_to_drop int 1
session AsyncClient None
try:
    await create_jupyter_obj(
        content_path="admin/", auth=dj_auth, debug_api=True
    )


except dmde.DomoError as e:
    print(e)
🐛 debugging get_data
{'body': {'content': '',
          'format': None,
          'name': 'admin',
          'path': 'admin',
          'type': 'directory'},
 'function_name': 'get_traceback',
 'headers': {'Connection': 'keep-alive',
             'Content-Type': 'application/json',
             'accept': 'application/json, text/plain',
             'authorization': 'Token  OT98Xy8sePH894pA7SgUhjEcjk1kHK',
             'x-domo-developer-token': '83ece44f1451d4b581e1191f98cd411164f0b5b6ad2755b3'},
 'method': 'POST',
 'params': None,
 'parent_class': None,
 'url': 'https://domo-community.jupyter-prod1.domodatascience.com/user/domo-community-1893952720/1cfe9db4/api/contents/'}
get_data: sending json
get_data_response <Response [201 Created]>
🐛 debugging get_data
{'body': {'path': 'admin/'},
 'function_name': 'get_traceback',
 'headers': {'Connection': 'keep-alive',
             'Content-Type': 'application/json',
             'accept': 'application/json, text/plain',
             'authorization': 'Token  OT98Xy8sePH894pA7SgUhjEcjk1kHK',
             'x-domo-developer-token': '83ece44f1451d4b581e1191f98cd411164f0b5b6ad2755b3'},
 'method': 'PATCH',
 'params': None,
 'parent_class': None,
 'url': 'https://domo-community.jupyter-prod1.domodatascience.com/user/domo-community-1893952720/1cfe9db4/api/contents/Untitled%20Folder%207'}
get_data: sending json
get_data_response <Response [409 Conflict]>
🛑  JupyterAPI_Error 🛑 - function: get_traceback || status 409 || conlict during PATCH - does the content already exist? at domo-community

source

delete_jupyter_content

 delete_jupyter_content (auth:domolibrary.client.DomoAuth.DomoJupyterAuth,
                         content_path:str, debug_api:bool=False,
                         parent_class:str=None,
                         debug_num_stacks_to_drop=1,
                         session:httpx.AsyncClient=None)
Type Default Details
auth DomoJupyterAuth
content_path str file name and location in jupyter
debug_api bool False
parent_class str None
debug_num_stacks_to_drop int 1
session AsyncClient None

source

update_jupyter_file

 update_jupyter_file (auth:domolibrary.client.DomoAuth.DomoJupyterAuth,
                      new_content, content_path:str='',
                      debug_api:bool=False, parent_class:str=None,
                      debug_num_stacks_to_drop=1,
                      session:httpx.AsyncClient=None)
Type Default Details
auth DomoJupyterAuth
new_content
content_path str file name and location in jupyter
debug_api bool False
parent_class str None
debug_num_stacks_to_drop int 1
session AsyncClient None

sample implementation of update_content

try:

    res = await update_jupyter_file(
        auth=dj_auth,
        content_path="new_folder",
        new_content=None,
        debug_api=False,
    )

    res.response

    res = await update_jupyter_file(
        auth=dj_auth,
        content_path=f"new_folder/updated_{dt.date.today()}.txt",
        new_content="jae is excellent at demoes",
        debug_api=False,
    )

    print(res.response)

except (JupyterAPI_Error, JupyterAPI_WorkspaceStarted) as e:
    print(e)
{'name': 'updated_2025-03-10.txt', 'path': 'new_folder/updated_2025-03-10.txt', 'last_modified': '2025-03-10T19:33:21.148000Z', 'created': '2025-03-10T19:33:21.148000Z', 'content': None, 'format': None, 'mimetype': 'text/plain', 'size': 26, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'file'}

recursive get_content

![Tutorial Video pt 3 of 4]


source

get_content

 get_content (auth:domolibrary.client.DomoAuth.DomoJupyterAuth,
              content_path='', is_recursive:bool=True,
              is_skip_recent_executions:bool=True,
              is_skip_default_files:bool=True, return_raw:bool=False,
              debug_api:bool=False, debug_num_stacks_to_drop=2,
              parent_class:str=None, session:httpx.AsyncClient=None)

sample implementation of get_content_recursive

try:
    res = await get_content(
        auth=dj_auth,
        debug_api=False,
        return_raw=True,
        is_recursive=False,
        content_path="new_folder",
    )

    # print(
    #     "num_files",
    #     len([content for content in res.response if content["type"] != "directory"]),
    # )
    # pd.DataFrame(res.logs).fillna(0)
    if res.response:
        display(pd.DataFrame(res.response))

    print(res.response)

except (JupyterAPI_Error, JupyterAPI_WorkspaceStarted) as e:
    print(e)
name path last_modified created content format mimetype size writable hash hash_algorithm type
0 new_folder new_folder 2025-03-10T19:33:21.153000Z 2025-03-10T19:33:21.153000Z {'name': 'my_great_demo.txt', 'path': 'new_fol... json None None True None None directory
1 new_folder new_folder 2025-03-10T19:33:21.153000Z 2025-03-10T19:33:21.153000Z {'name': 'updated_2024-08-26.txt', 'path': 'ne... json None None True None None directory
2 new_folder new_folder 2025-03-10T19:33:21.153000Z 2025-03-10T19:33:21.153000Z {'name': 'updated_2025-03-10.txt', 'path': 'ne... json None None True None None directory
3 new_folder new_folder 2025-03-10T19:33:21.153000Z 2025-03-10T19:33:21.153000Z {'name': 'updated_2024-03-06.txt', 'path': 'ne... json None None True None None directory
{'name': 'new_folder', 'path': 'new_folder', 'last_modified': '2025-03-10T19:33:21.153000Z', 'created': '2025-03-10T19:33:21.153000Z', 'content': [{'name': 'my_great_demo.txt', 'path': 'new_folder/my_great_demo.txt', 'last_modified': '2024-06-04T19:29:13.281000Z', 'created': '2024-06-04T19:29:13.281000Z', 'content': None, 'format': None, 'mimetype': 'text/plain', 'size': 26, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'file'}, {'name': 'updated_2024-08-26.txt', 'path': 'new_folder/updated_2024-08-26.txt', 'last_modified': '2024-08-26T20:06:53.080000Z', 'created': '2024-08-26T20:06:53.080000Z', 'content': None, 'format': None, 'mimetype': 'text/plain', 'size': 60, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'file'}, {'name': 'updated_2025-03-10.txt', 'path': 'new_folder/updated_2025-03-10.txt', 'last_modified': '2025-03-10T19:33:21.148000Z', 'created': '2025-03-10T19:33:21.148000Z', 'content': None, 'format': None, 'mimetype': 'text/plain', 'size': 26, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'file'}, {'name': 'updated_2024-03-06.txt', 'path': 'new_folder/updated_2024-03-06.txt', 'last_modified': '2024-08-26T19:33:03.415000Z', 'created': '2024-08-26T19:33:03.415000Z', 'content': None, 'format': None, 'mimetype': 'text/plain', 'size': 60, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'file'}], 'format': 'json', 'mimetype': None, 'size': None, 'writable': True, 'hash': None, 'hash_algorithm': None, 'type': 'directory'}

source

update_jupyter_workspace_config

 update_jupyter_workspace_config (auth, workspace_id, config:dict,
                                  parent_class:str=None,
                                  session:httpx.AsyncClient=None,
                                  debug_api:bool=False,
                                  debug_num_stacks_to_drop=2)