Skip to content

Workspaces

add_workspace_role_assignment(workspace, user_uuid, user_type='User', role='Admin', *, df=True)

Adds a permission to a workspace for a user.

Parameters:

Name Type Description Default
workspace str

The ID or name of the workspace.

required
user_uuid str

The UUID of the user.

required
user_type str

The type of user (options: User, Group, ServicePrincipal, ServicePrincipalProfile).

'User'
role str

The role to assign (options: admin, member, contributor, viewer).

'Admin'
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The role assignment details if successful.

Raises:

Type Description
ResourceNotFoundError

If the specified workspace is not found.

OptionNotAvailableError

If the user type or role is invalid.

Examples:

add_workspace_role_assignment(
    '123e4567-e89b-12d3-a456-426614174000',
    'FefEFewf-feF-1234-5678-9abcdef01234', user_type='User', role='Admin'
)
Source code in src/pyfabricops/core/workspaces.py
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
@df
def add_workspace_role_assignment(
    workspace: str,
    user_uuid: str,
    user_type: Literal[
        'User', 'Group', 'ServicePrincipal', 'ServicePrincipalProfile'
    ] = 'User',
    role: Literal['Admin', 'Contributor', 'Member', 'Viewer'] = 'Admin',
    *,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Adds a permission to a workspace for a user.

    Args:
        workspace (str): The ID or name of the workspace.
        user_uuid (str): The UUID of the user.
        user_type (str): The type of user (options: User, Group, ServicePrincipal, ServicePrincipalProfile).
        role (str): The role to assign (options: admin, member, contributor, viewer).
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The role assignment details if successful.

    Raises:
        ResourceNotFoundError: If the specified workspace is not found.
        OptionNotAvailableError: If the user type or role is invalid.

    Examples:
        ```python
        add_workspace_role_assignment(
            '123e4567-e89b-12d3-a456-426614174000',
            'FefEFewf-feF-1234-5678-9abcdef01234', user_type='User', role='Admin'
        )
        ```
    """
    if user_type not in [
        'User',
        'Group',
        'ServicePrincipal',
        'ServicePrincipalProfile',
    ]:
        raise OptionNotAvailableError(
            f'Invalid user type: {user_type}. Must be one of: User, Group, ServicePrincipal, ServicePrincipalProfile'
        )
    if role not in ['Admin', 'Contributor', 'Member', 'Viewer']:
        raise OptionNotAvailableError(
            f'Invalid role: {role}. Must be one of: Admin, Contributor, Member, Viewer'
        )
    payload = {'principal': {'id': user_uuid, 'type': user_type}, 'role': role}

    return api_request(
        '/workspaces/' + resolve_workspace(workspace) + '/roleAssignments',
        payload=payload,
        method='post',
    )

assign_to_capacity(workspace, capacity)

Assigns a workspace to a capacity.

Parameters:

Name Type Description Default
workspace str

The ID or name of the workspace to assign.

required
capacity str

The ID or name of the capacity to assign the workspace to.

required

Returns:

Type Description
None

None

Examples:

assign_to_capacity(
    '123e4567-e89b-12d3-a456-426614174000',
    'b7e2c1a4-8f3e-4c2a-9d2e-7b1e5f6a8c9d'
)
Source code in src/pyfabricops/core/workspaces.py
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
def assign_to_capacity(workspace: str, capacity: str) -> None:
    """
    Assigns a workspace to a capacity.

    Args:
        workspace (str): The ID or name of the workspace to assign.
        capacity (str): The ID or name of the capacity to assign the workspace to.

    Returns:
        None

    Examples:
        ```python
        assign_to_capacity(
            '123e4567-e89b-12d3-a456-426614174000',
            'b7e2c1a4-8f3e-4c2a-9d2e-7b1e5f6a8c9d'
        )
        ```
    """
    payload = {'capacityId': resolve_capacity(capacity)}
    response = api_request(
        '/workspaces/' + resolve_workspace(workspace) + '/assignToCapacity',
        payload=payload,
        method='post',
        return_raw=True,
    )
    if response.status_code == 202:
        # Assuming the API returns a 202 status code for successful assignment
        logger.success(
            f'Workspace {workspace} assigned to capacity {capacity} successfully.'
        )
        return None
    else:
        logger.error(f'{response.status_code}: {response.error}')
        return None

create_workspace(display_name, *, capacity=None, description=None, df=True)

Create a new workspace with the specified name, capacity and description.

Parameters:

Name Type Description Default
display_name str

The name of the workspace to create.

required
capacity str

The ID or name of the capacity to assign to the workspace. Defaults to None.

None
description str

A description for the workspace. Defaults to None.

None
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The details of the created or updated workspace if successful, otherwise None.

Examples:

create_workspace(
    'MyProject',
    capacity_id='85974fbf-2c3b-4d5e-8f6a-7b8c9d0e1f2g',
    description='My new project workspace',
)
Source code in src/pyfabricops/core/workspaces.py
 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
@df
def create_workspace(
    display_name: str,
    *,
    capacity: Optional[str] = None,
    description: Optional[str] = None,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Create a new workspace with the specified name, capacity and description.

    Args:
        display_name (str): The name of the workspace to create.
        capacity (str, optional): The ID or name of the capacity to assign to the workspace. Defaults to None.
        description (str, optional): A description for the workspace. Defaults to None.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The details of the created or updated workspace if successful, otherwise None.

    Examples:
        ```python
        create_workspace(
            'MyProject',
            capacity_id='85974fbf-2c3b-4d5e-8f6a-7b8c9d0e1f2g',
            description='My new project workspace',
        )
        ```
    """
    payload = {'displayName': display_name}

    if capacity:
        payload['capacityId'] = resolve_capacity(capacity)

    if description:
        payload['description'] = description

    return api_request('/workspaces', payload=payload, method='post')

delete_workspace(workspace)

Delete a workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID of the workspace to delete.

required

Returns:

Type Description
None

None

Raises:

Type Description
ResourceNotFoundError

If the specified workspace is not found.

Examples:

delete_workspace('123e4567-e89b-12d3-a456-426614174000')
Source code in src/pyfabricops/core/workspaces.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
def delete_workspace(workspace: str) -> None:
    """
    Delete a workspace.

    Args:
        workspace (str): The name or ID of the workspace to delete.

    Returns:
        None

    Raises:
        ResourceNotFoundError: If the specified workspace is not found.

    Examples:
        ```python
        delete_workspace('123e4567-e89b-12d3-a456-426614174000')
        ```
    """
    workspace_id = resolve_workspace(workspace)

    if not workspace_id:
        return None

    return api_request(
        '/workspaces/' + resolve_workspace(workspace),
        method='delete',
    )

delete_workspace_role_assignment(workspace, user_uuid)

Removes a permission from a workspace for a user.

Parameters:

Name Type Description Default
workspace str

The ID or name of the workspace.

required
user_uuid str

The ID of the user to remove.

required

Returns:

Name Type Description
None None

If the role assignment is successfully deleted.

Examples:

    delete_workspace_role_assignment(
        '123e4567-e89b-12d3-a456-426614174000',
        'FefEFewf-feF-1234-5678-9abcdef01234',
    )
Source code in src/pyfabricops/core/workspaces.py
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
def delete_workspace_role_assignment(
    workspace: str,
    user_uuid: str,
) -> None:
    """
    Removes a permission from a workspace for a user.

    Args:
        workspace (str): The ID or name of the workspace.
        user_uuid (str): The ID of the user to remove.

    Returns:
        None: If the role assignment is successfully deleted.

    Examples:
    ```python
        delete_workspace_role_assignment(
            '123e4567-e89b-12d3-a456-426614174000',
            'FefEFewf-feF-1234-5678-9abcdef01234',
        )
    ```
    """
    return api_request(
        '/workspaces/'
        + resolve_workspace(workspace)
        + '/roleAssignments/'
        + user_uuid,
        method='delete',
    )

get_workspace(workspace, df=True)

Returns the specified workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID of the workspace to retrieve.

required
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, List[Dict[str, Any]], None]

