utils.rc.dtos.template_v2
This module contains classes for working with templates.
- Classes:
Metadata TemplateInputV2 TemplateTransformV2 TemplateV2
- Functions:
clean_view get_all get_all_by_id get_all_by_name get_local_templates get_template_by find_by_name
Module Contents
Classes
Represents metadata about an entity primarily template but can be used |
|
A dataclass representing a template input. |
|
Dataclass for defining a transformation to be applied on a variable in a |
|
A class representing a Template. |
|
A class representing a Template. |
Attributes
- utils.rc.dtos.template_v2.logger
- class utils.rc.dtos.template_v2.Metadata
Bases:
utils.rcclient.commons.abstract_dataclass.AbstractDataClass
Represents metadata about an entity primarily template but can be used with other classes too.
- input_name
The name of the input field.
- Type:
str
- is_required
Whether the input field is required or optional.
- Type:
bool
- default_value
The default value of the input field.
- Type:
str
- multiple
Whether the input field can have multiple values.
- Type:
bool
- output
Whether the input field is for output only.
- Type:
bool
- tooltip
A tooltip message to display when the user hovers over the input field.
- Type:
str
- datatype
The data type(s) of the input field.
- Type:
List[str]
- options
The list of available options for the input field.
- Type:
List[str]
- constant_options
The list of constant options for the input field.
- Type:
List[str]
- dataset
The list of available datasets for the input field.
- Type:
List[str]
- input_name: str
- is_required: bool = False
- default_value: str
- multiple: bool
- output: bool
- tooltip: str
- datatype: list
- options: list
- constant_options: list
- dataset: list
- class utils.rc.dtos.template_v2.TemplateInputV2
Bases:
utils.rcclient.commons.abstract_dataclass.AbstractDataClass
A dataclass representing a template input.
- name
The name of the template input.
- Type:
str
- name: str
- classmethod from_(variable: utils.dtos.variable.Variable)
Constructs a TemplateInputV2 instance from a Variable instance.
- Parameters:
variable (Variable) – The Variable instance to construct the TemplateInputV2 instance from.
- Returns:
The constructed TemplateInputV2 instance.
- Return type:
- __post_init__()
- class utils.rc.dtos.template_v2.TemplateTransformV2
Bases:
utils.rcclient.commons.abstract_dataclass.AbstractDataClass
Dataclass for defining a transformation to be applied on a variable in a template.
- type
Type of transformation.
- Type:
str
- params
Parameters for the transformation.
- Type:
dict
- type: str
- params: dict
- class utils.rc.dtos.template_v2.TemplateV2
Bases:
utils.rcclient.commons.abstract_dataclass.AbstractDataClass
A class representing a Template.
Attributes:
- namestr
The name of the Template.
- display_namestr
The display name of the Template.
- idstr
The id of the Template.
- versionstr
The version of the Template.
- project_idstr
The project id of the Template.
- projectIdstr
The projectId of the Template.
- descriptionstr
The description of the Template.
- tagslist
The tags of the Template.
- requirementsstr
The requirements of the Template.
- baseTransformslist
The base transforms of the Template.
- base_transformslist
The base transforms of the Template.
- sourcestr
The source of the Template.
- statusstr
The status of the Template.
- inputslist
The inputs of the Template.
Methods:
- get_template_by(name: str, project_id: str = None, version: str = ‘1.0’,
refresh: bool = False, source: str = ‘SYSTEM’ ) -> Union[None, ‘TemplateV2’]:
Returns a Template object that matches the given arguments.
- clean_view(templates_dict, log_output: bool = True) -> dict:
Returns a clean dictionary of a list of Template objects.
- get_all() -> dict:
Returns a dictionary of all the Template objects.
- get_local_templates(project_id: str) -> dict:
Returns a dictionary of all the local Template objects.
- get_all_by_id() -> dict:
Returns a dictionary of all the Template objects by their ids.
- get_all_by_name() -> dict:
Returns a dictionary of all the Template objects by their names.
- find_by_name(name: str) -> Union[None, ‘TemplateV2’]:
Returns a Template object that matches the given name.
- disable():
Disables a Template object.
- publish(notebook_path=None):
Publishes a Template object.
- get_all_input_names() -> list:
Returns a list of all the input names of the Template object.
- delete():
Deletes a Template object.
- name: str
- display_name: str
- id: str
- version: str = '1.0'
- project_id: str
- projectId: str
- code: str
- description: str
- tags: list
- secondary_tags: list
- requirements: str = ''
- baseTransforms: list
- base_transforms: list
- source: str = 'PROJECT'
- status: str = 'ACTIVE'
- category: str = 'BASIC'
- inputs: list
- markdown: str
- __post_init__()
- classmethod get_template_by(name: str, project_id: str = None, version: str = '1.0', source: str = 'SYSTEM', refresh: bool = False)
Returns a template with the given name, project ID, version, and source.
- Parameters:
name – A string representing the name of the template.
project_id – An optional string representing the ID of the project associated with the template. If None, the template can belong to any project.
version – A string representing the version of the template. Defaults to ‘1.0’.
source – A string indicating whether to search for the template in the global (system) templates or in the local templates of a specific project. Defaults to SYSTEM.
refresh – A boolean indicating whether to refresh the template local cache before searching for the template. Defaults to False.
- Returns:
A dictionary representing the template with the given parameters, or None if no template matching the parameters was found.
- classmethod clean_view(templates_dict, log_output: bool = True)
Given a dictionary of templates, returns a dictionary with cleaned templates information.
- Parameters:
templates_dict (Dict[str, TemplateV2]) – A dictionary of templates, where keys are the names of the templates and values are instances of the TemplateV2 class. log_output (bool, optional): Whether to log output or not. Defaults to True.
- Returns:
A dictionary containing cleaned templates information.
- Return type:
Dict
- Raises:
TypeError – If templates_dict is not a dictionary or any of its values are not an instance of TemplateV2.
- classmethod create_code_template(recipe_name: str, project_id: str, code: str, markdown=None)
Creates a code template for a recipe.
- Parameters:
recipe_name (str) – The name of the recipe.
project_id (str) – The ID of the project.
code (str) – The code to include in the template.
- Returns:
The created code template.
- Return type:
template (Template)
- classmethod get_all()
Return a dictionary of all templates.
This method retrieves all templates from the TemplatesWrapper and creates a dictionary with the template IDs as keys and TemplateV2 objects as values.
- Returns:
A dictionary containing all templates, with template IDs as keys and TemplateV2 objects as values.
- classmethod get_local_templates(project_id: str)
Retrieve all local templates associated with a given project.
- Parameters:
project_id – A string representing the ID of the project to retrieve
for. (templates)
- Returns:
A dictionary where each key is the ID of a local template associated with the project, and each value is an instance of the TemplateV2 class representing the corresponding template.
- classmethod get_all_by_id()
Returns a dictionary mapping template IDs to TemplateV2 instances for all templates in the system.
- Returns:
A dictionary mapping template IDs to TemplateV2 instances.
- classmethod get_all_by_name()
Retrieves all templates as a dictionary with their names as keys.
- Returns:
A dictionary where the keys are the names of the templates and the values are instances of the TemplateV2 class.
- classmethod find_by_name(name: str)
Finds a template by name.
- Parameters:
name – A string representing the name of the template to find.
- Returns:
If a template with the specified name is found, returns a TemplateV2 instance representing that template. Otherwise, returns None.
- publish(notebook_path=None, validate_reqs=True)
Publishes the template on the platform.
- Parameters:
notebook_path (str) – The path to the notebook containing the template code.
- Raises:
ValueError – If the template name or project ID is not specified or if the template inputs are invalid.
- Returns:
None
- __build_base_transforms(notebook_path: str)
- get_all_input_names()
Returns a list of all the names of the input parameters of this TemplateV2 instance.
- Returns:
A list of strings representing the names of the input parameters of this TemplateV2 instance.
- delete()
Deletes the current template from the database. Raises an exception if the template is a global template sourced from the system and user is not publisher. Otherwise, sends a request to platform to delete the template from the database. Does nothing if the template has not been saved to the database yet.
- disable()
Disable the current template in the database. sends a request to platform to disable the template from the database. Does nothing if the template has not been saved to the database yet.
- update_tags(tags=[], secondary=[])
Update tags for the object. This method updates the tags associated with the object. :param tags: A list of primary tags to be associated with the object (default is an empty list). :type tags: List[str], optional :param Primary tags are used for general categorization or identification.: :param secondary: A list of secondary tags to be associated with the object (default is an empty list). :type secondary: List[str], optional :param Secondary tags can be used for additional metadata or finer-grained categorization.:
- Returns:
None
- enable()
Enable the current template in the database. Sends a request to platform to disable the template from the database. Does nothing if the template has not been saved to the database yet.
- classmethod __create_idx(all_templates)
- classmethod __get_key(t_dict)
- __convert_to_template_inputs(inputs: list)
- __handle_invalid_values()
- __handle_inputs()
- __validate_reqs()
- __get_base_transforms()
- __handle_template_nuances()
- __get_view_dict()
- class utils.rc.dtos.template_v2.FuncTemplate
Bases:
TemplateV2
A class representing a Template.
Attributes:
- namestr
The name of the Template.
- display_namestr
The display name of the Template.
- idstr
The id of the Template.
- versionstr
The version of the Template.
- project_idstr
The project id of the Template.
- projectIdstr
The projectId of the Template.
- descriptionstr
The description of the Template.
- tagslist
The tags of the Template.
- requirementsstr
The requirements of the Template.
- baseTransformslist
The base transforms of the Template.
- base_transformslist
The base transforms of the Template.
- sourcestr
The source of the Template.
- statusstr
The status of the Template.
- inputslist
The inputs of the Template.
Methods:
- get_template_by(name: str, project_id: str = None, version: str = ‘1.0’,
refresh: bool = False, source: str = ‘SYSTEM’ ) -> Union[None, ‘TemplateV2’]:
Returns a Template object that matches the given arguments.
- clean_view(templates_dict, log_output: bool = True) -> dict:
Returns a clean dictionary of a list of Template objects.
- get_all() -> dict:
Returns a dictionary of all the Template objects.
- get_local_templates(project_id: str) -> dict:
Returns a dictionary of all the local Template objects.
- get_all_by_id() -> dict:
Returns a dictionary of all the Template objects by their ids.
- get_all_by_name() -> dict:
Returns a dictionary of all the Template objects by their names.
- find_by_name(name: str) -> Union[None, ‘TemplateV2’]:
Returns a Template object that matches the given name.
- disable():
Disables a Template object.
- publish(notebook_path=None):
Publishes a Template object.
- get_all_input_names() -> list:
Returns a list of all the input names of the Template object.
- delete():
Deletes a Template object.
- source: str = 'PROJECT'