Skip to content

Code Reference

Provides tools for managing and publishing items in a Fabric workspace.

Classes:

Name Description
FabricWorkspace

A class to manage and publish workspace items to the Fabric API.

Functions:

Name Description
append_feature_flag

Append a feature flag to the global feature_flag set.

change_log_level

Sets the log level for all loggers within the fabric_cicd package. Currently only supports DEBUG.

deploy_with_config

Deploy items using YAML configuration file with environment-specific settings.

publish_all_items

Publishes all items defined in the item_type_in_scope list of the given FabricWorkspace object.

unpublish_all_orphan_items

Unpublishes all orphaned items not present in the repository except for those matching the exclude regex.

FabricWorkspace

FabricWorkspace(
    repository_directory: str,
    item_type_in_scope: Optional[list[str]] = None,
    environment: str = "N/A",
    workspace_id: Optional[str] = None,
    workspace_name: Optional[str] = None,
    token_credential: TokenCredential = None,
    **kwargs,
)

A class to manage and publish workspace items to the Fabric API.

Parameters:

Name Type Description Default
workspace_id Optional[str]

The ID of the workspace to interact with. Either workspace_id or workspace_name must be provided. Considers only workspace_id if both are specified.

None
workspace_name Optional[str]

The name of the workspace to interact with. Either workspace_id or workspace_name must be provided. Considers only workspace_id if both are specified.

None
repository_directory str

Local directory path of the repository where items are to be deployed from.

required
item_type_in_scope Optional[list[str]]

Item types that should be deployed for a given workspace. If omitted, defaults to all available item types.

None
environment str

The environment to be used for parameterization.

'N/A'
token_credential TokenCredential

The token credential to use for API requests.

None
kwargs

Additional keyword arguments.

{}

Examples:

Basic usage

>>> from fabric_cicd import FabricWorkspace
>>> workspace = FabricWorkspace(
...     workspace_id="your-workspace-id",
...     repository_directory="/path/to/repo",
...     item_type_in_scope=["Environment", "Notebook", "DataPipeline"]
... )

Basic usage with workspace_name

>>> from fabric_cicd import FabricWorkspace
>>> workspace = FabricWorkspace(
...     workspace_name="your-workspace-name",
...     repository_directory="/path/to/repo"
... )

With optional parameters

>>> from fabric_cicd import FabricWorkspace
>>> workspace = FabricWorkspace(
...     workspace_id="your-workspace-id",
...     repository_directory="/your/path/to/repo",
...     item_type_in_scope=["Environment", "Notebook", "DataPipeline"],
...     environment="your-target-environment"
... )

With token credential

>>> from fabric_cicd import FabricWorkspace
>>> from azure.identity import ClientSecretCredential
>>> client_id = "your-client-id"
>>> client_secret = "your-client-secret"
>>> tenant_id = "your-tenant-id"
>>> token_credential = ClientSecretCredential(
...     client_id=client_id, client_secret=client_secret, tenant_id=tenant_id
... )
>>> workspace = FabricWorkspace(
...     workspace_id="your-workspace-id",
...     repository_directory="/your/path/to/repo",
...     item_type_in_scope=["Environment", "Notebook", "DataPipeline"],
...     token_credential=token_credential
... )

base_api_url property

base_api_url: str

Construct the base API URL using constants.

append_feature_flag

append_feature_flag(feature: str) -> None

Append a feature flag to the global feature_flag set.

Parameters:

Name Type Description Default
feature str

The feature flag to be included.

required

Examples:

Basic usage

>>> from fabric_cicd import append_feature_flag
>>> append_feature_flag("enable_lakehouse_unpublish")

change_log_level

change_log_level(level: str = 'DEBUG') -> None

Sets the log level for all loggers within the fabric_cicd package. Currently only supports DEBUG.

Parameters:

Name Type Description Default
level str

The logging level to set (e.g., DEBUG).

'DEBUG'

Examples:

Basic usage

>>> from fabric_cicd import change_log_level
>>> change_log_level("DEBUG")

deploy_with_config

deploy_with_config(
    config_file_path: str,
    environment: str = "N/A",
    token_credential: Optional[TokenCredential] = None,
    config_override: Optional[dict] = None,
) -> None

Deploy items using YAML configuration file with environment-specific settings. This function provides a simplified deployment interface that loads configuration from a YAML file and executes deployment operations based on environment-specific settings. It constructs the necessary FabricWorkspace object internally and handles publish/unpublish operations according to the configuration.

Parameters:

Name Type Description Default
config_file_path str

Path to the YAML configuration file as a string.

required
environment str

Environment name to use for deployment (e.g., 'dev', 'test', 'prod'), if missing defaults to 'N/A'.

'N/A'
token_credential Optional[TokenCredential]

Optional Azure token credential for authentication.

None
config_override Optional[dict]

Optional dictionary to override specific configuration values.

None

Raises:

Type Description
InputError

If configuration file is invalid or environment not found.

FileNotFoundError

If configuration file doesn't exist.

Examples:

Basic usage

>>> from fabric_cicd import deploy_with_config
>>> deploy_with_config(
...     config_file_path="workspace/config.yml",
...     environment="prod"
... )

With custom authentication

>>> from fabric_cicd import deploy_with_config
>>> from azure.identity import ClientSecretCredential
>>> credential = ClientSecretCredential(tenant_id, client_id, client_secret)
>>> deploy_with_config(
...     config_file_path="workspace/config.yml",
...     environment="prod",
...     token_credential=credential
... )

With override configuration

