Skip to content

Commit fe66dfb

Browse files
authored
Jupyter notebook API / last polish (#138)
1 parent 21b8227 commit fe66dfb

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

dataikuapi/dss/jupyternotebook.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
from .discussion import DSSObjectDiscussions
2+
from .utils import DSSTaggableObjectListItem
3+
4+
class DSSJupyterNotebookListItem(DSSTaggableObjectListItem):
5+
"""An item in a list of Jupyter notebooks. Do not instantiate this class, use :meth:`dataikuapi.dss.project.DSSProject.list_jupyter_notebooks`"""
6+
def __init__(self, client, data):
7+
super(DSSJupyterNotebookListItem, self).__init__(data)
8+
self.client = client
9+
10+
def to_notebook(self):
11+
"""Gets the :class:`DSSJupyterNotebook` corresponding to this notebook"""
12+
return DSSJupyterNotebook(self.client, self._data["projectKey"], self._data["name"])
13+
14+
@property
15+
def name(self):
16+
return self._data["name"]
17+
@property
18+
def language(self):
19+
return self._data["language"]
20+
@property
21+
def kernel_spec(self):
22+
return self._data["kernelSpec"]
223

324
class DSSJupyterNotebook(object):
425
def __init__(self, client, project_key, notebook_name):

dataikuapi/dss/project.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time, warnings, sys, os.path as osp
22
from .dataset import DSSDataset, DSSDatasetListItem, DSSManagedDatasetCreationHelper
3-
from .jupyternotebook import DSSJupyterNotebook
3+
from .jupyternotebook import DSSJupyterNotebook, DSSJupyterNotebookListItem
44
from .notebook import DSSNotebook
55
from .streaming_endpoint import DSSStreamingEndpoint, DSSStreamingEndpointListItem, DSSManagedStreamingEndpointCreationHelper
66
from .recipe import DSSRecipeListItem, DSSRecipe
@@ -839,11 +839,11 @@ def list_jupyter_notebooks(self, active=False, as_type="object"):
839839
: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`
840840
:rtype: list of :class:`dataikuapi.dss.notebook.DSSJupyterNotebook` or list of String
841841
"""
842-
notebook_names = self.client._perform_json("GET", "/projects/%s/jupyter-notebooks/" % self.project_key, params={"active": active})
843-
if as_type == "names" or as_type == "name":
844-
return notebook_names
842+
notebook_items = self.client._perform_json("GET", "/projects/%s/jupyter-notebooks/" % self.project_key, params={"active": active})
843+
if as_type == "listitems" or as_type == "listitem":
844+
return [DSSJupyterNotebookListItem(self.client, notebook_item) for notebook_item in notebook_items]
845845
elif as_type == "objects" or as_type == "object":
846-
return [DSSJupyterNotebook(self.client, self.project_key, notebook_name) for notebook_name in notebook_names]
846+
return [DSSJupyterNotebook(self.client, self.project_key, notebook_item["name"]) for notebook_item in notebook_items]
847847
else:
848848
raise ValueError("Unknown as_type")
849849

0 commit comments

Comments
 (0)