utils.rcclient.libs.dynamic_templates

Subpackages

Submodules

Package Contents

Classes

TemplateV2

A class representing a Template.

TemplateInputV2

A dataclass representing a template input.

NotebookExecStage

Create a collection of name/value pairs.

TemplateType

str(object='') -> str

Constant

LogUtil

Functions

__generate_base_transforms(template, kwargs)

template(template_obj)

Attributes

logger

class utils.rcclient.libs.dynamic_templates.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
type: utils.rcclient.enums.TemplateType
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.rcclient.libs.dynamic_templates.TemplateInputV2

Bases: utils.rcclient.commons.abstract_dataclass.AbstractDataClass

A dataclass representing a template input.

name

The name of the template input.

Type:

str

metadata

The metadata associated with the input.

Type:

Metadata, optional

name: str
metadata: Metadata
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:

TemplateInputV2

__post_init__()
class utils.rcclient.libs.dynamic_templates.NotebookExecStage(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

NOTEBOOK_ON_UI = 'NOTEBOOK_ON_UI'
MANUAL_RUN = 'MANUAL_RUN'
COMPILE_TIME = 'COMPILE_TIME'
RUN_TIME = 'RUN_TIME'
classmethod from_val(val)
class utils.rcclient.libs.dynamic_templates.TemplateType

Bases: str, enum.Enum

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

NOTEBOOK = 'NOTEBOOK'
PYTHON_FUNC = 'PYTHON_FUNC'
CODE = 'CODE'
class utils.rcclient.libs.dynamic_templates.Constant
CLIENT_SDK_VERSION = '0.18'
FUNC_TEMPLATE_EXECUTER_NOTEBOOK = 'func_template_executer.ipynb'
FUNC_TEMPLATES_REMOTE_LOC = 'system-templates/func_templates'
DEFAULT_GCS_KEY = 'GOOGLE_APPLICATION_CREDENTIALS'
DEFAULT_BUCKET_KEY = 'BUCKET_NAME'
class utils.rcclient.libs.dynamic_templates.LogUtil
classmethod get_logger()
classmethod get_plain_logger()
classmethod get_pandas_logger()
classmethod get_papermill_logger()
classmethod set_basic_config(format='%(levelname)s:%(message)s', level=logging.INFO)
classmethod highlight_msg(msg: str)
utils.rcclient.libs.dynamic_templates.logger
utils.rcclient.libs.dynamic_templates.__generate_base_transforms(template: utils.rc.dtos.template_v2.TemplateV2, kwargs: dict)
utils.rcclient.libs.dynamic_templates.template(template_obj: utils.rc.dtos.template_v2.TemplateV2)