(Union[DataFrame, List[Dict[str, Any]], None]) The details of the workspace if found, otherwise None. If df=True, returns a DataFrame with flattened keys.

Examples:

get_workspace('123e4567-e89b-12d3-a456-426614174000')
get_workspace('MyProjectWorkspace')
get_workspace('MyProjectWorkspace', df=False) # Returns as list
Source code in src/pyfabricops/core/workspaces.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
@df
def get_workspace(
    workspace: str, df: Optional[bool] = True
) -> Union[DataFrame, List[Dict[str, Any]], None]:
    """
    Returns the specified workspace.

    Args:
        workspace (str): The name or ID of the workspace to retrieve.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
                If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, List[Dict[str, Any]], None]) The details of the workspace if found, otherwise None. If `df=True`, returns a DataFrame with flattened keys.

    Examples:
        ```python
        get_workspace('123e4567-e89b-12d3-a456-426614174000')
        get_workspace('MyProjectWorkspace')
        get_workspace('MyProjectWorkspace', df=False) # Returns as list
        ```
    """
    return api_request('/workspaces/' + resolve_workspace(workspace))

get_workspace_id(workspace)

Retrieves the ID of a workspace by its name.

Parameters:

Name Type Description Default
workspace str

The name of the workspace.

required

Returns:

