fabric-pbi 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,167 @@
1
+ """
2
+ Workspace Client for Microsoft Fabric
3
+ Provides operations for managing Workspaces.
4
+ """
5
+
6
+ from typing import Optional, Dict, Any, List
7
+ from ..auth import BaseClient
8
+
9
+
10
+ class WorkspaceClient(BaseClient):
11
+ """
12
+ Client for interacting with Fabric Workspace APIs
13
+
14
+ Reference: https://learn.microsoft.com/en-us/rest/api/fabric/core/workspaces
15
+ """
16
+
17
+ def list_workspaces(
18
+ self,
19
+ continuation_token: Optional[str] = None
20
+ ) -> Dict[str, Any]:
21
+ """
22
+ List all workspaces
23
+
24
+ Reference: https://learn.microsoft.com/en-us/rest/api/fabric/core/workspaces/list-workspaces
25
+
26
+ Args:
27
+ continuation_token: Optional token for pagination
28
+
29
+ Returns:
30
+ Dictionary with workspace list
31
+ """
32
+ endpoint = "workspaces"
33
+ params = {}
34
+
35
+ if continuation_token:
36
+ params["continuationToken"] = continuation_token
37
+
38
+ response = self._make_request("GET", endpoint, params=params)
39
+ return response.json()
40
+
41
+ def get_workspace(
42
+ self,
43
+ workspace_id: str
44
+ ) -> Dict[str, Any]:
45
+ """
46
+ Get a workspace by ID
47
+
48
+ Reference: https://learn.microsoft.com/en-us/rest/api/fabric/core/workspaces/get-workspace
49
+
50
+ Args:
51
+ workspace_id: The workspace ID
52
+
53
+ Returns:
54
+ Workspace details
55
+ """
56
+ endpoint = f"workspaces/{workspace_id}"
57
+ response = self._make_request("GET", endpoint)
58
+ return response.json()
59
+
60
+ def create_workspace(
61
+ self,
62
+ display_name: str,
63
+ description: Optional[str] = None,
64
+ capacity_id: Optional[str] = None
65
+ ) -> Dict[str, Any]:
66
+ """
67
+ Create a new workspace
68
+
69
+ Reference: https://learn.microsoft.com/en-us/rest/api/fabric/core/workspaces/create-workspace
70
+
71
+ Args:
72
+ display_name: Display name for the workspace
73
+ description: Optional description
74
+ capacity_id: Optional capacity ID
75
+
76
+ Returns:
77
+ Created workspace details
78
+ """
79
+ endpoint = "workspaces"
80
+
81
+ payload = {
82
+ "displayName": display_name
83
+ }
84
+
85
+ if description:
86
+ payload["description"] = description
87
+ if capacity_id:
88
+ payload["capacityId"] = capacity_id
89
+
90
+ response = self._make_request("POST", endpoint, data=payload)
91
+ return response.json()
92
+
93
+ def update_workspace(
94
+ self,
95
+ workspace_id: str,
96
+ display_name: Optional[str] = None,
97
+ description: Optional[str] = None
98
+ ) -> Dict[str, Any]:
99
+ """
100
+ Update a workspace
101
+
102
+ Reference: https://learn.microsoft.com/en-us/rest/api/fabric/core/workspaces/update-workspace
103
+
104
+ Args:
105
+ workspace_id: The workspace ID
106
+ display_name: New display name
107
+ description: New description
108
+
109
+ Returns:
110
+ Updated workspace details
111
+ """
112
+ endpoint = f"workspaces/{workspace_id}"
113
+
114
+ payload = {}
115
+ if display_name:
116
+ payload["displayName"] = display_name
117
+ if description:
118
+ payload["description"] = description
119
+
120
+ response = self._make_request("PATCH", endpoint, data=payload)
121
+ return response.json()
122
+
123
+ def delete_workspace(
124
+ self,
125
+ workspace_id: str
126
+ ) -> None:
127
+ """
128
+ Delete a workspace
129
+
130
+ Reference: https://learn.microsoft.com/en-us/rest/api/fabric/core/workspaces/delete-workspace
131
+
132
+ Args:
133
+ workspace_id: The workspace ID to delete
134
+
135
+ Returns:
136
+ None (204 No Content on success)
137
+ """
138
+ endpoint = f"workspaces/{workspace_id}"
139
+ self._make_request("DELETE", endpoint)
140
+
141
+ def get_all_workspaces(self) -> List[Dict[str, Any]]:
142
+ """
143
+ Get all workspaces with automatic pagination
144
+
145
+ Returns:
146
+ List of all workspaces
147
+ """
148
+ all_workspaces = []
149
+ continuation_token = None
150
+
151
+ print("Fetching all workspaces...")
152
+
153
+ while True:
154
+ result = self.list_workspaces(continuation_token=continuation_token)
155
+ workspaces = result.get("value", [])
156
+ all_workspaces.extend(workspaces)
157
+
158
+ print(f" Retrieved {len(workspaces)} workspaces (Total: {len(all_workspaces)})")
159
+
160
+ # Check if there are more pages
161
+ continuation_token = result.get("continuationToken")
162
+ if not continuation_token:
163
+ break
164
+
165
+ print(f"✓ Total workspaces found: {len(all_workspaces)}\n")
166
+ return all_workspaces
167
+