msticpy.data.core.query_source module

Intake kql driver.

class msticpy.data.core.query_source.QuerySource(name: str, source: Dict[str, Any], defaults: Dict[str, Any], metadata: Dict[str, Any])

Bases: object

Query definition class for templated queries.

name

The query name

Type:

str

metadata

The consolidated metadata for the query

Type:

Dict[str, Any]

params

The dictionary of parameter definitions for the query.

Type:

dict[str, Any]

query_store

The query store object that the query belongs to

Type:

QueryStore

Initialize query source definition.

Parameters:
  • name (str) – The query name

  • source (dict) – The data source definition settings

  • defaults (dict) – The default settings (if source-specific setting not supplied)

  • metadata (dict) – The global metadata from the source file.

Notes

A data source can belong to multiple families (e.g. a query that joins data from several sources)

create_doc_string() str

Return a doc string for the query.

Returns:

New-line delimited docstring dynamically created from query definition properties.

Return type:

str

create_query(formatters: Dict[str, Callable] | None = None, **kwargs) str

Return query with values from kwargs and defaults substituted.

Parameters:
  • formatters (Dict[str, Callable]) – Dictionary of custom parameter formatters indexed by data type

  • kwargs (Mapping[str, Any]) – Set of parameter name, value pairs used to populate the template query.

Returns:

The populated query

Return type:

str

Raises:

ValueError – If one or more parameters with no default values are not supplied.

Notes

Parameters supplied as arguments will override any parameter defaults (see default_params property).

property data_families: List[str]

Return the list of data families used by the query.

Returns:

The list of data families. A data family is usually equivalent to a table or entity set.

Return type:

List[str]

property default_params: Dict[str, dict]

Return the set of parameters with default values.

Returns:

List of parameters

Return type:

Iterable[dict]

property description: str

Return description of the query.

Returns:

Query description.

Return type:

str

help()

Print help for query.

property query: str

Return the query template.

Returns:

The template query.

Return type:

str

property required_params: Dict[str, dict]

Return the set of parameters with no default values.

Returns:

List of parameters

Return type:

Iterable[dict]

resolve_param_aliases(param_dict: Dict[str, Any]) Dict[str, Any]

Try to resolve any parameters in param_dict that are aliases.

validate() Tuple[bool, List[str]]

Validate the source to ensure that all required properties are present.

Returns:

True if validation is successful.

Return type:

bool