sempy_labs.semantic_model package

Module contents

sempy_labs.semantic_model.approved_for_copilot(dataset: str | UUID, approved_for_copilot: bool, workspace: str | UUID | None = None)

Turn on this setting to approve your model for Copilot use. This improves visibility in search results and removes the warning in standalone Copilot in Power BI that your organization hasn’t approved the data.

Parameters:
  • dataset (str | uuid.UUID) – The name or UUID of the semantic model.

  • approved_for_copilot (bool) – Set to True to approve the model for Copilot use, or False to disapprove it.

  • 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.semantic_model.direct_lake_manager(dataset: str | UUID | None = None, workspace: str | UUID | None = None, dark_mode: bool = False)

Generates an interactive editor for managing Direct Lake semantic models.

The editor lets you pick an existing Direct Lake semantic model within a given workspace or create a new Direct Lake model from a supported source (leveraging sempy_labs.directlake.generate_direct_lake_semantic_model()). Once a model is open, you can add or edit sources, reassign tables to a different source, add new tables to the model, and refresh the model.

Parameters:
  • dataset (str | uuid.UUID, default=None) – Name or ID of a Direct Lake semantic model to open immediately. If None, the manager opens on the model-selection screen.

  • workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID where datasets are listed and where new models are created by default. Defaults to None which resolves to the workspace of the attached lakehouse or, if no lakehouse is attached, the workspace of the notebook.

  • dark_mode (bool, default=False) – If True, renders the manager with a dark color theme. If False, renders with a light color theme.

sempy_labs.semantic_model.enable_query_caching(dataset: str | UUID, workspace: str | UUID | None = None, enable: bool = True)

Enables or disables query caching for a semantic model.

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

  • workspace (str | uuid.UUID, default=None) – The 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) – Set to True to enable query caching, or False to disable it.

sempy_labs.semantic_model.find_unused_objects(dataset: str | UUID | None = None, workspace: str | UUID | None = None, method: Literal['Report', 'WorkspaceMonitoring'] = 'WorkspaceMonitoring', workspace_monitoring_days: int = 7, visualize: bool = True, dark_mode: bool = False) DataFrame | None

Identifies used and unused objects (tables, columns and measures) in a semantic model.

Object usage is determined by scoring the DAX queries that reference the model (either captured by workspace monitoring, or reconstructed from the model’s downstream reports), expanding each direct reference through the model’s calculation dependencies, and counting how often each object was used. An object with a usage count of zero is unused.

Parameters:
  • dataset (str | uuid.UUID, default=None) – Name or ID of the semantic model. Defaults to None which opens the widget on a workspace / semantic model picker so the model to analyze can be chosen interactively. Required when visualize is False.

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

  • method (Literal["Report", "WorkspaceMonitoring"], default="WorkspaceMonitoring") –

    The source of usage information (used to compute the returned dataframe when visualize is False, and to preselect the analysis method in the interactive widget when visualize is True).

    • ”WorkspaceMonitoring” scores the DAX queries captured by workspace monitoring. Workspace monitoring must be enabled on the workspace.

    • ”Report” scores the objects referenced by the model’s downstream reports (which must be in the PBIR format). Each reference to an object within a report counts as one use.

  • workspace_monitoring_days (int, default=7) – The number of days of workspace monitoring history to analyze (also the initial time frame preselected in the interactive widget). Only used with the “WorkspaceMonitoring” method.

  • visualize (bool, default=True) – If True, displays an interactive widget that lets you choose the analysis method (workspace monitoring or downstream reports) and, for workspace monitoring, the time frame; it then shows the unused/used objects as a table -> column/measure tree. Returns None. If False, runs the analysis for the given method/workspace_monitoring_days and returns a pandas dataframe.

  • dark_mode (bool, default=False) – If True, the interactive widget is rendered with a dark color theme. Only used when visualize is True.

Returns:

