hezar.utils.common_utils module

hezar.utils.common_utils.colorize_text(text: str, color: str | Color)[source]

Add colorization codes to the text. The output is the text with surrounding color codes and the colors are applied on the console/terminal output like when using print()

class hezar.utils.common_utils.exec_timer[source]

Bases: object

A context manager that captures the execution time of all the operations inside it

Examples

>>> with exec_timer() as timer:
>>>     # operations here
>>> print(timer.time)
hezar.utils.common_utils.is_text_valid(text, valid_characters)[source]

Given a list of valid characters, check if only those are included in the text

hezar.utils.common_utils.is_url(text)[source]
hezar.utils.common_utils.permute_dict_list(dict_list: List[Dict]) Dict[str, List][source]

Convert a list of dictionaries to a dictionary of lists

Parameters:

dict_list – Input list of dicts

Returns:

hezar.utils.common_utils.reverse_string_digits(text)[source]

Reverse all digit segments in a given text

hezar.utils.common_utils.sanitize_function_parameters(func: Callable, params: Dict | Mapping, **kwargs)[source]

Given a dict of parameters or kwargs, you can figure out which ones must be passed to the func based on its signature.

Parameters:
  • func – The function object

  • params – A dict of parameters with values

  • kwargs – Keyword arguments that are merged with params

Returns:

The proper dict of parameters keys and values

hezar.utils.common_utils.snake_case(s)[source]