Skip to content

Commit 99f7d79

Browse files
committed
Structured listing of recipes
1 parent 717755a commit 99f7d79

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

dataikuapi/dss/project.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time, warnings, sys, os.path as osp
22
from .dataset import DSSDataset, DSSDatasetListItem, DSSManagedDatasetCreationHelper
33
from .streaming_endpoint import DSSStreamingEndpoint, DSSStreamingEndpointListItem, DSSManagedStreamingEndpointCreationHelper
4-
from .recipe import DSSRecipe
4+
from .recipe import DSSRecipeListItem, DSSRecipe
55
from . import recipe
66
from .managedfolder import DSSManagedFolder
77
from .savedmodel import DSSSavedModel
@@ -990,15 +990,23 @@ def create_scenario(self, scenario_name, type, definition=None):
990990
# Recipes
991991
########################################################
992992

993-
def list_recipes(self):
993+
def list_recipes(self, as_type="listitems"):
994994
"""
995995
List the recipes in this project
996-
997-
Returns:
998-
the list of the recipes, each one as a JSON object
996+
997+
:param str as_type: How to return the list. Supported values are "listitems" and "objects".
998+
:returns: The list of the recipes. If "as_type" is "listitems", each one as a :class:`recipe.DSSRecipeListItem`.
999+
If "as_type" is "objects", each one as a :class:`recipe.DSSRecipe`
1000+
:rtype: list
9991001
"""
1000-
return self.client._perform_json(
1001-
"GET", "/projects/%s/recipes/" % self.project_key)
1002+
items = self.client._perform_json("GET", "/projects/%s/recipes/" % self.project_key)
1003+
if as_type == "listitems" or as_type == "listitem":
1004+
return [DSSRecipeListItem(self.client, item) for item in items]
1005+
elif as_type == "objects" or as_type == "object":
1006+
return [DSSRecipe(self.client, self.project_key, item["name"]) for item in items]
1007+
else:
1008+
raise ValueError("Unknown as_type")
1009+
10021010

10031011
def get_recipe(self, recipe_name):
10041012
"""

dataikuapi/dss/recipe.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,27 @@
22
from .utils import DSSTaggableObjectSettings
33
from .discussion import DSSObjectDiscussions
44
import json, logging, warnings
5+
from .utils import DSSTaggableObjectListItem, DSSTaggableObjectSettings
56

6-
#####################################################
7-
# Base classes
8-
#####################################################
7+
class DSSRecipeListItem(DSSTaggableObjectListItem):
8+
"""An item in a list of recipes. Do not instantiate this class, use :meth:`dataikuapi.dss.project.DSSProject.list_recipes`"""
9+
def __init__(self, client, data):
10+
super(DSSRecipeListItem, self).__init__(data)
11+
self.client = client
12+
13+
def to_recipe(self):
14+
"""Gets the :class:`DSSRecipe` corresponding to this dataset"""
15+
return DSSRecipe(self.client, self._data["projectKey"], self._data["name"])
16+
17+
@property
18+
def name(self):
19+
return self._data["name"]
20+
@property
21+
def id(self):
22+
return self._data["name"]
23+
@property
24+
def type(self):
25+
return self._data["type"]
926

1027
class DSSRecipe(object):
1128
"""

0 commit comments

Comments
 (0)