Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions dataikuapi/dss/jupyternotebook.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
10 changes: 5 additions & 5 deletions dataikuapi/dss/project.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apichery Hi the return explanation here If "as_type" is "names" is wrong, maybe you forgot to change it. I guess you can just say:
If "as_type" is "listitems", then each one as a dict.

: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")

Expand Down