sempy_labs.directlake package
Module contents
- sempy_labs.directlake.add_table_to_direct_lake_semantic_model(dataset: str | UUID, table_name: str, lakehouse_table_name: str, refresh: bool = True, workspace: str | UUID | None = None, columns: str | List[str] | None = None)
Adds a table and all of its columns to a Direct Lake semantic model, based on a Fabric lakehouse table.
- Parameters:
dataset (str | uuid.UUID) – Name or ID of the semantic model.
table_name (str, List[str]) – Name of the table in the semantic model.
lakehouse_table_name (str) – The name of the Fabric lakehouse table.
refresh (bool, default=True) – Refreshes the table after it is added to the semantic model.
workspace (str | uuid.UUID, default=None) – The name or ID of the Fabric workspace in which the semantic model resides. Defaults to None which resolves to the workspace of the attached lakehouse or if no lakehouse attached, resolves to the workspace of the notebook.
columns (List[str] | str, default=None) – A list of column names to add to the table. If None, all columns from the lakehouse table will be added.
- sempy_labs.directlake.check_fallback_reason(dataset: str | UUID, workspace: str | UUID | None = None) DataFrame
Shows the reason a table in a Direct Lake semantic model would fallback to DirectQuery.
- Parameters:
- Returns:
The tables in the semantic model and their fallback reason.
- Return type:
- sempy_labs.directlake.direct_lake_schema_compare(dataset: str | UUID, workspace: str | UUID | None = None)
Checks that all the tables in a Direct Lake semantic model map to tables in their corresponding lakehouse and that the columns in each table exist.
- sempy_labs.directlake.direct_lake_schema_sync(dataset: str | UUID, workspace: str | UUID | None = None, add_to_model: bool = False, remove_from_model: bool = False) DataFrame
Shows/adds columns which exist in the lakehouse but do not exist in the semantic model (only for tables in the semantic model).
- Parameters:
dataset (str | uuid.UUID) – Name or ID of the semantic model.
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.
add_to_model (bool, default=False) – If set to True, columns which exist in the lakehouse but do not exist in the semantic model are added to the semantic model. No new tables are added.
remove_from_model (bool, default=False) – If set to True, columns which exist in the semantic model but do not exist in the lakehouse are removed from the semantic model. No new tables are removed.
- Returns:
A pandas dataframe showing the status of columns in the semantic model and lakehouse (prior to adding/removing them from the model using this function).
- Return type:
- sempy_labs.directlake.generate_direct_lake_semantic_model(dataset: str, tables: List[str], source: str | UUID, source_type: Literal['Lakehouse', 'Warehouse', 'SQLDatabase', 'MirroredAzureDatabricksCatalog', 'MirroredDatabase'] = 'Lakehouse', source_workspace: str | UUID | None = None, use_sql_endpoint: bool = False, workspace: str | UUID | None = None, refresh: bool = True, inherit_descriptions: bool = True)
Dynamically generates a Direct Lake semantic model based on tables in Fabric.
- Parameters:
dataset (str) – Name of the semantic model to be created.
List or dictionary of tables to include in the semantic model. Table names should be schema-qualified if there are multiple tables with the same name across schemas (e.g. “schema1.tableA”, “schema2.tableA”, “schema1.tableB”).
- Example 1:
tables = [“dbo.sales”, “dbo.geography”]
- Example 2:
- tables = {
“Sales”: “dbo.sales”, “Geography”: “dbo.geography”,
}
source (str | uuid.UUID) – The source item name or ID from which to generate the semantic model. This can be a Lakehouse, Mirrored Azure Databricks Catalog, Warehouse, SQL Database, or Mirrored Database.
source_type (Literal["Lakehouse", "Warehouse", "SQLDatabase", "MirroredAzureDatabricksCatalog", "MirroredDatabase"], default = "Lakehouse") – The type of the source item. Supported values are “Lakehouse”, “Warehouse”, “SQLDatabase”, “MirroredAzureDatabricksCatalog”, “MirroredDatabase”.
source_workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID in which the source item resides. This parameter is required if the source item is not in the same workspace as the semantic model will be created, and is ignored if the source item is in the same workspace. Defaults to None which resolves to the workspace of the attached lakehouse or if no lakehouse attached, resolves to the workspace of the notebook.
use_sql_endpoint (bool, default=False) – If True, the generated expression will use the SQL endpoint. If False, the generated expression will use Direct Lake over OneLake.
workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID in which the semantic model will reside. Defaults to None which resolves to the workspace of the attached lakehouse or if no lakehouse attached, resolves to the workspace of the notebook.
refresh (bool, default=True) – If True, refreshes the newly created semantic model after it is created.
inherit_descriptions (bool, default=True) – If True, sets table/column descriptions based on the comments/descriptions in the source table. Only available for lakehouse sources.
Dynamically generates the M expression used by a Direct Lake model for a given lakehouse/warehouse.
- Parameters:
item (str, default=None) – The item name or ID. Defaults to None which resolves to the lakehouse attached to the notebook.
item_type (str, default="Lakehouse") – The Fabric item name. Valid options: ‘Lakehouse’, ‘Warehouse’, ‘MirroredAzureDatabricksCatalog’, ‘SQLDatabase’, ‘MirroredDatabase’.
workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID used by the item. Defaults to None which resolves to the workspace of the attached lakehouse or if no lakehouse attached, resolves to the workspace of the notebook.
use_sql_endpoint (bool, default=True) – Whether to use the SQL Endpoint for the lakehouse/warehouse. If False, the expression will be generated without using the SQL Endpoint.
- Returns:
Shows the expression which can be used to connect a Direct Lake semantic model to its SQL Endpoint.
- Return type:
- sempy_labs.directlake.get_direct_lake_guardrails() DataFrame
Shows the guardrails for when Direct Lake semantic models will fallback to Direct Query based on Microsoft’s online documentation.
- Returns:
A table showing the Direct Lake guardrails by SKU.
- Return type:
- sempy_labs.directlake.get_direct_lake_sources(dataset: str | UUID, workspace: str | UUID | None = None) 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.
Parameters: dataset : str | uuid.UUID
The name or UUID of the semantic model.
- workspacestr | 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.
Returns: typing.List[dict]
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,
}, {
“itemId”: “123e4567-e89b-12d3-a456-426614174002”, “itemName”: “My Data Source”, “itemType”: “Warehouse”, “workspaceId”: “123e4567-e89b-12d3-a456-426614174001”, “workspaceName”: “Workspace A”, “usesSqlEndpoint”: True,
}
]
- sempy_labs.directlake.get_directlake_guardrails_for_sku(sku_size: str) DataFrame
Shows the guardrails for Direct Lake based on the SKU used by your workspace’s capacity. * Use the result of the ‘get_sku_size’ function as an input for this function’s sku_size parameter.*
- Parameters:
sku_size (str) – Sku size of a workspace/capacity.
- Returns:
A table showing the Direct Lake guardrails for the given SKU.
- Return type:
Dynamically generates the M expression used by a Direct Lake model for a given lakehouse.
- Parameters:
lakehouse (str, default=None) – The Fabric lakehouse used by the Direct Lake semantic model. Defaults to None which resolves to the lakehouse attached to the notebook.
workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID used by the lakehouse. 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:
Shows the expression which can be used to connect a Direct Lake semantic model to its SQL Endpoint.
- Return type:
- sempy_labs.directlake.get_sku_size(workspace: str | UUID | None = None) str
Shows the SKU size for a workspace.
- sempy_labs.directlake.list_direct_lake_model_calc_tables(dataset: str | UUID, workspace: str | UUID | None = None) DataFrame
Shows the calculated tables and their respective DAX expression for a Direct Lake model (which has been migrated from import/DirectQuery).
- Parameters:
- Returns:
A pandas dataframe showing the calculated tables which were migrated to Direct Lake and whose DAX expressions are stored as model annotations.
- Return type:
- sempy_labs.directlake.set_autosync(dataset: str | UUID, workspace: str | UUID | None = None, enable: bool = True)
Enables or disables AutoSync for a Direct Lake semantic model.
- Parameters:
dataset (str | uuid.UUID) – Name or ID of the semantic model.
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.
enable (bool, default=True) – Whether to enable (True) or disable (False) AutoSync.
- sempy_labs.directlake.show_unsupported_direct_lake_objects(dataset: str | UUID, workspace: str | UUID | None = None) Tuple[DataFrame, DataFrame, DataFrame]
Returns a list of a semantic model’s objects which are not supported by Direct Lake based on official documentation.
- Parameters:
- Returns:
3 pandas dataframes showing objects in a semantic model which are not supported by Direct Lake.
- Return type:
- sempy_labs.directlake.update_direct_lake_model_connection(dataset: str | UUID, workspace: str | UUID | None = None, source: str | UUID | None = None, source_type: Literal['Lakehouse', 'Warehouse'] = 'Lakehouse', source_workspace: str | UUID | None = None, use_sql_endpoint: bool = True, tables: str | List[str] | None = None)
Remaps a Direct Lake semantic model’s SQL Endpoint connection to a new lakehouse/warehouse.
- Parameters:
dataset (str | uuid.UUID) – Name or ID of the semantic model.
workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID in which the semantic model 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.
source (str | uuid.UUID, default=None) – The name of the Fabric lakehouse/warehouse used by the Direct Lake semantic model. Defaults to None which resolves to the lakehouse attached to the notebook.
source_type (Literal["Lakehouse", "Warehouse"], default="Lakehouse") – The type of source for the Direct Lake semantic model. Valid options: “Lakehouse”, “Warehouse”.
source_workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID used by the lakehouse/warehouse. Defaults to None which resolves to the workspace of the attached lakehouse or if no lakehouse attached, resolves to the workspace of the notebook.
use_sql_endpoint (bool, default=True) – If True, the SQL Endpoint will be used for the connection. If False, Direct Lake over OneLake will be used.
tables (str | List[str], default=None) – The name(s) of the table(s) to update in the Direct Lake semantic model. If None, all tables will be updated (if there is only one expression). If multiple tables are specified, they must be provided as a list.
- sempy_labs.directlake.update_direct_lake_model_lakehouse_connection(dataset: str | UUID, workspace: str | UUID | None = None, lakehouse: str | None = None, lakehouse_workspace: str | UUID | None = None)
Remaps a Direct Lake semantic model’s SQL Endpoint connection to a new lakehouse.
- Parameters:
dataset (str | uuid.UUID) – Name or ID of the semantic model.
workspace (str | uuid. UUID, default=None) – The Fabric workspace name or ID in which the semantic model 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.
lakehouse (str | uuid.UUID, default=None) – The Fabric lakehouse used by the Direct Lake semantic model. Defaults to None which resolves to the lakehouse attached to the notebook.
lakehouse_workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID used by the lakehouse. Defaults to None which resolves to the workspace of the attached lakehouse or if no lakehouse attached, resolves to the workspace of the notebook.
- sempy_labs.directlake.update_direct_lake_partition_entity(dataset: str | UUID, table_name: str | List[str], entity_name: str | List[str], schema: str | None = None, workspace: str | UUID | None = None)
Remaps a table (or tables) in a Direct Lake semantic model to a table in a lakehouse.
- Parameters:
dataset (str | uuid.UUID) – Name or ID of the semantic model.
table_name (str, List[str]) – Name of the table(s) in the semantic model.
entity_name (str, List[str]) – Name of the lakehouse table to be mapped to the semantic model table.
schema (str, default=None) – The schema of the lakehouse table to be mapped to the semantic model table. Defaults to None which resolves to the existing schema of the lakehouse table.
workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID in which the semantic model 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.
- sempy_labs.directlake.warm_direct_lake_cache_isresident(dataset: str | UUID, workspace: str | UUID | None = None) DataFrame
Performs a refresh on the semantic model and puts the columns which were in memory prior to the refresh back into memory.
- Parameters:
- Returns:
Returns a pandas dataframe showing the columns that have been put into memory.
- Return type:
- sempy_labs.directlake.warm_direct_lake_cache_perspective(dataset: str | UUID, perspective: str, add_dependencies: bool = False, workspace: str | UUID | None = None) DataFrame
Warms the cache of a Direct Lake semantic model by running a simple DAX query against the columns in a perspective.
- Parameters:
dataset (str | uuid.UUID) – Name or ID of the semantic model.
perspective (str) – Name of the perspective which contains objects to be used for warming the cache.
add_dependencies (bool, default=False) – Includes object dependencies in the cache warming process.
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.
- Returns:
Returns a pandas dataframe showing the columns that have been put into memory.
- Return type: