-
Notifications
You must be signed in to change notification settings - Fork 29
Python wrapper for Jupyter Notebooks Public API #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
601dd25
c5fbe90
d4f2f70
08301dc
a23d027
c9a9a06
54cba76
745fb80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,11 +4,12 @@ class DSSNotebook(object): | |||||
| """ | ||||||
| A Python/R/Scala notebook on the DSS instance | ||||||
| """ | ||||||
| def __init__(self, client, project_key, notebook_name, state=None): | ||||||
| def __init__(self, client, project_key, notebook_name, state=None, content=None): | ||||||
| self.client = client | ||||||
| self.project_key = project_key | ||||||
| self.notebook_name = notebook_name | ||||||
| self.state = state | ||||||
| self.content = content | ||||||
| self.state_is_peek = True | ||||||
|
|
||||||
| def unload(self, session_id=None): | ||||||
|
|
@@ -27,14 +28,19 @@ def unload(self, session_id=None): | |||||
| raise Exception("Several sessions of the notebook are running, choose one") | ||||||
| else: | ||||||
| session_id = state['activeSessions'][0].get('sessionId', None) | ||||||
| return self.client._perform_json("DELETE", "/projects/%s/notebooks/" % self.project_key, params={'notebookName' : self.notebook_name, 'sessionId' : session_id}) | ||||||
| return self.client._perform_json("DELETE", | ||||||
| "/projects/%s/jupyter-notebooks/%s/sessions/%s" % (self.project_key, self.notebook_name, session_id)) | ||||||
|
|
||||||
| def get_state(self): | ||||||
| """ | ||||||
| Get the status of the notebook | ||||||
| """ | ||||||
| if self.state is None: | ||||||
| self.state = self.client._perform_json("GET", "/projects/%s/notebooks/" % self.project_key, params={'notebookName' : self.notebook_name}) | ||||||
| notebook_list = self.client._perform_json("GET", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we keep the cache mechanism?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable contains the metadata of the notebook, not a notebook.
Suggested change
|
||||||
| "/projects/%s/jupyter-notebooks/" % self.project_key, | ||||||
| params={"active": False}) | ||||||
| for notebook in notebook_list: | ||||||
| if notebook.get("name") == self.notebook_name: | ||||||
| self.state = notebook | ||||||
|
apichery marked this conversation as resolved.
Outdated
|
||||||
| return self.state | ||||||
|
|
||||||
| def get_sessions(self): | ||||||
|
|
@@ -48,6 +54,30 @@ def get_sessions(self): | |||||
| raise Exception("Notebook isn't running") | ||||||
| return state['activeSessions'] | ||||||
|
|
||||||
| def get_content(self): | ||||||
| """ | ||||||
| Get the content of this notebook (metadata, cells, nbformat) | ||||||
| """ | ||||||
| if self.content is None: | ||||||
| self.content = self.client._perform_json("GET", | ||||||
| "/projects/%s/jupyter-notebooks/%s" % (self.project_key, self.notebook_name)) | ||||||
| return self.content | ||||||
|
|
||||||
| def save(self): | ||||||
| """ | ||||||
| Save the content of this notebook | ||||||
| """ | ||||||
| return self.client._perform_json("PUT", | ||||||
| "/projects/%s/jupyter-notebooks/%s" % (self.project_key, self.notebook_name), | ||||||
| body=self.content) | ||||||
|
|
||||||
| def delete(self): | ||||||
| """ | ||||||
| Delete this jupyter notebook and stop all of its active sessions. | ||||||
| """ | ||||||
| return self.client._perform_json("DELETE", | ||||||
| "/projects/%s/jupyter-notebooks/%s" % (self.project_key, self.notebook_name)) | ||||||
|
|
||||||
| ######################################################## | ||||||
| # Discussions | ||||||
| ######################################################## | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is (and was) not compatible with SQL notebooks