Skip to content

Items

deploy_all_items(workspace, path, start_path=None)

Deploy all items to workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID of the workspace.

required
path str

The path to the notebooks.

required
start_path Optional[str]

The starting path for folder creation.

None
Source code in src/pyfabricops/helpers/items.py
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
def deploy_all_items(
    workspace: str,
    path: str,
    start_path: Optional[str] = None,
) -> None:
    """
    Deploy all items to workspace.

    Args:
        workspace (str): The name or ID of the workspace.
        path (str): The path to the notebooks.
        start_path (Optional[str]): The starting path for folder creation.
    """
    workspace_id = resolve_workspace(workspace)
    if workspace_id is None:
        return None

    types = ['Notebook', 'DataPipeline', 'Dataflow', 'SemanticModel', 'Report']
    for type in types:
        item_paths = list_paths_of_type(path, type)

        for path_ in item_paths:

            display_name = extract_display_name_from_platform(path_)
            if display_name is None:
                return None

            item_id = resolve_item(workspace_id, display_name)

            folder_path_string = extract_middle_path(
                path_, start_path=start_path
            )
            folder_id = create_folders_from_path_string(
                workspace_id, folder_path_string
            )

            item_definition = pack_item_definition(path_)

            if item_id is None:
                create_item(
                    workspace_id,
                    display_name=display_name,
                    item_definition=item_definition,
                    folder=folder_id,
                    df=False,
                )

            else:
                update_item_definition(
                    workspace_id,
                    item_id,
                    item_definition=item_definition,
                    df=False,
                )

    logger.success(
        f'All items were deployed to workspace "{workspace}" successfully.'
    )
    return None

deploy_item(workspace, path, start_path=None, description=None, df=True)

Creates or updates a item in Fabric based on local folder structure. Automatically detects the folder_id based on where the item is located locally.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
path str

The root path of the project.

required
start_path str

The starting path for the item.

None
description str

A description for the item.

None
df bool

Whether to return a DataFrame. Defaults to True.

True
Source code in src/pyfabricops/helpers/items.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
@df
def deploy_item(
    workspace: str,
    path: str,
    start_path: Optional[str] = None,
    description: Optional[str] = None,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Creates or updates a item in Fabric based on local folder structure.
    Automatically detects the folder_id based on where the item is located locally.

    Args:
        workspace (str): The workspace name or ID.
        path (str): The root path of the project.
        start_path (str, optional): The starting path for the item.
        description (str, optional): A description for the item.
        df (bool, optional): Whether to return a DataFrame. Defaults to True.
    """
    workspace_id = resolve_workspace(workspace)
    if not workspace_id:
        return None

    display_name = extract_display_name_from_platform(path)
    if display_name is None:
        return None

    item_id = resolve_item(workspace_id, display_name)

    folder_path_string = extract_middle_path(path, start_path=start_path)
    folder_id = create_folders_from_path_string(
        workspace_id, folder_path_string
    )

    item_definition = pack_item_definition(path)

    if item_id is None:
        return create_item(
            workspace_id,
            display_name=display_name,
            item_definition=item_definition,
            description=description,
            folder=folder_id,
            df=False,
        )

    else:
        return update_item_definition(
            workspace_id,
            item_id,
            item_definition=item_definition,
            df=False,
        )

export_all_items(workspace, path)

Exports all items to the specified folder structure.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
path str

The root path of the project.

required
Source code in src/pyfabricops/helpers/items.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def export_all_items(
    workspace: str,
    path: str,
) -> None:
    """
    Exports all items to the specified folder structure.

    Args:
        workspace (str): The workspace name or ID.
        path (str): The root path of the project.
    """
    workspace_id = resolve_workspace(workspace)
    if workspace_id is None:
        return None

    items = list_items(workspace_id, df=False)

    if items is None:
        return None

    items = [item for item in items if item['type'] != 'SQLEndpoint']

    for item in items:
        item_id = item['id']
        item_ = get_item(workspace_id, item_id, df=False)
        if not item_:
            return None

        item_id = item_['id']
        item_name = item_['displayName']
        item_type = item_['type']

        definition = get_item_definition(workspace_id, item_id)
        if not definition:
            return None

        folder_id = None
        folder_path = None

        if 'folderId' in item_:
            folder_id = item_['folderId']

            try:
                folder_path = resolve_folder_from_id_to_path(
                    workspace_id, folder_id
                )
            except:
                logger.info(
                    f'{item["displayName"]}.{item_type} is not inside a folder.'
                )
                folder_path = None

        if folder_path is None:
            item_path = Path(path) / f'{item_name}.{item_type}'
        else:
            item_path = Path(path) / folder_path / f'{item_name}.{item_type}'
        os.makedirs(item_path, exist_ok=True)

        unpack_item_definition(definition, item_path)

        logger.success(
            f'{item_name}.{item_type} was exported to {item_path} successfully.'
        )
    return None

export_item(workspace, item, path)

Exports a item definition to a specified folder structure.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
item str

The name of the item to export.

required
path str

The root path of the project.

required

Examples:

export_item('MyProjectWorkspace', 'SalesDataModel', '/path/to/project')
export_item('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000', '/path/to/project')
Source code in src/pyfabricops/helpers/items.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def export_item(
    workspace: str,
    item: str,
    path: str,
):
    """
    Exports a item definition to a specified folder structure.

    Args:
        workspace (str): The workspace name or ID.
        item (str): The name of the item to export.
        path (str): The root path of the project.

    Examples:
        ```python
        export_item('MyProjectWorkspace', 'SalesDataModel', '/path/to/project')
        export_item('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000', '/path/to/project')
        ```
    """
    workspace_id = resolve_workspace(workspace)
    if not workspace_id:
        return None

    item_ = get_item(workspace_id, item, df=False)
    if not item_:
        return None

    item_id = item_['id']
    definition = get_item_definition(workspace_id, item_id)
    if not definition:
        return None

    item_type = item_['type']
    item_name = item_['displayName']

    folder_id = None
    folder_path = None

    if 'folderId' in item_:
        folder_id = item_['folderId']
        try:
            folder_path = resolve_folder_from_id_to_path(
                workspace_id, folder_id
            )
        except:
            logger.info(f'{item_name}.{item_type} is not inside a folder.')
            folder_path = None

    if folder_path is None:
        item_path = Path(path) / f'{item_name}.{item_type}'
    else:
        item_path = Path(path) / folder_path / f'{item_name}.{item_type}'

    os.makedirs(item_path, exist_ok=True)

    unpack_item_definition(definition, item_path)

    logger.success(
        f'{item_name}.{item_type} was exported to {item_path} successfully.'
    )
    return None