Type Description
Union[str, None]

str | None: The ID of the workspace if found, otherwise None.

Source code in src/pyfabricops/core/workspaces.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def get_workspace_id(workspace: str) -> Union[str, None]:
    """
    Retrieves the ID of a workspace by its name.

    Args:
        workspace (str): The name of the workspace.

    Returns:
        str | None: The ID of the workspace if found, otherwise None.
    """
    workspaces = list_workspaces(df=False)
    for _workspace in workspaces:
        if _workspace['displayName'] == workspace:
            return _workspace['id']

    logger.warning(f"Workspace '{workspace}' not found.")
    return None

get_workspace_role_assignment(workspace, user_uuid, *, df=True)

Retrieves the role of a user in a workspace.

Parameters:

Name Type Description Default
workspace str

The name or id of the workspace to get role assignment for.

required
user_uuid str

The UUID of the user to check.

required
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The role assignment if found, otherwise None.

Examples:

get_workspace_role_assignment(
    '123e4567-e89b-12d3-a456-426614174000',
    'FefEFewf-feF-1234-5678-9abcdef01234'
)
Source code in src/pyfabricops/core/workspaces.py
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
@df
def get_workspace_role_assignment(
    workspace: str,
    user_uuid: str,
    *,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Retrieves the role of a user in a workspace.

    Args:
        workspace (str): The name or id of the workspace to get role assignment for.
        user_uuid (str): The UUID of the user to check.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The role assignment if found, otherwise None.

    Examples:
        ```python
        get_workspace_role_assignment(
            '123e4567-e89b-12d3-a456-426614174000',
            'FefEFewf-feF-1234-5678-9abcdef01234'
        )
        ```
    """
    return api_request(
        '/workspaces/'
        + resolve_workspace(workspace)
        + '/roleAssignments/'
        + user_uuid
    )

list_workspace_role_assignments(workspace, *, df=True)

Lists all role assignments for a workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID of the workspace to list role assignments for.

required
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, List[Dict[str, Any]], None]

A list of role assignments.

Examples:

list_workspace_role_assignments('123e4567-e89b-12d3-a456-426614174000')
Source code in src/pyfabricops/core/workspaces.py
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
@df
def list_workspace_role_assignments(
    workspace: str,
    *,
    df: Optional[bool] = True,
) -> Union[DataFrame, List[Dict[str, Any]], None]:
    """
    Lists all role assignments for a workspace.

    Args:
        workspace (str): The name or ID of the workspace to list role assignments for.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, List[Dict[str, Any]], None]): A list of role assignments.


    Examples:
        ```python
        list_workspace_role_assignments('123e4567-e89b-12d3-a456-426614174000')
        ```
    """
    return api_request(
        '/workspaces/' + resolve_workspace(workspace) + '/roleAssignments',
        support_pagination=True,
    )

list_workspaces(df=True)

Returns a list of workspaces.

Parameters:

Name Type Description Default
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
DataFrame | list | None

A list of workspaces or a DataFrame if df is True.

Examples:

list_workspaces() # Returns as DataFrame
list_workspaces(df=False) # Returns as list
Source code in src/pyfabricops/core/workspaces.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@df
def list_workspaces(
    df: Optional[bool] = True,
) -> Union[DataFrame, List[Dict[str, Any]], None]:
    """
    Returns a list of workspaces.

    Args:
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (DataFrame | list | None): A list of workspaces or a DataFrame if df is True.

    Examples:
        ```python
        list_workspaces() # Returns as DataFrame
        list_workspaces(df=False) # Returns as list
        ```
    """
    return api_request('/workspaces', support_pagination=True)

resolve_workspace(workspace)

Resolves a workspace name to its ID.

Parameters:

Name Type Description Default
workspace str

The name of the workspace.

required

Returns:

Type Description
Union[str, None]

str | None: The ID of the workspace if found, otherwise None.

Source code in src/pyfabricops/core/workspaces.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def resolve_workspace(workspace: str) -> Union[str, None]:
    """
    Resolves a workspace name to its ID.

    Args:
        workspace (str): The name of the workspace.

    Returns:
        str | None: The ID of the workspace if found, otherwise None.
    """
    if is_valid_uuid(workspace):
        return workspace
    else:
        return get_workspace_id(workspace)

unassign_from_capacity(workspace)

Unassigns a workspace from its current capacity.

Parameters:

Name Type Description Default
workspace str

The ID or name of the workspace to unassign.

required

Returns:

Type Description
None

None

Examples:

unassign_from_capacity('123e4567-e89b-12d3-a456-426614174000')
Source code in src/pyfabricops/core/workspaces.py
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
def unassign_from_capacity(workspace: str) -> None:
    """
    Unassigns a workspace from its current capacity.

    Args:
        workspace (str): The ID or name of the workspace to unassign.

    Returns:
        None

    Examples:
        ```python
        unassign_from_capacity('123e4567-e89b-12d3-a456-426614174000')
        ```
    """
    response = api_request(
        '/workspaces/'
        + resolve_workspace(workspace)
        + '/unassignFromCapacity',
        method='post',
        return_raw=True,
    )
    if response.status_code == 202:
        logger.success(
            f'Workspace {workspace} unassigned from capacity successfully.'
        )
        return None
    else:
        logger.error(f'{response.status_code}: {response.error}')
        return None

update_workspace(workspace, *, display_name=None, description=None, df=True)

Updates the properties of a workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID to update.

required
display_name str

The new name for the workspace.

None
description str

The new description for the workspace.

None
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
DataFrame | dict | None

The updated workspace details. If df=True, returns a DataFrame with flattened keys.

Examples:

update_workspace(
    '123e4567-e89b-12d3-a456-426614174000',
    display_name='New Workspace Name',
)

update_workspace(
    'MyProjectWorkspace',
    description='Updated description',
)

update_workspace(
    '123e4567-e89b-12d3-a456-426614174000',
    display_name='New Workspace Name',
    description='Updated description',
)
Source code in src/pyfabricops/core/workspaces.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
@df
def update_workspace(
    workspace: str,
    *,
    display_name: Optional[str] = None,
    description: Optional[str] = None,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Updates the properties of a workspace.

    Args:
        workspace (str): The workspace name or ID to update.
        display_name (str, optional): The new name for the workspace.
        description (str, optional): The new description for the workspace.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (DataFrame | dict | None): The updated workspace details. If `df=True`, returns a DataFrame with flattened keys.

    Examples:
        ```python
        update_workspace(
            '123e4567-e89b-12d3-a456-426614174000',
            display_name='New Workspace Name',
        )

        update_workspace(
            'MyProjectWorkspace',
            description='Updated description',
        )

        update_workspace(
            '123e4567-e89b-12d3-a456-426614174000',
            display_name='New Workspace Name',
            description='Updated description',
        )
        ```
    """
    if not display_name and not description:
        logger.warning(
            'No changes provided. Please specify at least one property to update.'
        )
        return None

    payload = {}
    if display_name:
        payload['displayName'] = display_name
    if description:
        payload['description'] = description

    return api_request(
        '/workspaces/' + resolve_workspace(workspace),
        payload=payload,
        method='patch',
    )

