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)

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.

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:
  • 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.

Returns:

The tables in the semantic model and their fallback reason.

Return type:

pandas.DataFrame

sempy_labs.directlake.direct_lake_schema_compare(dataset: str | UUID, workspace: str | UUID | None = None, **kwargs)

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.

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.

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:

pandas.DataFrame

sempy_labs.directlake.generate_direct_lake_semantic_model(dataset: str, lakehouse_tables: str | List[str], workspace: str | UUID | None = None, lakehouse: str | None = None, lakehouse_workspace: str | UUID | None = None, schema: str = 'dbo', overwrite: bool = False, refresh: bool = True)

Dynamically generates a Direct Lake semantic model based on tables in a Fabric lakehouse.

Parameters:
  • dataset (str) – Name of the semantic model to be created.

  • lakehouse_tables (str | List[str]) – The table(s) within the Fabric lakehouse to add to the semantic model. All columns from these tables will be added to the semantic model.

  • 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.

  • lakehouse (str, default=None) – The lakehouse which stores the delta tables which will feed the Direct Lake semantic model. Defaults to None which resolves to the attached lakehouse.

  • lakehouse_workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID in which the lakehouse 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.

  • schema (str, default="dbo") – The schema used for the lakehouse.

  • overwrite (bool, default=False) – If set to True, overwrites the existing semantic model if it already exists.

  • refresh (bool, default=True) – If True, refreshes the newly created semantic model after it is created.

sempy_labs.directlake.generate_shared_expression(item_name: str | None = None, item_type: str = 'Lakehouse', workspace: str | UUID | None = None) str

Dynamically generates the M expression used by a Direct Lake model for a given lakehouse/warehouse.

Parameters:
  • item_name (str, default=None) – The Fabric lakehouse or warehouse name. 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’.

  • 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.

Returns:

Shows the expression which can be used to connect a Direct Lake semantic model to its SQL Endpoint.

Return type:

str

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:

pandas.DataFrame

sempy_labs.directlake.get_direct_lake_lakehouse(dataset: str | UUID, workspace: str | UUID | None = None, lakehouse: str | None = None, lakehouse_workspace: str | UUID | None = None) Tuple[str, UUID]

Identifies the lakehouse used by 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.

  • 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.

  • 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.

Returns:

The lakehouse name and lakehouse ID.

Return type:

Tuple[str, uuid.UUID]

sempy_labs.directlake.get_direct_lake_source(dataset: str | UUID, workspace: str | UUID | None = None) Tuple[str, str, UUID, UUID]

Obtains the source information for a direct lake semantic model (if the source is located in the same workspace as the semantic model).

Parameters:
  • dataset (str | uuid.UUID) – The 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.

Returns:

If the source of the direct lake semantic model is a lakehouse this will return: ‘Lakehouse’, Lakehouse Name, SQL Endpoint Id, Workspace Id If the source of the direct lake semantic model is a warehouse this will return: ‘Warehouse’, Warehouse Name, Warehouse Id, Workspace Id If the semantic model is not a Direct Lake semantic model, it will return None, None, None.

Return type:

Tuple[str, str, UUID, UUID]

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:

pandas.DataFrame

sempy_labs.directlake.get_shared_expression(lakehouse: str | None = None, workspace: str | UUID | None = None) str

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:

str

sempy_labs.directlake.get_sku_size(workspace: str | UUID | None = None) str

Shows the SKU size for a workspace.

Parameters:

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:

The SKU size for a workspace.

Return type:

str

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:
  • 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.

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:

pandas.DataFrame

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:
  • 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.

Returns:

3 pandas dataframes showing objects in a semantic model which are not supported by Direct Lake.

Return type:

pandas.DataFrame, pandas.DataFrame, pandas.DataFrame

sempy_labs.directlake.update_direct_lake_model_connection(dataset: str | UUID, workspace: str | UUID | None = None, source: str | None = None, source_type: str = 'Lakehouse', source_workspace: str | UUID | None = None)

Remaps a Direct Lake semantic model’s SQL Endpoint connection to a new lakehouse/warehouse.

Parameters:
  • dataset (str | UUID) – Name or ID of the semantic model.

  • workspace (str | 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, 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 (str, default="Lakehouse") – The type of source for the Direct Lake semantic model. Valid options: “Lakehouse”, “Warehouse”.

  • source_workspace (str | 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.

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) – Name or ID of the semantic model.

  • workspace (str | 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, 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, 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:
  • 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.

Returns:

Returns a pandas dataframe showing the columns that have been put into memory.

Return type:

pandas.DataFrame

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:

pandas.DataFrame