>>> from fabric_cicd import deploy_with_config
>>> from azure.identity import ClientSecretCredential
>>> credential = ClientSecretCredential(tenant_id, client_id, client_secret)
>>> deploy_with_config(
...     config_file_path="workspace/config.yml",
...     environment="prod",
...     config_override={
...         "core": {
...             "item_types_in_scope": ["Notebook"]
...         },
...         "publish": {
...             "skip": {
...                 "prod": False
...             }
...         }
...     }
... )

publish_all_items

publish_all_items(
    fabric_workspace_obj: FabricWorkspace,
    item_name_exclude_regex: Optional[str] = None,
    folder_path_exclude_regex: Optional[str] = None,
    items_to_include: Optional[list[str]] = None,
) -> None

Publishes all items defined in the item_type_in_scope list of the given FabricWorkspace object.

Parameters:

Name Type Description Default
fabric_workspace_obj FabricWorkspace

The FabricWorkspace object containing the items to be published.

required
item_name_exclude_regex Optional[str]

Regex pattern to exclude specific items from being published.

None
folder_path_exclude_regex Optional[str]

Regex pattern to exclude items based on their folder path.

None
items_to_include Optional[list[str]]

List of items in the format "item_name.item_type" that should be published.

None
folder_path_exclude_regex

This is an experimental feature in fabric-cicd. Use at your own risk as selective deployments are not recommended due to item dependencies. To enable this feature, see How To -> Optional Features for information on which flags to enable.

items_to_include

This is an experimental feature in fabric-cicd. Use at your own risk as selective deployments are not recommended due to item dependencies. To enable this feature, see How To -> Optional Features for information on which flags to enable.

Examples:

Basic usage

>>> from fabric_cicd import FabricWorkspace, publish_all_items
>>> workspace = FabricWorkspace(
...     workspace_id="your-workspace-id",
...     repository_directory="/path/to/repo",
...     item_type_in_scope=["Environment", "Notebook", "DataPipeline"]
... )
>>> publish_all_items(workspace)

With regex name exclusion

>>> from fabric_cicd import FabricWorkspace, publish_all_items
>>> workspace = FabricWorkspace(
...     workspace_id="your-workspace-id",
...     repository_directory="/path/to/repo",
...     item_type_in_scope=["Environment", "Notebook", "DataPipeline"]
... )
>>> exclude_regex = ".*_do_not_publish"
>>> publish_all_items(workspace, item_name_exclude_regex=exclude_regex)

With folder exclusion

>>> from fabric_cicd import FabricWorkspace, publish_all_items
>>> workspace = FabricWorkspace(
...     workspace_id="your-workspace-id",
...     repository_directory="/path/to/repo",
...     item_type_in_scope=["Environment", "Notebook", "DataPipeline"]
... )
>>> folder_exclude_regex = "^legacy/"
>>> publish_all_items(workspace, folder_path_exclude_regex=folder_exclude_regex)

With items to include

>>> from fabric_cicd import FabricWorkspace, publish_all_items
>>> workspace = FabricWorkspace(
...     workspace_id="your-workspace-id",
...     repository_directory="/path/to/repo",
...     item_type_in_scope=["Environment", "Notebook", "DataPipeline"]
... )
>>> items_to_include = ["Hello World.Notebook", "Hello.Environment"]
>>> publish_all_items(workspace, items_to_include=items_to_include)

unpublish_all_orphan_items

unpublish_all_orphan_items(
    fabric_workspace_obj: FabricWorkspace,
    item_name_exclude_regex: str = "^$",
    items_to_include: Optional[list[str]] = None,
) -> None

Unpublishes all orphaned items not present in the repository except for those matching the exclude regex.

Parameters:

Name Type Description Default
fabric_workspace_obj FabricWorkspace

The FabricWorkspace object containing the items to be published.

required
item_name_exclude_regex str

Regex pattern to exclude specific items from being unpublished. Default is '^$' which will exclude nothing.

'^$'
items_to_include Optional[list[str]]

List of items in the format "item_name.item_type" that should be unpublished.

None
items_to_include

This is an experimental feature in fabric-cicd. Use at your own risk as selective unpublishing is not recommended due to item dependencies. To enable this feature, see How To -> Optional Features for information on which flags to enable.

Examples:

Basic usage

>>> from fabric_cicd import FabricWorkspace, publish_all_items, unpublish_all_orphan_items
>>> workspace = FabricWorkspace(
...     workspace_id="your-workspace-id",
...     repository_directory="/path/to/repo",
...     item_type_in_scope=["Environment", "Notebook", "DataPipeline"]
... )
>>> publish_all_items(workspace)
>>> unpublish_orphaned_items(workspace)

With regex name exclusion

>>> from fabric_cicd import FabricWorkspace, publish_all_items, unpublish_all_orphan_items
>>> workspace = FabricWorkspace(
...     workspace_id="your-workspace-id",
...     repository_directory="/path/to/repo",
...     item_type_in_scope=["Environment", "Notebook", "DataPipeline"]
... )
>>> publish_all_items(workspace)
>>> exclude_regex = ".*_do_not_delete"
>>> unpublish_orphaned_items(workspace, item_name_exclude_regex=exclude_regex)

With items to include

>>> from fabric_cicd import FabricWorkspace, publish_all_items, unpublish_all_orphan_items
>>> workspace = FabricWorkspace(
...     workspace_id="your-workspace-id",
...     repository_directory="/path/to/repo",
...     item_type_in_scope=["Environment", "Notebook", "DataPipeline"]
... )
>>> publish_all_items(workspace)
>>> items_to_include = ["Hello World.Notebook", "Run Hello World.DataPipeline"]
>>> unpublish_orphaned_items(workspace, items_to_include=items_to_include)