11import time , warnings , sys , os .path as osp
22from .dataset import DSSDataset , DSSManagedDatasetCreationHelper
33from .recipe import DSSRecipe
4+ from . import recipe
45from .managedfolder import DSSManagedFolder
56from .savedmodel import DSSSavedModel
67from .job import DSSJob , DSSJobWaiter
@@ -829,13 +830,9 @@ def list_recipes(self):
829830
830831 def get_recipe (self , recipe_name ):
831832 """
832- Get a handle to interact with a specific recipe
833-
834- Args:
835- recipe_name: the name of the desired recipe
836-
837- Returns:
838- A :class:`dataikuapi.dss.recipe.DSSRecipe` recipe handle
833+ Gets a :class:`dataikuapi.dss.recipe.DSSRecipe` handle to interact with a recipe
834+ :param str recipe_name: The name of the recipe
835+ :rtype :class:`dataikuapi.dss.recipe.DSSRecipe`
839836 """
840837 return DSSRecipe (self .client , self .project_key , recipe_name )
841838
@@ -862,6 +859,67 @@ def create_recipe(self, recipe_proto, creation_settings):
862859 body = definition )['name' ]
863860 return DSSRecipe (self .client , self .project_key , recipe_name )
864861
862+ def new_recipe (self , type , name ):
863+ """
864+ Initializes the creation of a new recipe. Returns a :class:`dataikuapi.dss.recipe.DSSRecipeCreator`
865+ or one of its subclasses to complete the creation of the recipe.
866+
867+ Usage example:
868+
869+ .. code-block:: python
870+
871+ grouping_recipe_builder = project.new_recipe("grouping")
872+ grouping_recipe_builder.with_input("dataset_to_group_on")
873+ # Create a new managed dataset for the output in the "filesystem_managed" connection
874+ grouping_recipe_builder.with_new_output("grouped_dataset", "filesystem_managed")
875+ grouping_recipe_builder.with_group_key("column")
876+ recipe = grouping_recipe_builder.build()
877+
878+ # After the recipe is created, you can edit its settings
879+ recipe_settings = recipe.get_settings()
880+ recipe_settings.set_column_aggregations("value", sum=True)
881+ recipe_settings.save()
882+
883+ # And you may need to apply new schemas to the outputs
884+ recipe.compute_schema_updates().apply()
885+
886+ :param str type: Type of the recipe
887+ :rtype: :class:`dataikuapi.dss.recipe.DSSRecipeCreator`
888+ """
889+
890+ if type == "grouping" :
891+ return recipe .GroupingRecipeCreator (name , self )
892+ elif type == "window" :
893+ return recipe .WindowRecipeCreator (name , self )
894+ elif type == "sync" :
895+ return recipe .SyncRecipeCreator (name , self )
896+ elif type == "sort" :
897+ return recipe .SortRecipeCreator (name , self )
898+ elif type == "topn" :
899+ return recipe .TopNRecipeCreator (name , self )
900+ elif type == "distinct" :
901+ return recipe .DistinctRecipeCreator (name , self )
902+ elif type == "join" :
903+ return recipe .JoinRecipeCreator (name , self )
904+ elif type == "vstack" :
905+ return recipe .StackRecipeCreator (name , self )
906+ elif type == "sampling" :
907+ return recipe .SamplingRecipeCreator (name , self )
908+ elif type == "split" :
909+ return recipe .SplitRecipeCreator (name , self )
910+ elif type == "prepare" or type == "shaker" :
911+ return recipe .PrepareRecipeCreator (name , self )
912+ elif type == "prediction_scoring" :
913+ return recipe .PredictionScoringRecipeCreator (name , self )
914+ elif type == "clustering_scoring" :
915+ return recipe .ClusteringScoringRecipeCreator (name , self )
916+ elif type == "download" :
917+ return recipe .DownloadRecipeCreator (name , self )
918+ elif type == "sql_query" :
919+ return recipe .SQLQueryRecipeCreator (name , self )
920+ elif type in ["python" , "r" , "sql_script" , "pyspark" , "sparkr" , "spark_scala" , "shell" ]:
921+ return recipe .CodeRecipeCreator (name , type , self )
922+
865923 ########################################################
866924 # Flow
867925 ########################################################
0 commit comments