sempy_labs.variable_library package

Module contents

sempy_labs.variable_library.create_variable_library(name: str, variables: List[dict], value_sets: List[dict], value_sets_order: List[str] | None = None, description: str | None = None, workspace: str | UUID | None = None, folder: str | PathLike | None = None)

Creates a variable library.

This is a wrapper function for the following API: Items - Create Variable Library.

Service Principal Authentication is supported (see here for examples).

Parameters:
  • name (str) – Name of the variable library.

  • variables (List[dict]) –

    A list of variable definitions. Each variable definition should be a dictionary with keys such as ‘name’, ‘type’, ‘value’, and ‘note’.

    Example:

    variables = [

    { “name”: “variable1”, “note”: “Some optional note”, “type”: “String”, “value”: “Some string value” }, { “name”: “variableWithoutNote”, “type”: “Boolean”, “value”: True }

    ]

  • value_sets (List[dict]) –

    A list of value set definitions. Each value set definition should be a dictionary with keys such as ‘name’ and ‘variableOverrides’.

    Example:

    value_sets = [
    {

    “name”: “valueSet1”, “variableOverrides”: [

    {

    “name”: “variable1”, “value”: “Overridden string value”

    }, {

    ”name”: “variableWithoutNote”, “value”: False

    }

    ]

    }, {

    “name”: “valueSet0”, “variableOverrides”: [

    {

    “name”: “variable1”, “value”: “Another overridden string value”

    }, {

    ”name”: “variableWithoutNote”, “value”: True

    }

    ]

    }

    ]

  • value_sets_order (List[str], default=None) – The order of value sets. If None, a default order will be used.

  • description (str, default=None) – Description of the variable library.

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

  • folder (str | PathLike, default=None) – The folder path within the workspace to create the variable library in.

sempy_labs.variable_library.delete_variable_library(variable_library: str | UUID, workspace: str | UUID | None = None)

Deletes a variable library.

This is a wrapper function for the following API: `Items - Delete Variable Library https://learn.microsoft.com/rest/api/fabric/variablelibrary/items/delete-variable-library>`_.

Parameters:
  • navariable_libraryme (str | uuid.UUID) – Name or ID of the variable library.

  • 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.variable_library.get_variable_library(variable_library: str | UUID, workspace: str | UUID | None = None) DataFrame

Returns properties of the specified variable library.

This is a wrapper function for the following API: Items - Get Variable Library.

Service Principal Authentication is supported (see here for examples).

Parameters:
  • variable_library (str | uuid.UUID) – Name or ID of the variable library.

  • 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 properties of the variable library.

Return type:

pandas.DataFrame

sempy_labs.variable_library.get_variable_library_definition(variable_library: str | UUID, workspace: str | UUID | None = None, decode: bool = True, return_dataframe: bool = False) dict | DataFrame

Gets the definition of a variable library.

This is a wrapper function for the following API: Items - Get Variable Library Definition.

Service Principal Authentication is supported (see here for examples).

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:

A dictionary showing the definition or a pandas dataframe showing the definition.

Return type:

dict | pandas.DataFrame

sempy_labs.variable_library.get_variable_value(variable_name: str, variable_library: str | UUID, workspace: str | UUID | None = None, value_set: str | None = None) Any

Gets the value of a single variable in a variable library.

Service Principal Authentication is supported (see here for examples).

Parameters:
  • variable_name (str) – Name of the variable.

  • variable_library (str | uuid.UUID) – Name or ID of the variable library.

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

  • value_set (str, default=None) – The name of the value set to use for variable overrides. If None, the active value set of the variable library will be used.

Returns:

The value of the variable.

Return type:

Any

sempy_labs.variable_library.get_variable_values(variable_names: List[str], variable_library: str | UUID, workspace: str | UUID | None = None, value_set: str | None = None) dict

Gets the values of multiple variables from a variable library with a single call to list_variables.

Service Principal Authentication is supported (see here for examples).

Parameters:
  • variable_names (List[str]) – A list of variable names to retrieve.

  • variable_library (str | uuid.UUID) – Name or ID of the variable library.

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

  • value_set (str, default=None) – The name of the value set to use for variable overrides. If None, the active value set of the variable library will be used.

Returns:

Dictionary mapping variable names to their corresponding values.

Return type:

dict

sempy_labs.variable_library.list_variable_libraries(workspace: str | UUID | None = None) DataFrame

Shows the variable libraries within a workspace.

This is a wrapper function for the following API: Items - List Variable Libraries.

Service Principal Authentication is supported (see here for examples).

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:

A pandas dataframe showing the variable libraries within a workspace.

Return type:

pandas.DataFrame

sempy_labs.variable_library.list_variables(variable_library: str | UUID, workspace: str | UUID | None = None) DataFrame

Lists the variables in a variable library.

Service Principal Authentication is supported (see here for examples).

Parameters:
  • variable_library (str | uuid.UUID) – Name or ID of the variable library.

  • 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 variables within a variable library.

Return type:

pandas.DataFrame

sempy_labs.variable_library.update_variable(variable_library: str | UUID, name: str, new_name: str | None = None, type: Literal['Boolean', 'DateTime', 'Number', 'Integer', 'String'] = None, value: str | None = None, note: str | None = None, workspace: str | UUID | None = None)

Updates the properties of the specified variable within a variable library.

Service Principal Authentication is supported (see here for examples).

Parameters:
  • variable_library (str | uuid.UUID) – Name or ID of the variable library.

  • name (str) – Name of the variable.

  • new_name (str, default=None) – New name of the variable. Defaults to None which keeps the same name.

  • type (Literal["Boolean", "DateTime", "Number", "Integer", "String"], default=None) – New type of the variable. Valid types are: “Boolean”, “DateTime”, “Number”, “Integer”, “String”. Defaults to None which keeps the same type.

  • value (str, default=None) – New value of the variable. Defaults to None which keeps the same value.

  • note (str, default=None) – New note of the variable. Defaults to None which keeps the same note.

  • 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.variable_library.update_variable_library(variable_library: str | UUID, name: str | None = None, description: str | None = None, default_value_set: str | None = None, workspace: str | UUID | None = None)

Updates the properties of the specified variable library.

This is a wrapper function for the following API: Items - Update Variable Library.

Service Principal Authentication is supported (see here for examples).

Parameters:
  • variable_library (str | uuid.UUID) – Name or ID of the variable library.

  • name (str, default=None) – New name of the variable library.

  • description (str, default=None) – New description of the variable library.

  • default_value_set (str, default=None) – New default value set name of the variable library.

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