msticpy.config.query_editor module

Query Editor.

class msticpy.config.query_editor.CustomChange(new: Any)

Bases: object

Dummy ipywidgets change event.

new: Any
class msticpy.config.query_editor.IPyDisplayMixin(*args: Any, **kwargs: Any)

Bases: LayoutProperties

IPython display mixin class.

display() None

Display the interactive widgets.

class msticpy.config.query_editor.MetadataEditWidget(*args: Any, **kwargs: Any)

Bases: IPyDisplayMixin

A class for editing Metadata properties.

Initialize a MetadataEditWidget object.

Parameters:

metadata (Metadata) – A Metadata object.

property changed_data: bool

Return True if data has changed.

display() None

Display the GUI widget.

populate_widgets() None

Populate the widgets with the metadata of the Metadata object.

reset_changed_data() None

Reset changed data flag.

save_metadata(button: ipywidgets.Button) None

Save the values to the Metadata object.

set_metadata(metadata: QueryMetadata) None

Set the metadata object.

class msticpy.config.query_editor.QueryEditWidget(*args: Any, **kwargs: Any)

Bases: IPyDisplayMixin

A class for editing queries.

Initialize a QueryEditWidget object.

Parameters:

query_collection (QueryCollection) – A collection of queries.

add_query(button: ipywidgets.Button) None

Add a new query.

Parameters:

button (Button) – The button object.

property changed_data: bool

Return True if data has changed.

delete_query(button: ipywidgets.Button) None

Delete a query.

Parameters:

button (Button) – The button object.

display() None

Display the interactive widgets.

populate_query_dropdown(change: Any) None

Populate the query dropdown widget.

Parameters:

change (Any) – The change event.

populate_widgets(change: CustomChange) None

Populate the query widgets with the data of a query.

Parameters:

change (Any) – The change event.

reset_changed_data() None

Reset changed data flag.

save_query(button: ipywidgets.Button) None

Save the data of a query.

Parameters:

button (Button) – The button object.

set_query_collection(query_collection: QueryCollection) None

Set the query collection.

class msticpy.config.query_editor.QueryEditor(*args: Any, **kwargs: Any)

Bases: IPyDisplayMixin

Query template editor.

Initialize the QueryEditor.

Parameters:

query_file (Union[QueryCollection, Path, str, None], optional) – The query collection to edit, can be a string or pathlib Path object for a file to load, or a QueryCollection object. By default None

property current_file: str

Return the current file name.

display() None

Display the interactive widgets.

class msticpy.config.query_editor.QueryParameterEditWidget(*args: Any, **kwargs: Any)

Bases: IPyDisplayMixin

Class to manage editing of query parameters.

This class provides a graphical user interface for editing query parameters. It allows users to add, modify, and delete parameters, as well as specify their names, descriptions, types, default values, and whether they are mandatory.

_changed_data

A flag indicating whether the data has been changed.

Type:

bool

param_container

The container for the query parameters.

Type:

Union[Query, QueryDefaults]

parameter_dropdown

A widget for selecting a parameter to edit.

Type:

ipywidgets.Select

parameter_name_widget

A widget for editing the name of a parameter.

Type:

ipywidgets.Text

description_widget

A widget for editing the description of a parameter.

Type:

ipywidgets.Text

type_widget

A widget for selecting the type of a parameter.

Type:

ipywidgets.Dropdown

default_reqd_widget

A widget for indicating whether a default value is required for a parameter.

Type:

ipywidgets.Checkbox

Initialize the class.

add_parameter(button: ipywidgets.Button) None

Add a new parameter.

property changed_data: bool

Return True if data has changed.

delete_parameter(button: ipywidgets.Button) None

Delete parameter item.

display() None

Display the interactive widgets.

populate_widgets(change: CustomChange) None

Populate parameter value in widgets.

reset_changed_data() None

Reset changed data flag.

save_parameter(button: ipywidgets.Button) None

Save currently edited parameter.

set_param_container(container: Query | QueryDefaults) None

Set the parameter container.

class msticpy.config.query_editor.YamlLiteralBlockContext(dumper: type[~yaml.dumper.SafeDumper] = <class 'yaml.dumper.SafeDumper'>)

Bases: object

Context manager to temporarily force multiline strings to literal style.

Initialize the context manager.

msticpy.config.query_editor.box_layout() dict[str, Any]

Return a dictionary with layout and style for a box widget.

Returns:

A dictionary with layout and style for a select widget.

Return type:

Dict

msticpy.config.query_editor.load_queries_from_yaml(yaml_file: str | Path) QueryCollection

Load a YAML file into a QueryCollection.

Parameters:

yaml_file (Union[str, Path]) – The path to the YAML file to load.

Returns:

A QueryCollection object containing the loaded queries.

Return type:

QueryCollection

msticpy.config.query_editor.replace_in_query(param_name: str, param: QueryParameter, src_name: str, query: str) str

Replace a parameter in a query string with a formatted string.

Parameters:
  • param_name (str) – The name of the parameter to replace.

  • param (Parameter) – The parameter object containing the datatype of the parameter.

  • src_name (str) – The name of the source to replace in the query string.

  • query (str) – The query string to replace the source in.

Returns:

The query string with the source replaced by the formatted parameter string.

Return type:

str

msticpy.config.query_editor.save_queries_to_yaml(query_collection: QueryCollection, yaml_file: str | Path) None

Save a QueryCollection to a YAML file.

Parameters:
  • query_collection (QueryCollection) – The QueryCollection object to save to YAML.

  • yaml_file (Union[str, Path]) – The path to the YAML file to save.

msticpy.config.query_editor.sel_fmt(width: str = '40%', height: str = '150px') dict[str, Any]

Return a dictionary with layout and style for a select widget.

Parameters:
  • width (str, optional) – The width of the widget, by default “40%”

  • height (str, optional) – The height of the widget, by default “150px”

Returns:

A dictionary with layout and style for a select widget.

Return type:

Dict

msticpy.config.query_editor.txt_fmt(width: str = '70%') dict[str, Any]

Return a dictionary with layout and style for a text widget.

Parameters:
  • width (str, optional) – The width of the widget, by default “70%”

  • height (str, optional) – The height of the widget, by default “20px”

Returns:

A dictionary with layout and style for a text widget.

Return type:

Dict

msticpy.config.query_editor.txtarea_fmt(width: str = '70%', height: str = '150px') dict[str, Any]

Return a dictionary with layout and style for a textarea widget.

Parameters:
  • width (str, optional) – The width of the widget, by default “70%”

  • height (str, optional) – The height of the widget, by default “150px”

Returns:

A dictionary with layout and style for a textarea widget.

Return type:

Dict