msticpy.common.utility.ipython module

Notebook utility functions.

msticpy.common.utility.ipython.is_ipython(notebook: bool = False) bool

Return True if running in IPython environment.

Parameters:

notebook (bool, optional) – If notebook is true this will only return true if running in a Jupyter notebook.

Returns:

True if running in IPython environment, otherwise False

Return type:

bool

msticpy.common.utility.ipython.md(string: str, styles: str | Iterable[str] | None = None, disp_id: bool | IPython.display.DisplayHandle | None = None) IPython.display.DisplayHandle | None

Display a string as Markdown with optional style.

Parameters:
  • string (str) – The string to display

  • styles (Union[str, Iterable[str]], optional) – A style mnemonic or collection of styles. If multiple styles, these can be supplied as an interable of strings or a comma-separated string, by default None

  • disp_id (Optional[Union[bool, DisplayHandle]], optional) – If True, the function will return a display handle that can be re-used in subsequent calls to update the display object. If this is previously-created display handle, this is used as the target display object to update it with the content of this call, by default None

Returns:

A handle to the display object that can be used to update the contents.

Return type:

DisplayHandle

msticpy.common.utility.ipython.md_error(string: str, disp_id: IPython.display.DisplayHandle | None = None)

Return string as an error - red text prefixed by “Error”.

Parameters:
  • string (str) – The error message.

  • disp_id (Optional[Union[bool, DisplayHandle]], optional) – If True, the function will return a display handle that can be re-used in subsequent calls to update the display object. If this is previously-created display handle, this is used as the target display object to update it with the content of this call, by default None

msticpy.common.utility.ipython.md_warn(string: str, disp_id: IPython.display.DisplayHandle | None = None)

Return string as a warning - orange text prefixed by “Warning”.

Parameters:
  • string (str) – The warning message.

  • disp_id (Optional[DisplayHandle], optional) – If True, the function will return a display handle that can be re-used in subsequent calls to update the display object. If this is previously-created display handle, this is used as the target display object to update it with the content of this call, by default None

Returns:

A handle to the display object that can be used to update the contents.

Return type:

DisplayHandle

msticpy.common.utility.ipython.save_obj_to_cell(obj: Any, var_name: str)

Save a pickle-able object to a new cell.

Parameters:
  • obj (Any) – The object to be stored. Must be pickle-able.

  • var_name (str) – The variable name use to restore the object in the new cell.

Raises:

TypeError – If the object does not support pickling.

Notes

Saves obj as picked, base64-encoded blob to a new notebook cell.