update_workspace_role_assignment(workspace, user_uuid, role='Admin', *, df=True)

Update a role to a existing workspace role assignment.

Parameters:

Name Type Description Default
workspace str

The ID or name of the workspace.

required
user_uuid str

The UUID of the user.

required
role str

The new role to assign (options: admin, member, contributor, viewer).

'Admin'
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The updated role assignment details if successful, otherwise None.

Raises:

Type Description
ResourceNotFoundError

If the specified workspace or user is not found.

OptionNotAvailableError

If the role is invalid.

Examples:

```python update_workspace_role_assignment( '123e4567-e89b-12d3-a456-426614174000', 'FefEFewf-feF-1234-5678-9abcdef01234', role='Contributor' )

Source code in src/pyfabricops/core/workspaces.py
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
@df
def update_workspace_role_assignment(
    workspace: str,
    user_uuid: str,
    role: Literal['Admin', 'Contributor', 'Member', 'Viewer'] = 'Admin',
    *,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Update a role to a existing workspace role assignment.

    Args:
        workspace (str): The ID or name of the workspace.
        user_uuid (str): The UUID of the user.
        role (str): The new role to assign (options: admin, member, contributor, viewer).
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The updated role assignment details if successful, otherwise None.

    Raises:
        ResourceNotFoundError: If the specified workspace or user is not found.
        OptionNotAvailableError: If the role is invalid.

    Examples:
        ```python
        update_workspace_role_assignment(
            '123e4567-e89b-12d3-a456-426614174000',
            'FefEFewf-feF-1234-5678-9abcdef01234',
            role='Contributor'
        )
    """
    if role not in ['Admin', 'Contributor', 'Member', 'Viewer']:
        raise OptionNotAvailableError(
            f'Invalid role: {role}. Must be one of: Admin, Contributor, Member, Viewer'
        )

    payload = {'role': role}

    workspace_id = resolve_workspace(workspace)

    return api_request(
        '/workspaces/' + workspace_id + '/roleAssignments/' + user_uuid,
        payload=payload,
        method='patch',
    )