Skip to content

Commit 74840b8

Browse files
authored
Merge pull request #70 from dataiku/feature/dss80-scenario-api
Overhaul of scenario API
2 parents badb1ec + e2b4a76 commit 74840b8

File tree

2 files changed

+444
-97
lines changed

2 files changed

+444
-97
lines changed

dataikuapi/dss/project.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from .managedfolder import DSSManagedFolder
77
from .savedmodel import DSSSavedModel
88
from .job import DSSJob, DSSJobWaiter
9+
from .scenario import DSSScenario, DSSScenarioListItem
910
from .continuousactivity import DSSContinuousActivity
10-
from .scenario import DSSScenario
1111
from .apiservice import DSSAPIService
1212
from .future import DSSFuture
1313
from .notebook import DSSNotebook
@@ -907,18 +907,22 @@ def preload_bundle(self, bundle_id):
907907
# Scenarios
908908
########################################################
909909

910-
def list_scenarios(self):
910+
def list_scenarios(self, as_type="listitems"):
911911
"""
912912
List the scenarios in this project.
913913
914-
This method returns a list of Python dictionaries. Each dictionary represents
915-
a scenario. Each dictionary contains at least a "id" field, that you can then pass
916-
to the :meth:`get_scenario`
917-
918-
:returns: the list of scenarios, each one as a Python dictionary
914+
:param str as_type: How to return the list. Supported values are "listitems" and "objects".
915+
:returns: The list of the datasets. If "rtype" is "listitems", each one as a :class:`scenario.DSSScenarioListItem`.
916+
If "rtype" is "objects", each one as a :class:`scenario.DSSScenario`
917+
:rtype: list
919918
"""
920-
return self.client._perform_json(
921-
"GET", "/projects/%s/scenarios/" % self.project_key)
919+
items = self.client._perform_json("GET", "/projects/%s/scenarios/" % self.project_key)
920+
if as_type == "listitems":
921+
return [DSSScenarioListItem(self.client, item) for item in items]
922+
elif as_type == "objects":
923+
return [DSSScenario(self.client, self.project_key, item["id"]) for item in items]
924+
else:
925+
raise ValueError("Unknown as_type")
922926

923927
def get_scenario(self, scenario_id):
924928
"""

0 commit comments

Comments
 (0)