sempy_labs.tom package
Module contents
- class sempy_labs.tom.TOMWrapper(dataset, workspace, readonly)
Bases:
objectConvenience wrapper around the TOM object model for a semantic model. Always use the connect_semantic_model function to make sure the TOM object is initialized correctly.
XMLA read/write endpoints must be enabled if setting the readonly parameter to False.
- add_calculated_column(table_name: str, column_name: str, expression: str, data_type: str, format_string: str | None = None, hidden: bool = False, description: str | None = None, display_folder: str | None = None, data_category: str | None = None, key: bool = False, summarize_by: str | None = None, lineage_tag: str | None = None, source_lineage_tag: str | None = None)
Adds a calculated column to a table within a semantic model.
- Parameters:
table_name (str) – Name of the table in which the column will be created.
column_name (str) – Name of the column.
expression (str) – The DAX expression for the column.
data_type (str) – The data type of the column.
format_string (str, default=None) – Format string of the column.
hidden (bool, default=False) – Whether the column will be hidden or visible.
description (str, default=None) – A description of the column.
display_folder (str, default=None) – The display folder in which the column will reside.
data_category (str, default=None) – The data category of the column.
key (bool, default=False) – Marks the column as the primary key of the table.
summarize_by (str, default=None) – Sets the value for the Summarize By property of the column. Defaults to None which resolves to ‘Default’.
lineage_tag (str, default=None) – A tag that represents the lineage of the object.
source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.
- Returns:
The column object which was created.
- Return type:
TOM.Object
- add_calculated_table(name: str, expression: str, description: str | None = None, data_category: str | None = None, hidden: bool = False, lineage_tag: str | None = None, source_lineage_tag: str | None = None)
Adds a calculated table to the semantic model.
- Parameters:
name (str) – Name of the table.
expression (str) – The DAX expression for the calculated table.
description (str, default=None) – A description of the table.
data_catgegory (str, default=None) – The data category for the table.
hidden (bool, default=False) – Whether the table is hidden or visible.
lineage_tag (str, default=None) – A tag that represents the lineage of the object.
source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.
- Returns:
The table which was created.
- Return type:
TOM.Object
- add_calculated_table_column(table_name: str, column_name: str, source_column: str, data_type: str, format_string: str | None = None, hidden: bool = False, description: str | None = None, display_folder: str | None = None, data_category: str | None = None, key: bool = False, summarize_by: str | None = None, lineage_tag: str | None = None, source_lineage_tag: str | None = None)
Adds a calculated table column to a calculated table within a semantic model.
- Parameters:
table_name (str) – Name of the table in which the column will be created.
column_name (str) – Name of the column.
source_column (str) – The source column for the column.
data_type (str) – The data type of the column.
format_string (str, default=None) – Format string of the column.
hidden (bool, default=False) – Whether the column will be hidden or visible.
description (str, default=None) – A description of the column.
display_folder (str, default=None) – The display folder in which the column will reside.
data_category (str, default=None) – The data category of the column.
key (bool, default=False) – Marks the column as the primary key of the table.
summarize_by (str, default=None) – Sets the value for the Summarize By property of the column. Defaults to None resolves to ‘Default’.
lineage_tag (str, default=None) – A tag that represents the lineage of the object.
source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.
- add_calculation_group(name: str, precedence: int, description: str | None = None, hidden: bool = False, column_name: str = 'Name')
Adds a calculation group to a semantic model.
- Parameters:
name (str) – Name of the calculation group.
precedence (int) – The precedence of the calculation group.
description (str, default=None) – A description of the calculation group.
hidden (bool, default=False) – Whether the calculation group is hidden/visible.
column_name (str, default="Name") – The name of the calculation group column.
- Returns:
The calculation group which was created.
- Return type:
TOM.Object
- add_calculation_item(table_name: str, calculation_item_name: str, expression: str, ordinal: int | None = None, description: str | None = None, format_string_expression: str | None = None)
- Adds a calculation item to
a calculation group within a semantic model.
- Parameters:
table_name (str) – Name of the table in which the calculation item will be created.
calculation_item_name (str) – Name of the calculation item.
expression (str) – The DAX expression for the calculation item.
ordinal (int, default=None) – The ordinal of the calculation item.
format_string_expression (str, default=None) – The format string expression for the calculation item.
description (str, default=None) – A description of the calculation item.
- Returns:
The calculation item which was created.
- Return type:
TOM.Object
- add_changed_property(object, property: str)
Adds a ChangedProperty property to a semantic model object. Only adds the property if it does not already exist for the object.
- Parameters:
object (TOM Object) – The TOM object within the semantic model.
property (str) – The property to set (i.e. ‘Name’, ‘DataType’).
- add_data_column(table_name: str, column_name: str, source_column: str, data_type: str, format_string: str | None = None, hidden: bool = False, description: str | None = None, display_folder: str | None = None, data_category: str | None = None, key: bool = False, summarize_by: str | None = None, lineage_tag: str | None = None, source_lineage_tag: str | None = None)
Adds a data column to a table within a semantic model.
- Parameters:
table_name (str) – Name of the table in which the column will be created.
column_name (str) – Name of the column.
source_column (str) – The source column for the column.
data_type (str) – The data type of the column.
format_string (str, default=None) – Format string of the column.
hidden (bool, default=False) – Whether the column will be hidden or visible.
description (str, default=None) – A description of the column.
display_folder (str, default=None) – The display folder in which the column will reside.
data_category (str, default=None) – The data category of the column.
key (bool, default=False) – Marks the column as the primary key of the table.
summarize_by (str, default=None) – Sets the value for the Summarize By property of the column. Defaults to None resolves to ‘Default’.
lineage_tag (str, default=None) – A tag that represents the lineage of the object.
source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.
- Returns:
The column object which was created.
- Return type:
TOM.Object
- add_direct_lake_tables(tables: dict, source: str | UUID | None = None, source_type: str | None = None, source_workspace: str | UUID | None = None, use_sql_endpoint: bool = False)
Adds table(s) (in Direct Lake mode) to the semantic model. The semantic model must only use Direct Lake mode and the sources must be viable for Direct Lake.
If the tables source from the same single source which already exists in the model, set source, source_type and source_workspace to None (or do not specify them at all).
- Parameters:
tables (dict) –
The table or tables to be added to the model. Can be a single table name, a dictionary with table details, or a list of table names or dictionaries.
- Example 1 (single table):
- tables = {
“Geography”: “dbo.DimGeography”
}
- Example 2 (single table, no schema):
- tables = {
“Geography”: “DimGeography”
}
- Example 3 (multiple tables):
- tables = {
“Geography”: “dbo.DimGeography”, “Sales”: “dbo.FactSales”, “Customer”: “dbo.DimCustomer”,
}
source (str | uuid.UUID, default=None) – The source name or ID. This is the name or ID of the Lakehouse or Warehouse.
source_type (str, default=None) – The source type (i.e. “Lakehouse” or “Warehouse”).
source_workspace (str | uuid.UUID, default=None) – The workspace name or ID of the source. This is the workspace in which the Lakehouse or Warehouse exists.
use_sql_endpoint (bool, default=False) – If True, uses the SQL endpoint of the artifact. If not, uses Direct Lake over OneLake.
- add_entity_partition(table_name: str, entity_name: str, expression: str | None = None, description: str | None = None, schema_name: str = None)
Adds an entity partition to a table within a semantic model.
- Parameters:
table_name (str) – Name of the table.
entity_name (str) – Name of the lakehouse/warehouse table.
expression (str, default=None) – The name of the expression used by the partition. Defaults to None which resolves to the ‘DatabaseQuery’ expression.
description (str, default=None) – A description for the partition.
schema_name (str, default=None) – The schema name.
- Returns:
The partition which was created.
- Return type:
TOM.Object
- add_expression(name: str, expression: str, description: str | None = None, lineage_tag: str | None = None, source_lineage_tag: str | None = None)
Adds an expression to a semantic model.
- Parameters:
name (str) – Name of the expression.
expression (str) – The M expression of the expression.
description (str, default=None) – A description of the expression.
lineage_tag (str, default=None) – A tag that represents the lineage of the object.
source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.
- Returns:
The expression which was created.
- Return type:
TOM.Object
- add_field_parameter(table_name: str, objects: List[str], object_names: List[str] = None, hierarchy_names: List[str] = None)
Adds a field parameter to the semantic model.
- Parameters:
table_name (str) – Name of the table.
objects (List[str]) – The columns/measures to be included in the field parameter. Columns must be specified as such : ‘Table Name’[Column Name]. Measures may be formatted as ‘[Measure Name]’ or ‘Measure Name’.
object_names (List[str], default=None) – The corresponding visible name for the measures/columns in the objects list. Defaults to None which shows the measure/column name.
hierarchy_names (List[str], default=None) –
- The corresponding hierarchy name for the measures/columns in the objects list if they are to be added to a hierarchy.
Defaults to None which adds all fields to the same level (i.e. no hierarchy).
For details see here.
- Returns:
The table which was created.
- Return type:
TOM.Object
- add_hierarchy(table_name: str, hierarchy_name: str, columns: List[str], levels: List[str] | None = None, hierarchy_description: str | None = None, hierarchy_hidden: bool = False, lineage_tag: str | None = None, source_lineage_tag: str | None = None)
Adds a hierarchy to a table within a semantic model.
- Parameters:
table_name (str) – Name of the table.
hierarchy_name (str) – Name of the hierarchy.
columns (List[str]) – Names of the columns to use within the hierarchy.
levels (List[str], default=None) – Names of the levels to use within the hierarhcy (instead of the column names).
hierarchy_description (str, default=None) – A description of the hierarchy.
hierarchy_hidden (bool, default=False) – Whether the hierarchy is visible or hidden.
lineage_tag (str, default=None) – A tag that represents the lineage of the object.
source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.
- Returns:
The hierarchy which was created.
- Return type:
TOM.Object
- add_incremental_refresh_policy(table_name: str, column_name: str, start_date: str, end_date: str, incremental_granularity: str, incremental_periods: int, rolling_window_granularity: str, rolling_window_periods: int, only_refresh_complete_days: bool = False, detect_data_changes_column: str | None = None)
Adds an incremental refresh policy for a table within a semantic model.
- Parameters:
table_name (str) – Name of the table.
column_name (str) – The DateTime column to be used for the RangeStart and RangeEnd parameters.
start_date (str) – The date to be used for the RangeStart parameter.
end_date (str) – The date to be used for the RangeEnd parameter.
incremental_granularity (str) – Granularity of the (most recent) incremental refresh range.
incremental_periods (int) – Number of periods for the incremental refresh range.
rolling_window_granularity (str) – Target granularity of the rolling window for the whole semantic model.
rolling_window_periods (int) – Number of periods for the rolling window for the whole semantic model.
only_refresh_complete_days (bool, default=False) – Lag or leading periods from Now() to the rolling window head.
detect_data_changes_column (str, default=None) – The column to use for detecting data changes. Defaults to None which resolves to not detecting data changes.
- add_m_partition(table_name: str, partition_name: str, expression: str, mode: str | None = None, description: str | None = None)
Adds an M-partition to a table within a semantic model.
- Parameters:
table_name (str) – Name of the table.
partition_name (str) – Name of the partition.
expression (str) – The M expression encapsulating the logic for the partition.
mode (str, default=None) – The query mode for the partition. Defaults to None which resolves to ‘Import’. Valid mode values
description (str, default=None) – A description for the partition.
- Returns:
The partition which was created.
- Return type:
TOM.Object
- add_measure(table_name: str, measure_name: str, expression: str, format_string: str | None = None, hidden: bool = False, description: str | None = None, display_folder: str | None = None, format_string_expression: str | None = None, data_category: str | None = None, lineage_tag: str | None = None, source_lineage_tag: str | None = None, detail_rows_expression: str | None = None)
Adds a measure to the semantic model.
- Parameters:
table_name (str) – Name of the table in which the measure will be created.
measure_name (str) – Name of the measure.
expression (str) – DAX expression of the measure.
format_string (str, default=None) – Format string of the measure.
hidden (bool, default=False) – Whether the measure will be hidden or visible.
description (str, default=None) – A description of the measure.
display_folder (str, default=None) – The display folder in which the measure will reside.
format_string_expression (str, default=None) – The format string expression.
data_category (str, default=None) – Specifies the type of data contained in the measure so that you can add custom behaviors based on measure type.
lineage_tag (str, default=None) – A tag that represents the lineage of the object.
source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.
detail_rows_expression (str, default=None) – The detail rows expression.
- add_perspective(perspective_name: str)
Adds a perspective to a semantic model.
- Parameters:
perspective_name (str) – Name of the perspective.
- Returns:
The perspective which was created.
- Return type:
TOM.Object
- add_relationship(from_table: str, from_column: str, to_table: str, to_column: str, from_cardinality: str, to_cardinality: str, cross_filtering_behavior: str | None = None, is_active: bool = True, security_filtering_behavior: str | None = None, rely_on_referential_integrity: bool = False)
Adds a relationship to a semantic model.
- Parameters:
from_table (str) – Name of the table on the ‘from’ side of the relationship.
from_column (str) – Name of the column on the ‘from’ side of the relationship.
to_table (str) – Name of the table on the ‘to’ side of the relationship.
to_column (str) – Name of the column on the ‘to’ side of the relationship.
from_cardinality (str) – The cardinality of the ‘from’ side of the relationship. Options: [‘Many’, ‘One’, ‘None’].
to_cardinality (str) – The cardinality of the ‘to’ side of the relationship. Options: [‘Many’, ‘One’, ‘None’].
cross_filtering_behavior (str, default=None) – Setting for the cross filtering behavior of the relationship. Options: (‘Automatic’, ‘OneDirection’, ‘BothDirections’). Defaults to None which resolves to ‘Automatic’.
is_active (bool, default=True) – Setting for whether the relationship is active or not.
security_filtering_behavior (str, default=None) – Setting for the security filtering behavior of the relationship. Options: (‘None’, ‘OneDirection’, ‘BothDirections’). Defaults to None which resolves to ‘OneDirection’.
rely_on_referential_integrity (bool, default=False) – Setting for the rely on referential integrity of the relationship.
- Returns:
The relationship which was created.
- Return type:
TOM.Object
- add_role(role_name: str, model_permission: str | None = None, description: str | None = None)
Adds a role to a semantic model.
- add_role_member(role_name: str, member: str | List[str], role_member_type: str | None = 'User')
Adds an external model role member (AzureAD) to a role.
- Parameters:
- add_table(name: str, description: str | None = None, data_category: str | None = None, hidden: bool = False, lineage_tag: str | None = None, source_lineage_tag: str | None = None)
Adds a table to the semantic model.
- Parameters:
name (str) – Name of the table.
description (str, default=None) – A description of the table.
data_catgegory (str, default=None) – The data category for the table.
hidden (bool, default=False) – Whether the table is hidden or visible.
lineage_tag (str, default=None) – A tag that represents the lineage of the object.
source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.
- Returns:
The table which was created.
- Return type:
TOM.Object
- add_time_intelligence(measure_name: str, date_table: str, time_intel: str | List[str])
Adds time intelligence measures
- add_to_perspective(object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy, perspective_name: str, include_all: bool = True)
Adds an object to a perspective.
- Parameters:
- add_translation(language: str)
Adds a translation language (culture) to a semantic model.
- Parameters:
language (str) – The language code (i.e. ‘it-IT’ for Italian).
- Returns:
The translation which was created.
- Return type:
TOM.Object
- all_calculated_columns()
Outputs a list of all calculated columns within all tables in the semantic model.
- Returns:
All calculated columns within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.Column]
- all_calculated_tables()
Outputs a list of all calculated tables in the semantic model.
- Returns:
All calculated tables within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.Table]
- all_calculation_groups()
Outputs a list of all calculation groups in the semantic model.
- Returns:
All calculation groups within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.Table]
- all_calculation_items()
Outputs a list of all calculation items in the semantic model.
- Returns:
All calculation items within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.CalculationItem]
- all_columns()
Outputs a list of all columns within all tables in the semantic model.
- Returns:
All columns within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.Column]
- all_date_tables()
Outputs the tables which are marked as date tables within a semantic model.
- Returns:
All tables marked as date tables within a semantic model.
- Return type:
Microsoft.AnalysisServices.Tabular.TableCollection
- all_functions()
Outputs a list of all user-defined functions in the semantic model.
- Returns:
All user-defined functions within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.Function]
- all_hierarchies()
Outputs a list of all hierarchies in the semantic model.
- Returns:
All hierarchies within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.Hierarchy]
- all_hybrid_tables()
Outputs the hybrid tables within a semantic model.
- Returns:
All hybrid tables within a semantic model.
- Return type:
Microsoft.AnalysisServices.Tabular.TableCollection
- all_levels()
Outputs a list of all levels in the semantic model.
- Returns:
All levels within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.Level]
- all_measures()
Outputs a list of all measures in the semantic model.
- Returns:
All measures within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.Measure]
- all_partitions()
Outputs a list of all partitions in the semantic model.
- Returns:
All partitions within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.Partition]
- all_rls()
Outputs a list of all row level security expressions in the semantic model.
- Returns:
All row level security expressions within the semantic model.
- Return type:
Iterator[Microsoft.AnalysisServices.Tabular.TablePermission]
- apply_refresh_policy(table_name: str, effective_date: datetime | None = None, refresh: bool = True, max_parallelism: int | None = 0)
Applies the incremental refresh policy for a table within a semantic model.
- Parameters:
table_name (str) – Name of the table.
effective_date (DateTime, default=None) – The effective date that is used when calculating the partitioning scheme.
refresh (bool, default=True) – An indication if partitions of the table should be refreshed or not; the default behavior is to do the refresh.
max_parallelism (int, default=0) – The degree of parallelism during the refresh execution.
- cardinality(column: TOM.Column)
Obtains the cardinality of a column within a semantic model.
- Parameters:
column (TOM Object) – The column object within the semantic model.
- Returns:
Cardinality of the TOM column.
- Return type:
- clear_annotations(object)
Removes all annotations on an object within the semantic model.
- Parameters:
object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.
- clear_extended_properties(object)
Removes all extended properties on an object within the semantic model.
- Parameters:
object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.
- clear_linguistic_schema(culture: str)
Clears the linguistic schema for a given culture.
- Parameters:
culture (str) – The culture name.
- close()
- convert_direct_lake_to_import(table_name: str, entity_name: str | None = None, schema: str | None = None, source: str | UUID | None = None, source_type: str = 'Lakehouse', source_workspace: str | UUID | None = None)
Converts a Direct Lake table’s partition to an import-mode partition.
The entity_name and schema parameters default to using the existing values in the Direct Lake partition. The source, source_type, and source_workspace parameters do not default to existing values. This is because it may not always be possible to reconcile the source and its workspace.
- Parameters:
table_name (str) – The table name.
entity_name (str, default=None) – The entity name of the Direct Lake partition (the table name in the source).
schema (str, default=None) – The schema of the source table. Defaults to None which resolves to the existing schema.
source (str | uuid.UUID, default=None) – The source name or ID. This is the name or ID of the Lakehouse or Warehouse.
source_type (str, default="Lakehouse") – The source type (i.e. “Lakehouse” or “Warehouse”).
source_workspace (str | uuid.UUID, default=None) – The workspace name or ID of the source. This is the workspace in which the Lakehouse or Warehouse exists. Defaults to None which resolves to the workspace of the attached lakehouse or if no lakehouse attached, resolves to the workspace of the notebook.
- copy_object(object, target_dataset: str | UUID, target_workspace: str | UUID | None = None, readonly: bool = False)
Copies a semantic model object from the current semantic model to the target semantic model.
- Parameters:
object (TOM Object) – The TOM object to be copied to the target semantic model. For example: tom.model.Tables[‘Sales’].
target_dataset (str | uuid.UUID) – Name or ID of the target semantic model.
target_workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID. Defaults to None which resolves to the workspace of the attached lakehouse or if no lakehouse attached, resolves to the workspace of the notebook.
readonly (bool, default=False) – Whether the connection is read-only or read/write. Setting this to False enables read/write which saves the changes made back to the server.
- data_size(column: TOM.Column)
Obtains the data size of a column within a semantic model.
- Parameters:
column (TOM Object) – The column object within the semantic model.
- Returns:
Data size of the TOM column.
- Return type:
- delete_synonym(culture: str, object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy, synonym_name: str)
Deletes a synonym for a table/column/measure/hierarchy in the linguistic schema of the semantic model. This function is currently in preview.
- depends_on(object, dependencies: DataFrame)
Obtains the objects on which the specified object depends.
- Parameters:
object (TOM Object) – The TOM object within the semantic model.
dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.
- Returns:
Objects on which the specified object depends.
- Return type:
Microsoft.AnalysisServices.Tabular.TableCollection, Microsoft.AnalysisServices.Tabular.ColumnCollection, Microsoft.AnalysisServices.Tabular.MeasureCollection
- dictionary_size(column: TOM.Column)
Obtains the dictionary size of a column within a semantic model.
- Parameters:
column (TOM Object) – The column object within the semantic model.
- Returns:
Dictionary size of the TOM column.
- Return type:
- format_dax(object: TOM.Measure | TOM.CalcultedColumn | TOM.CalculationItem | TOM.CalculatedTable | TOM.TablePermission | None = None)
Formats the DAX expressions of measures, calculated columns, calculation items, calculated tables and row level security expressions in the semantic model.
This function uses the DAX Formatter API.
- Parameters:
object (TOM Object, default=None) – The TOM object to format. If None, formats all measures, calculated columns, calculation items, calculated tables and row level security expressions in the semantic model. If a specific object is provided, only that object will be formatted.
- fully_qualified_measures(object: TOM.Measure, dependencies: DataFrame)
Obtains all fully qualified measure references for a given object.
- Parameters:
object (TOM Object) – The TOM object within the semantic model.
dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.
- Returns:
All fully qualified measure references for a given object.
- Return type:
Microsoft.AnalysisServices.Tabular.MeasureCollection
- generate_measure_descriptions(measure_name: str | List[str] | None = None, max_batch_size: int | None = 1) DataFrame
Auto-generates descriptions for measures using an LLM. This function requires a paid F-sku (Fabric) of F64 or higher. Setting the ‘readonly’ parameter in connect_semantic_model to True will allow you to see the auto-generated descriptions in a dataframe. Setting the ‘readonly’ parameter to False will update the descriptions for the measures within the ‘measure_name’ parameter.
- Parameters:
- Returns:
A pandas dataframe showing the updated measure(s) and their new description(s).
- Return type:
- get_annotation_value(object, name: str)
Obtains the annotation value for a given annotation on an object within the semantic model.
- get_annotations(object) Microsoft.AnalysisServices.Tabular.Annotation
Shows all annotations for a given object within a semantic model.
- Parameters:
object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.
- Returns:
TOM objects of all the annotations on a particular object within the semantic model.
- Return type:
Microsoft.AnalysisServices.Tabular.Annotation
- get_bim() dict
Retrieves the .bim file for the semantic model.
- Returns:
The .bim file.
- Return type:
- get_direct_lake_sources() List[dict]
Retrieves a list of the Direct Lake sources used in a semantic model, including their type, workspace, and whether they use a SQL endpoint.
- Returns:
A list of dictionaries, each containing details about a Direct Lake source used in the semantic model. Example: [
- {
“itemId”: “123e4567-e89b-12d3-a456-426614174000”, “itemName”: “My Lakehouse”, “itemType”: “Lakehouse”, “workspaceId”: “123e4567-e89b-12d3-a456-426614174001”, “workspaceName”: “Workspace A”, “usesSqlEndpoint”: False, “expressionName”: “DL Lake 1”,
}, {
”itemId”: “123e4567-e89b-12d3-a456-426614174002”, “itemName”: “My Data Source”, “itemType”: “Warehouse”, “workspaceId”: “123e4567-e89b-12d3-a456-426614174001”, “workspaceName”: “Workspace A”, “usesSqlEndpoint”: False, “expressionName”: “DL Warehouse 1”,
}
]
- Return type:
- get_extended_properties(object) Microsoft.AnalysisServices.Tabular.ExtendedProperty
Retrieves all extended properties on an object within the semantic model.
- Parameters:
object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.
- Returns:
TOM Objects of all the extended properties.
- Return type:
Microsoft.AnalysisServices.Tabular.ExtendedPropertiesCollection
- get_extended_property_value(object, name: str)
Retrieves the value of an extended property for an object within the semantic model.
- get_linguistic_schema(culture: str) dict
Obtains the linguistic schema for a given culture. :param culture: The culture name. :type culture: str
- Returns:
The linguistic schema for the given culture.
- Return type:
- get_mini_model_properties() dict
Retrieves the properties of the mini model (if the semantic model is a mini model).
- Returns:
A dictionary containing the properties of the mini model.
- Return type:
- has_aggs()
Identifies if a semantic model has any aggregations.
- Returns:
Indicates if the semantic model has any aggregations.
- Return type:
- has_date_table()
Identifies if a semantic model has a table marked as a date table.
- Returns:
Indicates if the semantic model has a table marked as a date table.
- Return type:
- has_hybrid_table()
Identifies if a semantic model has a hybrid table.
- Returns:
Indicates if the semantic model has a hybrid table.
- Return type:
- has_incremental_refresh_policy(object)
Identifies whether a table has an incremental refresh policy.
- Parameters:
object (TOM Object) – The TOM object within the semantic model. Accepts either a table or the model object.
- Returns:
An indicator whether a table has an incremental refresh policy.
- Return type:
- hide_key_columns()
Hides all columns in the semantic model that are used in a relationship and have an Int64 data type. This reduces clutter in the field list while preserving relationship functionality.
- in_perspective(object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy, perspective_name: str)
Indicates whether an object is contained within a given perspective.
- is_agg_table(table_name: str)
Identifies if a table has aggregations.
- is_auto_date_table(table_name: str)
Identifies if a table is an auto date/time table.
- is_calculated_column(table_name: str, column_name: str)
Identifies if a column is a calculated column.
- is_date_table(table_name: str)
Identifies if a table is marked as a date tables.
- is_direct_lake()
Identifies if a semantic model is in Direct Lake mode.
- Returns:
Indicates if the semantic model is in Direct Lake mode.
- Return type:
- is_direct_lake_using_view()
Identifies whether a semantic model is in Direct lake mode and uses views from the lakehouse.
- Returns:
An indicator whether a semantic model is in Direct lake mode and uses views from the lakehouse.
- Return type:
- is_field_parameter(table_name: str)
Identifies if a table is a field parameter.
- is_hybrid_table(table_name: str)
Identifies if a table is a hybrid table.
- is_mini_model() bool
Identifies whether the semantic model is a mini model (and is derived from a master model).
- Returns:
An indication whether the semantic model is a mini model.
- Return type:
- mark_as_date_table(table_name: str, column_name: str, validate: bool = False)
Marks a table as a date table.
- mark_primary_keys()
Identifies all primary key columns in the semantic model (columns used on the “one” side of a relationship) and sets the IsKey property to True for those columns.
- records_per_segment(object: TOM.Partition)
Obtains the records per segment of a partition within a semantic model.
- Parameters:
object (TOM Object) – The partition object within the semantic model.
- Returns:
Number of records per segment within the partition.
- Return type:
- referenced_by(object, dependencies: DataFrame)
Obtains the objects which reference the specified object.
- Parameters:
object (TOM Object) – The TOM object within the semantic model.
dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.
- Returns:
Objects which reference the specified object.
- Return type:
Microsoft.AnalysisServices.Tabular.TableCollection, Microsoft.AnalysisServices.Tabular.ColumnCollection, Microsoft.AnalysisServices.Tabular.MeasureCollection
- remove_alternate_of(table_name: str, column_name: str)
Removes the alternate of property on a column.
- remove_annotation(object, name: str)
Removes an annotation on an object within the semantic model.
- Parameters:
object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.
name (str) – Name of the annotation.
- remove_changed_property(object, property: str)
Removes a ChangedProperty property to a semantic model object. Only adds the property if it does not already exist for the object.
- Parameters:
object (TOM Object) – The TOM object within the semantic model.
property (str) – The property to set (i.e. ‘Name’, ‘DataType’).
- remove_extended_property(object, name: str)
Removes an extended property on an object within the semantic model.
- Parameters:
object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.
name (str) – Name of the annotation.
- remove_from_perspective(object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy, perspective_name: str)
Removes an object from a perspective.
- Parameters:
object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.
perspective_name (str) – Name of the perspective.
- remove_object(object)
Removes an object from a semantic model.
- Parameters:
object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.
- remove_role_member(role_name: str, member: str | List[str])
Removes an external model role member (AzureAD) from a role.
- remove_sort_by_column(table_name: str, column_name: str)
Removes the sort by column for a column in a semantic model.
- remove_translation(object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy | TOM.Level, language: str, property: str = 'Name')
Removes an object’s translation value.
- remove_vertipaq_annotations()
Removes the annotations set using the set_vertipaq_annotations function.
- row_count(object: TOM.Partition | TOM.Table)
Obtains the row count of a table or partition within a semantic model.
- Parameters:
object (TOM Object) – The table/partition object within the semantic model.
- Returns:
Number of rows within the TOM object.
- Return type:
- set_aggregations(table_name: str, agg_table_name: str)
Sets the aggregations (alternate of) for all the columns in an aggregation table based on a base table.
- set_alternate_of(table_name: str, column_name: str, summarization_type: str, base_table: str, base_column: str | None = None)
Sets the alternate of property on a column.
- Parameters:
- set_annotation(object, name: str, value: str)
Sets an annotation on an object within the semantic model.
- set_compatibility_level(compatibility_level: int)
Sets compatibility level of the semantic model
- Parameters:
compatibility_level (int) – The compatibility level to set the for the semantic model.
- set_data_coverage_definition(table_name: str, partition_name: str, expression: str)
Sets the data coverage definition for a partition.
- set_data_type(table_name: str, column_name: str, value: Literal['String', 'Int64', 'Decimal', 'Double', 'DateTime', 'Boolean', 'Binary'])
Sets the data type for a column.
- Parameters:
table_name (str) – Name of the table.
column_name (str) – Name of the column.
value (Literal["String", "Int64", "Decimal", "Double", "DateTime", "Boolean", "Binary"]) – The data type. Data type valid values
- set_direct_lake_behavior(direct_lake_behavior: str)
Sets the Direct Lake Behavior property for a semantic model.
- Parameters:
direct_lake_behavior (str) – The DirectLakeBehavior property value. DirectLakeBehavior valid values
- set_encoding_hint(table_name: str, column_name: str, value: Literal['Default', 'Hash', 'Value'])
Sets the encoding hint for a column.
- Parameters:
table_name (str) – Name of the table.
column_name (str) – Name of the column.
value (Literal["Default", "Hash", "Value"]) – Encoding hint value. Encoding hint valid values
- set_extended_property(object, extended_property_type: str, name: str, value: str)
Sets an extended property on an object within the semantic model.
- Parameters:
object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.
extended_property_type (str) – The extended property type. Extended property valid values
name (str) – Name of the extended property.
value (str) – Value of the extended property.
- set_is_available_in_mdx(table_name: str, column_name: str, value: bool = False)
Sets the IsAvailableInMDX property on a column.
- set_kpi(measure_name: str, target: int | float | str, lower_bound: float, upper_bound: float, lower_mid_bound: float | None = None, upper_mid_bound: float | None = None, status_type: str | None = None, status_graphic: str | None = None)
Sets the properties to add/update a KPI for a measure.
- Parameters:
measure_name (str) – Name of the measure.
target (str, int, float) – The target for the KPI. This can either be a number or the name of a different measure in the semantic model.
lower_bound (float) – The lower bound for the KPI.
upper_bound (float) – The upper bound for the KPI.
lower_mid_bound (float, default=None) – The lower-mid bound for the KPI. Set this if status_type is ‘Centered’ or ‘CenteredReversed’.
upper_mid_bound (float, default=None) – The upper-mid bound for the KPI. Set this if status_type is ‘Centered’ or ‘CenteredReversed’.
status_type (str, default=None) – The status type of the KPI. Options: ‘Linear’, ‘LinearReversed’, ‘Centered’, ‘CenteredReversed’. Defaults to None which resolvs to ‘Linear’.
status_graphic (str, default=None) – The status graphic for the KPI. Defaults to ‘Three Circles Colored’.
- set_ols(role_name: str, table_name: str, column_name: str | None = None, permission: Literal['Default', 'None', 'Read'] = 'Default')
Sets the object level security permissions for a column within a role.
- Parameters:
role_name (str) – Name of the role.
table_name (str) – Name of the table.
column_name (str, default=None) – Name of the column. Defaults to None which sets object level security for the entire table.
permission (Literal["Default", "None", "Read"], default="Default") – The object level security permission for the column. Permission valid values
- set_rls(role_name: str, table_name: str, filter_expression: str)
Sets the row level security permissions for a table within a role.
- set_sort_by_column(table_name: str, column_name: str, sort_by_column: str)
Sets the sort by column for a column in a semantic model.
- set_summarize_by(table_name: str, column_name: str, value: str | None = None)
Sets the SummarizeBy property on a column.
- Parameters:
table_name (str) – Name of the table.
column_name (str) – Name of the column.
value (bool, default=None) – The SummarizeBy property value. Defaults to none which resolves to ‘Default’. Aggregate valid values
- set_synonym(culture: str, object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy, synonym_name: str, weight: Decimal | None = None)
Sets a synonym for a table/column/measure/hierarchy in the linguistic schema of the semantic model. This function is currently in preview.
- Parameters:
culture (str) – The culture name for which the synonym is being set. Example: ‘en-US’.
object (TOM Object) – The TOM object for which the synonym is being set. This can be a table, column, measure, or hierarchy.
synonym_name (str) – The name of the synonym to be set.
weight (Decimal, default=None) – The weight of the synonym. If None, the default weight is used. The weight must be a Decimal value between 0 and 1.
- set_translation(object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy | TOM.Level, language: str, property: str, value: str)
Sets a translation value for an object’s property.
- set_user_defined_function(name: str, expression: str)
Sets the definition of a user-defined function within the semantic model. This function requires that the compatibility level is at least 1702.
- set_value_filter_behavior(value_filter_behavior: Literal['Automatic', 'Independent', 'Coalesced'] = 'Automatic')
Sets the Value Filter Behavior property for the semantic model.
- Parameters:
value_filter_behavior (Literal["Automatic", "Independent", "Coalesced"] , default="Automatic") – Determines value filter behavior for SummarizeColumns.
- set_vertipaq_annotations()
Saves Vertipaq Analyzer statistics as annotations on objects in the semantic model.
- show_incremental_refresh_policy(table_name: str)
Prints the incremental refresh policy for a table.
- Parameters:
table_name (str) – Name of the table.
- sync_descriptions(overwrite: bool = False)
Sets table/column descriptions in the semantic model based on the descriptions set on the tables/columns in the source Lakehouse tables. This function is only supported for Direct Lake models using lakehouse source(s).
It is recommended to run this function in a pure Python notebook.
- Parameters:
overwrite (bool, default=False) – If True, overwrites the existing descriptions in the semantic model. If False, skips the tables/columns which already have descriptions.
- total_size(object: TOM.Table | TOM.Column)
Obtains the data size of a table/column within a semantic model.
- Parameters:
object (TOM Object) – The table/column object within the semantic model.
- Returns:
Total size of the TOM table/column.
- Return type:
- unqualified_columns(object, dependencies: DataFrame)
Obtains all unqualified column references for a given object.
- Parameters:
object (TOM Object) – The TOM object within the semantic model.
dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.
- Returns:
All unqualified column references for a given object.
- Return type:
Microsoft.AnalysisServices.Tabular.ColumnCollection
- update_calculation_item(table_name: str, calculation_item_name: str, expression: str | None = None, ordinal: int | None = None, description: str | None = None, format_string_expression: str | None = None)
Updates a calculation item within a semantic model.
- Parameters:
table_name (str) – Name of the calculation group (table).
calculation_item_name (str) – Name of the calculation item.
expression (str, default=None) – The DAX expression of the calculation item. Defaults to None which keeps the existing setting.
ordinal (int, default=None) – The ordinal of the calculation item. Defaults to None which keeps the existing setting.
description (str, default=None) – The description of the role. Defaults to None which keeps the existing setting.
format_string_expression (str, default=None) – The format string expression for the calculation item. Defaults to None which keeps the existing setting.
- update_column(table_name: str, column_name: str, source_column: str | None = None, data_type: str | None = None, expression: str | None = None, format_string: str | None = None, hidden: bool | None = None, description: str | None = None, display_folder: str | None = None, data_category: str | None = None, key: bool | None = None, summarize_by: str | None = None, is_nullable: bool | None = None, is_available_in_mdx: bool | None = None)
Updates a column within a semantic model.
- Parameters:
table_name (str) – Name of the table in which the column exists.
column_name (str) – Name of the column.
source_column (str, default=None) – The source column for the column (for data columns only). Defaults to None which keeps the existing setting.
data_type (str, default=None) – The data type of the column. Defaults to None which keeps the existing setting.
expression (str, default=None) – The DAX expression of the column (for calculated columns only). Defaults to None which keeps the existing setting.
format_string (str, default=None) – Format string of the column. Defaults to None which keeps the existing setting.
hidden (bool, default=None) – Whether the column will be hidden or visible. Defaults to None which keeps the existing setting.
description (str, default=None) – A description of the column. Defaults to None which keeps the existing setting.
display_folder (str, default=None) – The display folder in which the column will reside. Defaults to None which keeps the existing setting.
data_category (str, default=None) – The data category of the column. Defaults to None which keeps the existing setting.
key (bool, default=False) – Marks the column as the primary key of the table. Defaults to None which keeps the existing setting.
summarize_by (str, default=None) – Sets the value for the Summarize By property of the column. Defaults to None which keeps the existing setting.
is_nullable (bool, default=None) – If False, the column cannot contain nulls. Even if True, it may still not allow nulls if it’s a key column.
is_available_in_mdx (bool, default=None) – A boolean value that indicates whether the column can be excluded from usage in MDX query tools. False if the column can be excluded from usage in MDX query tools; otherwise true.
- update_incremental_refresh_policy(table_name: str, incremental_granularity: str, incremental_periods: int, rolling_window_granularity: str, rolling_window_periods: int, only_refresh_complete_days: bool = False, detect_data_changes_column: str | None = None)
Updates the incremental refresh policy for a table within a semantic model.
- Parameters:
table_name (str) – Name of the table.
incremental_granularity (str) – Granularity of the (most recent) incremental refresh range.
incremental_periods (int) – Number of periods for the incremental refresh range.
rolling_window_granularity (str) – Target granularity of the rolling window for the whole semantic model.
rolling_window_periods (int) – Number of periods for the rolling window for the whole semantic model.
only_refresh_complete_days (bool, default=False) – Lag or leading periods from Now() to the rolling window head.
detect_data_changes_column (str, default=None) – The column to use for detecting data changes. Defaults to None which resolves to not detecting data changes.
- update_lineage_tags()
Adds lineage and source lineage tags for relevant semantic model objects if they do not exist. Also updates schema name for Direct Lake (entity) partitions.
- update_m_partition(table_name: str, partition_name: str, expression: str | None = None, mode: str | None = None, description: str | None = None)
Updates an M partition for a table within a semantic model.
- Parameters:
table_name (str) – Name of the table.
partition_name (str) – Name of the partition.
expression (str, default=None) – The M expression containing the logic for the partition. Defaults to None which keeps the existing setting.
mode (str, default=None) – The query mode of the partition. Defaults to None which keeps the existing setting.
description (str, default=None) – The description of the partition. Defaults to None which keeps the existing setting.
- update_measure(measure_name: str, expression: str | None = None, format_string: str | None = None, hidden: bool | None = None, description: str | None = None, display_folder: str | None = None, format_string_expression: str | None = None)
Updates a measure within a semantic model.
- Parameters:
measure_name (str) – Name of the measure.
expression (str, default=None) – DAX expression of the measure. Defaults to None which keeps the existing setting.
format_string (str, default=None) – Format string of the measure. Defaults to None which keeps the existing setting.
hidden (bool, default=None) – Whether the measure will be hidden or visible. Defaults to None which keeps the existing setting.
description (str, default=None) – A description of the measure. Defaults to None which keeps the existing setting.
display_folder (str, default=None) – The display folder in which the measure will reside. Defaults to None which keeps the existing setting.
format_string_expression (str, default=None) – The format string expression for the calculation item. Defaults to None which keeps the existing setting.
- update_role(role_name: str, model_permission: str | None = None, description: str | None = None)
Updates a role within a semantic model.
- used_in_calc_item(object: TOM.Table | TOM.Column | TOM.Measure, dependencies: DataFrame)
Identifies the … which reference a given object.
- Parameters:
object (TOM Object) – An object (i.e. table/column) within a semantic model.
dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.
- Return type:
Microsoft.AnalysisServices.Tabular.TableCollection, Microsoft.AnalysisServices.Tabular.ColumnCollection, Microsoft.AnalysisServices.Tabular.MeasureCollection
- used_in_data_coverage_definition(object: TOM.Table | TOM.Column | TOM.Measure, dependencies: DataFrame)
Identifies the … which reference a given object.
- Parameters:
object (TOM Object) – An object (i.e. table/column) within a semantic model.
dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.
- Return type:
Microsoft.AnalysisServices.Tabular.TableCollection, Microsoft.AnalysisServices.Tabular.ColumnCollection, Microsoft.AnalysisServices.Tabular.MeasureCollection
- used_in_hierarchies(column: TOM.Column)
Shows all hierarchies in which a column is used.
- Parameters:
object (TOM Object) – An column object within a semantic model.
- Returns:
All hierarchies in which the column is used.
- Return type:
Microsoft.AnalysisServices.Tabular.HierarchyCollection
- used_in_levels(column: TOM.Column)
Shows all levels in which a column is used.
- Parameters:
object (TOM Object) – An column object within a semantic model.
- Returns:
All levels in which the column is used.
- Return type:
Microsoft.AnalysisServices.Tabular.LevelCollection
- used_in_relationships(object: TOM.Table | TOM.Column)
Shows all relationships in which a table/column is used.
- Parameters:
object (TOM Object) – An object (i.e. table/column) within a semantic model.
- Returns:
All relationships in which the table/column is used.
- Return type:
Microsoft.AnalysisServices.Tabular.RelationshipCollection
- used_in_rls(object: TOM.Table | TOM.Column | TOM.Measure, dependencies: DataFrame)
Identifies the row level security filter expressions which reference a given object.
- Parameters:
object (TOM Object) – An object (i.e. table/column) within a semantic model.
dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.
- Return type:
Microsoft.AnalysisServices.Tabular.TableCollection, Microsoft.AnalysisServices.Tabular.ColumnCollection, Microsoft.AnalysisServices.Tabular.MeasureCollection
- used_in_sort_by(column: TOM.Column)
Shows all columns in which a column is used for sorting.
- Parameters:
object (TOM Object) – An column object within a semantic model.
- Returns:
All columns in which the column is used for sorting.
- Return type:
Microsoft.AnalysisServices.Tabular.ColumnCollection
- sempy_labs.tom.connect_semantic_model(dataset: str | UUID, readonly: bool = True, workspace: str | UUID | None = None) Iterator[TOMWrapper]
Connects to the Tabular Object Model (TOM) within a semantic model.
Service Principal Authentication is supported (see here for examples).
- Parameters:
dataset (str | uuid.UUID) – Name or ID of the semantic model.
readonly (bool, default=True) – Whether the connection is read-only or read/write. Setting this to False enables read/write which saves the changes made back to the server.
workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID. Also supports Azure Analysis Services (Service Principal Authentication required). If connecting to Azure Analysis Services, enter the workspace parameter in the following format: ‘asazure://<region>.asazure.windows.net/<server_name>’. Defaults to None which resolves to the workspace of the attached lakehouse or if no lakehouse attached, resolves to the workspace of the notebook.
- Returns:
A connection to the semantic model’s Tabular Object Model.
- Return type: