Skip to content

Commit 034ee6f

Browse files
committed
feat: FDG API
1 parent dc5e5dd commit 034ee6f

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

dataikuapi/dss/flow.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from ..utils import _write_response_content_to_file
12
from .utils import AnyLoc
23
from .dataset import DSSDataset
34
from .managedfolder import DSSManagedFolder
@@ -8,6 +9,7 @@
89
from .streaming_endpoint import DSSStreamingEndpoint
910
import logging, json
1011

12+
1113
class DSSProjectFlow(object):
1214
def __init__(self, client, project):
1315
self.client = client
@@ -111,6 +113,58 @@ def replace_input_computable(self, current_ref, new_ref, type="DATASET"):
111113
dap.replace_input(current_ref, new_ref)
112114
recipe_obj.set_definition_and_payload(dap)
113115

116+
def generate_documentation(self, folder_id=None, path=None):
117+
"""
118+
Start the flow document generation from a template docx file in a managed folder,
119+
or from the default template if no folder id and path are specified.
120+
121+
:param folder_id: (optional) the id of the managed folder
122+
:param path: (optional) the path to the file from the root of the folder
123+
:return: A :class:`~dataikuapi.dss.future.DSSFuture` representing the flow document generation process
124+
"""
125+
if bool(folder_id) != bool(path):
126+
raise ValueError("Both folder id and path arguments are required to use a template from folder. " +
127+
"Use without argument to generate the flow documentation using the default template")
128+
129+
template_mode_url = "" if folder_id is None and path is None else "-with-template-in-folder"
130+
131+
f = self.client._perform_json("POST", "/projects/%s/flow/documentation/generate%s" % (self.project.project_key, template_mode_url),
132+
params={"folderId": folder_id, "path": path})
133+
return DSSFuture(self.client, f["jobId"])
134+
135+
def generate_documentation_from_custom_template(self, fp):
136+
"""
137+
Start the flow document generation from a docx template (as a file object).
138+
139+
:param object fp: A file-like object pointing to a template docx file
140+
:return: A :class:`~dataikuapi.dss.future.DSSFuture` representing the flow document generation process
141+
"""
142+
files = {'file': fp}
143+
f = self.client._perform_json("POST", "/projects/%s/flow/documentation/generate-with-template" % self.project.project_key, files=files)
144+
return DSSFuture(self.client, f["jobId"])
145+
146+
def download_documentation_stream(self, export_id):
147+
"""
148+
Download a flow documentation, as a binary stream.
149+
150+
Warning: this stream will monopolize the DSSClient until closed.
151+
152+
:param export_id: the id of the generated flow documentation returned as the result of the future
153+
:return: A :class:`~dataikuapi.dss.future.DSSFuture` representing the flow document generation process
154+
"""
155+
return self.client._perform_raw("GET", "/projects/%s/flow/documentation/generated/%s" % (self.project.project_key, export_id))
156+
157+
def download_documentation_to_file(self, export_id, path):
158+
"""
159+
Download a flow documentation into the given output file.
160+
161+
:param export_id: the id of the generated flow documentation returned as the result of the future
162+
:param path: the path where to download the flow documentation
163+
:return: None
164+
"""
165+
stream = self.download_documentation_stream(export_id)
166+
_write_response_content_to_file(stream, path)
167+
114168
########################################################
115169
# Flow tools
116170
########################################################

dataikuapi/dss/ml.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import re
22
from six import string_types
33

4+
from ..utils import _write_response_content_to_file
45
from ..utils import DataikuException
5-
from ..utils import DataikuUTF8CSVReader
6-
from ..utils import DataikuStreamedHttpUTF8CSVReader
76

87
import json, warnings
98
import time
109

11-
from .metrics import ComputedMetrics
1210
from .utils import DSSDatasetSelectionBuilder, DSSFilterBuilder
1311
from .future import DSSFuture
1412

13+
1514
class PredictionSplitParamsHandler(object):
1615
"""Object to modify the train/test splitting params."""
1716

@@ -1943,11 +1942,7 @@ def download_documentation_to_file(self, export_id, path):
19431942
:return: None
19441943
"""
19451944
stream = self.download_documentation_stream(export_id)
1946-
with open(path, 'wb') as f:
1947-
for chunk in stream.iter_content(chunk_size=10000):
1948-
if chunk:
1949-
f.write(chunk)
1950-
f.flush()
1945+
_write_response_content_to_file(stream, path)
19511946

19521947
class DSSMLDiagnostic(object):
19531948
"""

dataikuapi/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,11 @@ def _make_zipfile(output_filename, source_dir):
114114
arcname = os.path.join(os.path.relpath(root, relroot), file)
115115
zipfp.write(filename, arcname)
116116
return output_filename
117+
118+
119+
def _write_response_content_to_file(response, path):
120+
with open(path, 'wb') as f:
121+
for chunk in response.iter_content(chunk_size=10000):
122+
if chunk:
123+
f.write(chunk)
124+
f.flush()

0 commit comments

Comments
 (0)