sagemaker.core.utils.utils#

Functions

add_indent(text[, num_spaces])

Add customizable indent spaces to a given text.

clean_documentaion(documentation)

configure_logging([log_level])

Configure the logging configuration based on log level.

convert_to_snake_case(entity_name)

Convert a string to snake_case.

enable_textual_rich_console_and_traceback()

Reconfigure the global textual rich console with the customized theme

escape_special_rst_characters(text)

get_rich_handler()

get_textual_rich_logger(name[, log_level])

Get a logger with textual rich handler.

get_textual_rich_theme()

Get a textual rich theme with customized styling.

is_not_primitive(obj)

is_not_str_dict(obj)

is_primitive_class(cls)

is_primitive_list(obj)

is_snake_case(s)

pascal_to_snake(pascal_str)

Converts a PascalCase string to snake_case.

reformat_file_with_black(filename)

remove_html_tags(text)

serialize(value)

Serialize an object recursively by converting all objects to JSON-serializable types

snake_to_pascal(snake_str)

Convert a snake_case string to PascalCase.

Classes

ResourceIterator(client, summaries_key, ...)

ResourceIterator class to iterate over a list of resources.

SageMakerClient(*args, **kwargs)

A singleton class for creating a SageMaker client.

SingletonMeta

Singleton metaclass.

Unassigned()

A custom type used to signify an undefined optional argument.

class sagemaker.core.utils.utils.ResourceIterator(client: SageMakerClient, summaries_key: str, summary_name: str, resource_cls: Type[T], list_method: str, list_method_kwargs: dict = {}, custom_key_mapping: dict | None = None)[source]#

Bases: Generic[T]

ResourceIterator class to iterate over a list of resources.

class sagemaker.core.utils.utils.SageMakerClient(*args, **kwargs)[source]#

Bases: object

A singleton class for creating a SageMaker client.

get_client(service_name: str) Any[source]#

Get the client of corresponding service

Parameters:

service_name (str) – the service name

Returns:

the client of that service

Return type:

Any

class sagemaker.core.utils.utils.SingletonMeta[source]#

Bases: type

Singleton metaclass. Ensures that a single instance of a class using this metaclass is created.

class sagemaker.core.utils.utils.Unassigned[source]#

Bases: object

A custom type used to signify an undefined optional argument.

sagemaker.core.utils.utils.add_indent(text, num_spaces=4)[source]#

Add customizable indent spaces to a given text. :param text: The text to which the indent spaces will be added. :type text: str :param num_spaces: Number of spaces to be added for each level of indentation. Default is 4. :type num_spaces: int

Returns:

The text with added indent spaces.

Return type:

str

sagemaker.core.utils.utils.clean_documentaion(documentation)[source]#
sagemaker.core.utils.utils.configure_logging(log_level=None)[source]#

Configure the logging configuration based on log level.

Usage:

Set Environment Variable LOG_LEVEL to DEBUG to see debug logs configure_logging() configure_logging(“DEBUG”)

Parameters:

log_level (str) – The log level to set. Accepted values are: “DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL”. Defaults to the value of the LOG_LEVEL environment variable. If argument/environment variable is not set, defaults to “INFO”.

Raises:

AttributeError – If the log level is invalid.

sagemaker.core.utils.utils.convert_to_snake_case(entity_name)[source]#

Convert a string to snake_case. :param entity_name: The string to convert. :type entity_name: str

Returns:

The converted string in snake_case.

Return type:

str

sagemaker.core.utils.utils.enable_textual_rich_console_and_traceback()[source]#
Reconfigure the global textual rich console with the customized theme

and enable textual rich error traceback

sagemaker.core.utils.utils.escape_special_rst_characters(text)[source]#
sagemaker.core.utils.utils.get_rich_handler()[source]#
sagemaker.core.utils.utils.get_textual_rich_logger(name: str, log_level: str = 'INFO') Logger[source]#

Get a logger with textual rich handler.

Parameters:
  • name (str) – The name of the logger

  • log_level (str) – The log level to set. Accepted values are: “DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL”. Defaults to the value of “INFO”.

Returns:

A textial rich logger.

Return type:

logging.Logger

sagemaker.core.utils.utils.get_textual_rich_theme() Theme[source]#

Get a textual rich theme with customized styling.

Returns:

A textual rich theme

Return type:

Theme

sagemaker.core.utils.utils.is_not_primitive(obj)[source]#
sagemaker.core.utils.utils.is_not_str_dict(obj)[source]#
sagemaker.core.utils.utils.is_primitive_class(cls)[source]#
sagemaker.core.utils.utils.is_primitive_list(obj)[source]#
sagemaker.core.utils.utils.is_snake_case(s: str)[source]#
sagemaker.core.utils.utils.pascal_to_snake(pascal_str)[source]#

Converts a PascalCase string to snake_case.

Parameters:

pascal_str (str) – The PascalCase string to be converted.

Returns:

The converted snake_case string.

Return type:

str

sagemaker.core.utils.utils.reformat_file_with_black(filename)[source]#
sagemaker.core.utils.utils.remove_html_tags(text)[source]#
sagemaker.core.utils.utils.serialize(value: Any) Any[source]#

Serialize an object recursively by converting all objects to JSON-serializable types

Parameters:

value (Any) – The object to be serialized

Returns:

The serialized object

Return type:

Any

sagemaker.core.utils.utils.snake_to_pascal(snake_str)[source]#

Convert a snake_case string to PascalCase.

Parameters:

snake_str (str) – The snake_case string to be converted.

Returns:

The PascalCase string.

Return type:

str