From 7c2bfc0ee37c39b5bba77c696892f1e540d0499f Mon Sep 17 00:00:00 2001 From: Arnaud PICHERY Date: Wed, 31 Mar 2021 20:08:48 +0200 Subject: [PATCH] Jupyter notebook API / last polish --- dataikuapi/dss/jupyternotebook.py | 21 +++++++++++++++++++++ dataikuapi/dss/project.py | 10 +++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/dataikuapi/dss/jupyternotebook.py b/dataikuapi/dss/jupyternotebook.py index ee6f4e95..b778db6c 100644 --- a/dataikuapi/dss/jupyternotebook.py +++ b/dataikuapi/dss/jupyternotebook.py @@ -1,4 +1,25 @@ from .discussion import DSSObjectDiscussions +from .utils import DSSTaggableObjectListItem + +class DSSJupyterNotebookListItem(DSSTaggableObjectListItem): + """An item in a list of Jupyter notebooks. Do not instantiate this class, use :meth:`dataikuapi.dss.project.DSSProject.list_jupyter_notebooks`""" + def __init__(self, client, data): + super(DSSJupyterNotebookListItem, self).__init__(data) + self.client = client + + def to_notebook(self): + """Gets the :class:`DSSJupyterNotebook` corresponding to this notebook""" + return DSSJupyterNotebook(self.client, self._data["projectKey"], self._data["name"]) + + @property + def name(self): + return self._data["name"] + @property + def language(self): + return self._data["language"] + @property + def kernel_spec(self): + return self._data["kernelSpec"] class DSSJupyterNotebook(object): def __init__(self, client, project_key, notebook_name): diff --git a/dataikuapi/dss/project.py b/dataikuapi/dss/project.py index 6ee2bc64..b01c4467 100644 --- a/dataikuapi/dss/project.py +++ b/dataikuapi/dss/project.py @@ -1,6 +1,6 @@ import time, warnings, sys, os.path as osp from .dataset import DSSDataset, DSSDatasetListItem, DSSManagedDatasetCreationHelper -from .jupyternotebook import DSSJupyterNotebook +from .jupyternotebook import DSSJupyterNotebook, DSSJupyterNotebookListItem from .notebook import DSSNotebook from .streaming_endpoint import DSSStreamingEndpoint, DSSStreamingEndpointListItem, DSSManagedStreamingEndpointCreationHelper from .recipe import DSSRecipeListItem, DSSRecipe @@ -839,11 +839,11 @@ def list_jupyter_notebooks(self, active=False, as_type="object"): :returns: The list of the notebooks. If "as_type" is "names", each one as a string, if "as_type" is "objects", each one as a :class:`dataikuapi.dss.notebook.DSSJupyterNotebook` :rtype: list of :class:`dataikuapi.dss.notebook.DSSJupyterNotebook` or list of String """ - notebook_names = self.client._perform_json("GET", "/projects/%s/jupyter-notebooks/" % self.project_key, params={"active": active}) - if as_type == "names" or as_type == "name": - return notebook_names + notebook_items = self.client._perform_json("GET", "/projects/%s/jupyter-notebooks/" % self.project_key, params={"active": active}) + if as_type == "listitems" or as_type == "listitem": + return [DSSJupyterNotebookListItem(self.client, notebook_item) for notebook_item in notebook_items] elif as_type == "objects" or as_type == "object": - return [DSSJupyterNotebook(self.client, self.project_key, notebook_name) for notebook_name in notebook_names] + return [DSSJupyterNotebook(self.client, self.project_key, notebook_item["name"]) for notebook_item in notebook_items] else: raise ValueError("Unknown as_type")