If visualize is False, a pandas dataframe with the columns ‘Table Name’, ‘Object Type’, ‘Object Name’, ‘IsUsed’ and ‘UsageCount’. If visualize is True, displays the widget and returns None.

Return type:

pandas.DataFrame | None

sempy_labs.semantic_model.lineage_view(dataset: str | UUID | None = None, workspace: str | UUID | None = None, dark_mode: bool = False)

Displays an interactive lineage view for a semantic model.

Shows a node graph placing the semantic model at the center with each downstream report (i.e. the reports in the model’s workspace that consume it) arranged around it. Each report can be analyzed for broken elements — references to columns, measures or hierarchies that no longer exist in the semantic model — with a side panel summarizing the results per report. Selecting a broken report lists its broken objects (grouped by object); a valid replacement object can be chosen from the model to stage a fix, and the staged fixes are written back to the report(s) with the Save button. Reports can also be selected and rebound to a different semantic model.

Both the ‘PBIR’ and ‘PBIRLegacy’ report formats are supported for broken-element analysis and fixes.

Parameters:
  • dataset (str | uuid.UUID, default=None) – Name or ID of the semantic model. Defaults to None which opens the view on a workspace / semantic model picker so the model to evaluate can be chosen interactively.

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

  • dark_mode (bool, default=False) – If True, renders the view with a dark color theme. If False, renders with a light color theme.

sempy_labs.semantic_model.make_discoverable(dataset: str | UUID, make_discoverable: bool, workspace: str | UUID | None = None)

Allow users without access to this semantic model to discover it and request permissions to access the data. The semantic model must be endorsed as ‘Promoted’, ‘Certified’, or ‘Master data’ to be made discoverable.

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

  • make_discoverable (bool) – Whether to make the semantic model discoverable.

  • workspace (str | uuid.UUID, default=None) – The 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.semantic_model.migrate_to_direct_lake(dataset: str | UUID | None = None, workspace: str | UUID | None = None, dark_mode: bool = False)

Generates an interactive wizard to migrate an import/DirectQuery semantic model to Direct Lake.

The wizard follows a guided, four-step flow: it analyzes the source model (showing which tables migrate and which are dropped), lets you configure the new model name, target workspace and Direct Lake source (Lakehouse or Warehouse), previews the plan, and then creates the new Direct Lake semantic model. It orchestrates the Semantic Link Labs migration functions (sempy_labs.migration.create_pqt_file(), sempy_labs.create_blank_semantic_model(), sempy_labs.migration.migrate_tables_columns_to_semantic_model() and the related migrate_* helpers) under the hood.

Parameters:
  • dataset (str | uuid.UUID, default=None) – Name or ID of the import/DirectQuery semantic model to migrate. Defaults to None which opens the wizard on a workspace / semantic model picker so the model to migrate can be chosen interactively.

  • workspace (str | uuid.UUID, default=None) – The Fabric workspace name or ID in which the source semantic model exists. Defaults to None which resolves to the workspace of the attached lakehouse or, if no lakehouse is attached, the workspace of the notebook.

  • dark_mode (bool, default=False) – If True, renders the wizard with a dark color theme. If False, renders with a light color theme.

sempy_labs.semantic_model.perspective_editor(dataset: str | UUID, workspace: str | UUID | None = None, dark_mode: bool = False)

Generates an interactive editor for managing perspectives within a semantic model.

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

  • workspace (str | uuid.UUID, default=None) – The 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.

  • dark_mode (bool, default=False) – If True, renders the editor with a dark color theme. If False, renders with a light color theme.

sempy_labs.semantic_model.set_endorsement(dataset: str | UUID, endorsement: Literal['None', 'Promoted', 'Certified', 'Master data'], workspace: str | UUID | None = None)

Sets the endorsement status for a semantic model.

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

  • endorsement (Literal["None", "Promoted", "Certified", "Master data"]) – The endorsement status to set for the semantic model.

  • workspace (str | uuid.UUID, default=None) – The 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.