fabric-api 1.0.0__tar.gz
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.
- fabric_api-1.0.0/PKG-INFO +231 -0
- fabric_api-1.0.0/README.md +202 -0
- fabric_api-1.0.0/powerbi_api/__init__.py +12 -0
- fabric_api-1.0.0/powerbi_api/admin.py +42 -0
- fabric_api-1.0.0/powerbi_api/auth.py +75 -0
- fabric_api-1.0.0/powerbi_api/capacity.py +186 -0
- fabric_api-1.0.0/powerbi_api/dataflow.py +390 -0
- fabric_api-1.0.0/powerbi_api/dataset.py +501 -0
- fabric_api-1.0.0/powerbi_api/kql.py +66 -0
- fabric_api-1.0.0/powerbi_api/lakehouse.py +59 -0
- fabric_api-1.0.0/powerbi_api/operations.py +108 -0
- fabric_api-1.0.0/powerbi_api/report.py +909 -0
- fabric_api-1.0.0/powerbi_api/utilities.py +12 -0
- fabric_api-1.0.0/powerbi_api/workspace.py +556 -0
- fabric_api-1.0.0/pyproject.toml +31 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fabric-api
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Power BI and Fabric REST API wrapper for automating operations
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Bernardo Rufino
|
|
7
|
+
Author-email: contact@bernardorufino.com
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Requires-Dist: Office365-REST-Python-Client (==2.4.1)
|
|
17
|
+
Requires-Dist: azure-identity (>=1.24.0,<2)
|
|
18
|
+
Requires-Dist: azure-kusto-data (>=6.0.1,<7.0.0)
|
|
19
|
+
Requires-Dist: ipykernel
|
|
20
|
+
Requires-Dist: numpy (==2.1.3)
|
|
21
|
+
Requires-Dist: openpyxl (==3.1.5)
|
|
22
|
+
Requires-Dist: pandas (==2.2.3)
|
|
23
|
+
Requires-Dist: pyodbc (==5.2.0)
|
|
24
|
+
Requires-Dist: python-dotenv (==1.0.1)
|
|
25
|
+
Requires-Dist: pyyaml (>=6.0.3,<7.0.0)
|
|
26
|
+
Requires-Dist: sqlalchemy (==2.0.44)
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# Power BI & Fabric API Wrapper
|
|
30
|
+
|
|
31
|
+
Python wrapper for the Power BI REST API and Microsoft Fabric API, designed to automate workspace management, dataset operations, report handling, dataflows, and more.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
This is a **private package**. You must be granted access to the repository before installing.
|
|
36
|
+
|
|
37
|
+
### Install from GitHub (recommended)
|
|
38
|
+
|
|
39
|
+
```shell
|
|
40
|
+
pip install git+https://github.com/Bernardo-Rufino/powerbi-api.git
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
To install a specific version/tag:
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
pip install git+https://github.com/Bernardo-Rufino/powerbi-api.git@v1.0.0
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
If the repo is private, authenticate using a [Personal Access Token (PAT)](https://github.com/settings/tokens):
|
|
50
|
+
|
|
51
|
+
```shell
|
|
52
|
+
pip install git+https://ghp_YOUR_TOKEN@github.com/Bernardo-Rufino/powerbi-api.git
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Install for local development
|
|
56
|
+
|
|
57
|
+
```shell
|
|
58
|
+
git clone https://github.com/Bernardo-Rufino/powerbi-api.git
|
|
59
|
+
cd powerbi-api
|
|
60
|
+
pip install -e .
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Granting access to others
|
|
64
|
+
|
|
65
|
+
1. Go to the repository on GitHub
|
|
66
|
+
2. **Settings → Collaborators → Add people**
|
|
67
|
+
3. The invited user installs the package using their own PAT (as shown above)
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Prerequisites
|
|
72
|
+
|
|
73
|
+
- Python >= 3.10
|
|
74
|
+
- An Azure app registration with a client ID and client secret
|
|
75
|
+
|
|
76
|
+
## Setting Up
|
|
77
|
+
|
|
78
|
+
1. **Install the package** (see above)
|
|
79
|
+
|
|
80
|
+
2. **Set up credentials** — choose one of the two options:
|
|
81
|
+
|
|
82
|
+
**Option A – `.env` file** (local development): copy the example and fill in your values:
|
|
83
|
+
|
|
84
|
+
```shell
|
|
85
|
+
cp utils/.env.example utils/.env
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Then edit `utils/.env`:
|
|
89
|
+
|
|
90
|
+
```shell
|
|
91
|
+
TENANT_ID='<YOUR_TENANT_ID>'
|
|
92
|
+
CLIENT_ID='<YOUR_CLIENT_ID>'
|
|
93
|
+
CLIENT_SECRET='<YOUR_CLIENT_SECRET>'
|
|
94
|
+
CLIENT_ID_SHAREPOINT='<YOUR_SHAREPOINT_CLIENT_ID>'
|
|
95
|
+
CLIENT_SECRET_SHAREPOINT='<YOUR_SHAREPOINT_CLIENT_SECRET>'
|
|
96
|
+
AZURE_SUBSCRIPTION_ID='<YOUR_AZURE_SUBSCRIPTION_ID>'
|
|
97
|
+
AZURE_RESOURCE_GROUP_ID='<YOUR_AZURE_RESOURCE_GROUP_ID>'
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Option B – environment variables** (CI/CD, Docker, etc.): if the variables are already set in the environment, the `.env` file is skipped automatically — no extra setup needed.
|
|
101
|
+
|
|
102
|
+
3. **Authenticate**:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from powerbi_api import Auth
|
|
106
|
+
|
|
107
|
+
auth = Auth(TENANT_ID, CLIENT_ID, CLIENT_SECRET)
|
|
108
|
+
token = auth.get_token() # Power BI API
|
|
109
|
+
fabric_token = auth.get_token('fabric') # Fabric API
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Modules
|
|
113
|
+
|
|
114
|
+
### Auth
|
|
115
|
+
|
|
116
|
+
Authentication via Azure service principal or interactive user login.
|
|
117
|
+
|
|
118
|
+
| Method | Description |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `get_token(service='pbi')` | Get a bearer token for Power BI (`pbi`) or Fabric (`fabric`) APIs using a service principal. |
|
|
121
|
+
| `get_token_for_user(service='pbi')` | Get a bearer token via interactive user login. Supports `pbi`, `fabric`, and `azure` services. |
|
|
122
|
+
|
|
123
|
+
### Workspace
|
|
124
|
+
|
|
125
|
+
Manage Power BI workspaces, users, and permissions.
|
|
126
|
+
|
|
127
|
+
| Method | Description |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `list_workspaces(...)` | List all workspaces the user has access to, with optional filters. |
|
|
130
|
+
| `get_workspace_details(workspace_id)` | Get details for a specific workspace. |
|
|
131
|
+
| `list_users(workspace_id)` | List all users in a workspace. |
|
|
132
|
+
| `list_reports(workspace_id)` | List all reports in a workspace. |
|
|
133
|
+
| `add_user(user_principal_name, workspace_id, access_right, user_type)` | Add a user or service principal to a workspace. |
|
|
134
|
+
| `update_user(user_principal_name, workspace_id, access_right)` | Update a user's role on a workspace. |
|
|
135
|
+
| `remove_user(user_principal_name, workspace_id)` | Remove a user from a workspace. |
|
|
136
|
+
| `batch_update_user(user, workspaces_list)` | Batch update a user across multiple workspaces. |
|
|
137
|
+
|
|
138
|
+
### Dataset
|
|
139
|
+
|
|
140
|
+
Manage datasets, permissions, and execute DAX queries.
|
|
141
|
+
|
|
142
|
+
| Method | Description |
|
|
143
|
+
|---|---|
|
|
144
|
+
| `list_datasets(workspace_id)` | List all datasets in a workspace. |
|
|
145
|
+
| `get_dataset_details(workspace_id, dataset_id)` | Get details of a specific dataset. |
|
|
146
|
+
| `execute_query(workspace_id, dataset_id, query)` | Execute a DAX query against a dataset. |
|
|
147
|
+
| `list_users(workspace_id, dataset_id)` | List users with access to a dataset. |
|
|
148
|
+
| `add_user(user_principal_name, workspace_id, dataset_id, access_right)` | Grant a user access to a dataset. |
|
|
149
|
+
| `update_user(user_principal_name, workspace_id, dataset_id, access_right)` | Update a user's access to a dataset. |
|
|
150
|
+
| `remove_user(user_principal_name, workspace_id, dataset_id)` | Remove a user's access to a dataset. |
|
|
151
|
+
| `list_dataset_related_reports(workspace_id, dataset_id)` | List all reports linked to a dataset. |
|
|
152
|
+
| `export_dataset_related_reports(workspace_id, dataset_id)` | Export all reports linked to a dataset as `.pbix` files. |
|
|
153
|
+
|
|
154
|
+
### Report
|
|
155
|
+
|
|
156
|
+
Retrieve report metadata, definitions, visuals, and report-level measures.
|
|
157
|
+
|
|
158
|
+
| Method | Description |
|
|
159
|
+
|---|---|
|
|
160
|
+
| `list_reports(workspace_id)` | List all reports in a workspace. |
|
|
161
|
+
| `get_report_metadata(workspace_id, report_id)` | Get metadata for a specific report. |
|
|
162
|
+
| `get_report_name(workspace_id, report_id)` | Get a report's display name. |
|
|
163
|
+
| `list_report_pages(workspace_id, report_id)` | List all pages in a report. |
|
|
164
|
+
| `get_report_json_pages_and_visuals(json_data, workspace_id, report_id)` | Parse a PBIR-Legacy report JSON and extract pages and visual details into a DataFrame. |
|
|
165
|
+
| `get_legacy_report_json(workspace_id, report_id, operations)` | Get and decode the full report definition for PBIR-Legacy reports. |
|
|
166
|
+
| `export_report(workspace_id, report_id, ...)` | Export a report as a `.pbix` file. |
|
|
167
|
+
| `get_report_measures(workspace_id, report_id, operations)` | Extract report-level measures and generate a DAX Query View script. Supports both PBIR and PBIR-Legacy formats. |
|
|
168
|
+
|
|
169
|
+
### Dataflow
|
|
170
|
+
|
|
171
|
+
Manage Power BI and Fabric dataflows, including Gen2.
|
|
172
|
+
|
|
173
|
+
| Method | Description |
|
|
174
|
+
|---|---|
|
|
175
|
+
| `list_dataflows(workspace_id, type='pbi')` | List dataflows in a workspace. Use `type='fabric'` for Fabric API. |
|
|
176
|
+
| `get_dataflow_details(workspace_id, dataflow_id)` | Get details of a specific dataflow. |
|
|
177
|
+
| `create_dataflow(workspace_id, dataflow_content)` | Create a new Power BI dataflow. |
|
|
178
|
+
| `delete_dataflow(workspace_id, dataflow_id, type='pbi')` | Delete a dataflow. Use `type='fabric'` for Fabric API. |
|
|
179
|
+
| `export_dataflow_json(workspace_id, dataflow_id, dataflow_name)` | Export a dataflow definition as JSON. |
|
|
180
|
+
| `get_dataflow_gen2_definition(workspace_id, dataflow_id)` | Get the definition of a Dataflow Gen2. |
|
|
181
|
+
| `create_dataflow_gen2_from_definition(workspace_id, display_name, definition)` | Create a Dataflow Gen2 from a definition. |
|
|
182
|
+
| `update_dataflow_gen2_from_definition(workspace_id, dataflow_id, display_name, definition)` | Update an existing Dataflow Gen2. |
|
|
183
|
+
|
|
184
|
+
### Capacity
|
|
185
|
+
|
|
186
|
+
Monitor and manage Power BI and Fabric capacities.
|
|
187
|
+
|
|
188
|
+
| Method | Description |
|
|
189
|
+
|---|---|
|
|
190
|
+
| `list_powerbi_capacities()` | List all Power BI capacities the user has access to. |
|
|
191
|
+
| `list_fabric_capacities(azure_subscription_id, azure_resource_group)` | List Fabric capacities for a given Azure subscription. |
|
|
192
|
+
| `assign_workspace_to_capacity(workspace_id, capacity_id)` | Assign a workspace to a capacity. |
|
|
193
|
+
|
|
194
|
+
### Operations
|
|
195
|
+
|
|
196
|
+
Track long-running Fabric API operations.
|
|
197
|
+
|
|
198
|
+
| Method | Description |
|
|
199
|
+
|---|---|
|
|
200
|
+
| `get_operation_state(operation_id)` | Get the current state of a long-running operation. |
|
|
201
|
+
| `get_operation_result(operation_id)` | Get the result of a completed operation. |
|
|
202
|
+
|
|
203
|
+
### Admin
|
|
204
|
+
|
|
205
|
+
Power BI Admin API operations.
|
|
206
|
+
|
|
207
|
+
| Method | Description |
|
|
208
|
+
|---|---|
|
|
209
|
+
| `get_report_users_as_admin(report_id)` | List users with access to a report (admin endpoint). |
|
|
210
|
+
|
|
211
|
+
### KQLDatabase
|
|
212
|
+
|
|
213
|
+
Query Kusto (KQL) databases in Microsoft Fabric.
|
|
214
|
+
|
|
215
|
+
| Method | Description |
|
|
216
|
+
|---|---|
|
|
217
|
+
| `query_kql_database(kql_query, sort_by)` | Execute a KQL query and return results as a DataFrame. |
|
|
218
|
+
|
|
219
|
+
### Lakehouse
|
|
220
|
+
|
|
221
|
+
Query SQL databases (Lakehouse) via ODBC.
|
|
222
|
+
|
|
223
|
+
| Method | Description |
|
|
224
|
+
|---|---|
|
|
225
|
+
| `execute_query(query)` | Execute a SQL query against a lakehouse database. |
|
|
226
|
+
|
|
227
|
+
## Limitations
|
|
228
|
+
|
|
229
|
+
- The Power BI REST API has a **200 requests per hour** rate limit.
|
|
230
|
+
- Not all users can be updated via the API. See Microsoft docs: [Dataset permissions](https://learn.microsoft.com/en-us/power-bi/developer/embedded/datasets-permissions#get-and-update-dataset-permissions-with-apis).
|
|
231
|
+
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# Power BI & Fabric API Wrapper
|
|
2
|
+
|
|
3
|
+
Python wrapper for the Power BI REST API and Microsoft Fabric API, designed to automate workspace management, dataset operations, report handling, dataflows, and more.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
This is a **private package**. You must be granted access to the repository before installing.
|
|
8
|
+
|
|
9
|
+
### Install from GitHub (recommended)
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
pip install git+https://github.com/Bernardo-Rufino/powerbi-api.git
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
To install a specific version/tag:
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
pip install git+https://github.com/Bernardo-Rufino/powerbi-api.git@v1.0.0
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
If the repo is private, authenticate using a [Personal Access Token (PAT)](https://github.com/settings/tokens):
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
pip install git+https://ghp_YOUR_TOKEN@github.com/Bernardo-Rufino/powerbi-api.git
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Install for local development
|
|
28
|
+
|
|
29
|
+
```shell
|
|
30
|
+
git clone https://github.com/Bernardo-Rufino/powerbi-api.git
|
|
31
|
+
cd powerbi-api
|
|
32
|
+
pip install -e .
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Granting access to others
|
|
36
|
+
|
|
37
|
+
1. Go to the repository on GitHub
|
|
38
|
+
2. **Settings → Collaborators → Add people**
|
|
39
|
+
3. The invited user installs the package using their own PAT (as shown above)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Prerequisites
|
|
44
|
+
|
|
45
|
+
- Python >= 3.10
|
|
46
|
+
- An Azure app registration with a client ID and client secret
|
|
47
|
+
|
|
48
|
+
## Setting Up
|
|
49
|
+
|
|
50
|
+
1. **Install the package** (see above)
|
|
51
|
+
|
|
52
|
+
2. **Set up credentials** — choose one of the two options:
|
|
53
|
+
|
|
54
|
+
**Option A – `.env` file** (local development): copy the example and fill in your values:
|
|
55
|
+
|
|
56
|
+
```shell
|
|
57
|
+
cp utils/.env.example utils/.env
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Then edit `utils/.env`:
|
|
61
|
+
|
|
62
|
+
```shell
|
|
63
|
+
TENANT_ID='<YOUR_TENANT_ID>'
|
|
64
|
+
CLIENT_ID='<YOUR_CLIENT_ID>'
|
|
65
|
+
CLIENT_SECRET='<YOUR_CLIENT_SECRET>'
|
|
66
|
+
CLIENT_ID_SHAREPOINT='<YOUR_SHAREPOINT_CLIENT_ID>'
|
|
67
|
+
CLIENT_SECRET_SHAREPOINT='<YOUR_SHAREPOINT_CLIENT_SECRET>'
|
|
68
|
+
AZURE_SUBSCRIPTION_ID='<YOUR_AZURE_SUBSCRIPTION_ID>'
|
|
69
|
+
AZURE_RESOURCE_GROUP_ID='<YOUR_AZURE_RESOURCE_GROUP_ID>'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Option B – environment variables** (CI/CD, Docker, etc.): if the variables are already set in the environment, the `.env` file is skipped automatically — no extra setup needed.
|
|
73
|
+
|
|
74
|
+
3. **Authenticate**:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from powerbi_api import Auth
|
|
78
|
+
|
|
79
|
+
auth = Auth(TENANT_ID, CLIENT_ID, CLIENT_SECRET)
|
|
80
|
+
token = auth.get_token() # Power BI API
|
|
81
|
+
fabric_token = auth.get_token('fabric') # Fabric API
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Modules
|
|
85
|
+
|
|
86
|
+
### Auth
|
|
87
|
+
|
|
88
|
+
Authentication via Azure service principal or interactive user login.
|
|
89
|
+
|
|
90
|
+
| Method | Description |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `get_token(service='pbi')` | Get a bearer token for Power BI (`pbi`) or Fabric (`fabric`) APIs using a service principal. |
|
|
93
|
+
| `get_token_for_user(service='pbi')` | Get a bearer token via interactive user login. Supports `pbi`, `fabric`, and `azure` services. |
|
|
94
|
+
|
|
95
|
+
### Workspace
|
|
96
|
+
|
|
97
|
+
Manage Power BI workspaces, users, and permissions.
|
|
98
|
+
|
|
99
|
+
| Method | Description |
|
|
100
|
+
|---|---|
|
|
101
|
+
| `list_workspaces(...)` | List all workspaces the user has access to, with optional filters. |
|
|
102
|
+
| `get_workspace_details(workspace_id)` | Get details for a specific workspace. |
|
|
103
|
+
| `list_users(workspace_id)` | List all users in a workspace. |
|
|
104
|
+
| `list_reports(workspace_id)` | List all reports in a workspace. |
|
|
105
|
+
| `add_user(user_principal_name, workspace_id, access_right, user_type)` | Add a user or service principal to a workspace. |
|
|
106
|
+
| `update_user(user_principal_name, workspace_id, access_right)` | Update a user's role on a workspace. |
|
|
107
|
+
| `remove_user(user_principal_name, workspace_id)` | Remove a user from a workspace. |
|
|
108
|
+
| `batch_update_user(user, workspaces_list)` | Batch update a user across multiple workspaces. |
|
|
109
|
+
|
|
110
|
+
### Dataset
|
|
111
|
+
|
|
112
|
+
Manage datasets, permissions, and execute DAX queries.
|
|
113
|
+
|
|
114
|
+
| Method | Description |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `list_datasets(workspace_id)` | List all datasets in a workspace. |
|
|
117
|
+
| `get_dataset_details(workspace_id, dataset_id)` | Get details of a specific dataset. |
|
|
118
|
+
| `execute_query(workspace_id, dataset_id, query)` | Execute a DAX query against a dataset. |
|
|
119
|
+
| `list_users(workspace_id, dataset_id)` | List users with access to a dataset. |
|
|
120
|
+
| `add_user(user_principal_name, workspace_id, dataset_id, access_right)` | Grant a user access to a dataset. |
|
|
121
|
+
| `update_user(user_principal_name, workspace_id, dataset_id, access_right)` | Update a user's access to a dataset. |
|
|
122
|
+
| `remove_user(user_principal_name, workspace_id, dataset_id)` | Remove a user's access to a dataset. |
|
|
123
|
+
| `list_dataset_related_reports(workspace_id, dataset_id)` | List all reports linked to a dataset. |
|
|
124
|
+
| `export_dataset_related_reports(workspace_id, dataset_id)` | Export all reports linked to a dataset as `.pbix` files. |
|
|
125
|
+
|
|
126
|
+
### Report
|
|
127
|
+
|
|
128
|
+
Retrieve report metadata, definitions, visuals, and report-level measures.
|
|
129
|
+
|
|
130
|
+
| Method | Description |
|
|
131
|
+
|---|---|
|
|
132
|
+
| `list_reports(workspace_id)` | List all reports in a workspace. |
|
|
133
|
+
| `get_report_metadata(workspace_id, report_id)` | Get metadata for a specific report. |
|
|
134
|
+
| `get_report_name(workspace_id, report_id)` | Get a report's display name. |
|
|
135
|
+
| `list_report_pages(workspace_id, report_id)` | List all pages in a report. |
|
|
136
|
+
| `get_report_json_pages_and_visuals(json_data, workspace_id, report_id)` | Parse a PBIR-Legacy report JSON and extract pages and visual details into a DataFrame. |
|
|
137
|
+
| `get_legacy_report_json(workspace_id, report_id, operations)` | Get and decode the full report definition for PBIR-Legacy reports. |
|
|
138
|
+
| `export_report(workspace_id, report_id, ...)` | Export a report as a `.pbix` file. |
|
|
139
|
+
| `get_report_measures(workspace_id, report_id, operations)` | Extract report-level measures and generate a DAX Query View script. Supports both PBIR and PBIR-Legacy formats. |
|
|
140
|
+
|
|
141
|
+
### Dataflow
|
|
142
|
+
|
|
143
|
+
Manage Power BI and Fabric dataflows, including Gen2.
|
|
144
|
+
|
|
145
|
+
| Method | Description |
|
|
146
|
+
|---|---|
|
|
147
|
+
| `list_dataflows(workspace_id, type='pbi')` | List dataflows in a workspace. Use `type='fabric'` for Fabric API. |
|
|
148
|
+
| `get_dataflow_details(workspace_id, dataflow_id)` | Get details of a specific dataflow. |
|
|
149
|
+
| `create_dataflow(workspace_id, dataflow_content)` | Create a new Power BI dataflow. |
|
|
150
|
+
| `delete_dataflow(workspace_id, dataflow_id, type='pbi')` | Delete a dataflow. Use `type='fabric'` for Fabric API. |
|
|
151
|
+
| `export_dataflow_json(workspace_id, dataflow_id, dataflow_name)` | Export a dataflow definition as JSON. |
|
|
152
|
+
| `get_dataflow_gen2_definition(workspace_id, dataflow_id)` | Get the definition of a Dataflow Gen2. |
|
|
153
|
+
| `create_dataflow_gen2_from_definition(workspace_id, display_name, definition)` | Create a Dataflow Gen2 from a definition. |
|
|
154
|
+
| `update_dataflow_gen2_from_definition(workspace_id, dataflow_id, display_name, definition)` | Update an existing Dataflow Gen2. |
|
|
155
|
+
|
|
156
|
+
### Capacity
|
|
157
|
+
|
|
158
|
+
Monitor and manage Power BI and Fabric capacities.
|
|
159
|
+
|
|
160
|
+
| Method | Description |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `list_powerbi_capacities()` | List all Power BI capacities the user has access to. |
|
|
163
|
+
| `list_fabric_capacities(azure_subscription_id, azure_resource_group)` | List Fabric capacities for a given Azure subscription. |
|
|
164
|
+
| `assign_workspace_to_capacity(workspace_id, capacity_id)` | Assign a workspace to a capacity. |
|
|
165
|
+
|
|
166
|
+
### Operations
|
|
167
|
+
|
|
168
|
+
Track long-running Fabric API operations.
|
|
169
|
+
|
|
170
|
+
| Method | Description |
|
|
171
|
+
|---|---|
|
|
172
|
+
| `get_operation_state(operation_id)` | Get the current state of a long-running operation. |
|
|
173
|
+
| `get_operation_result(operation_id)` | Get the result of a completed operation. |
|
|
174
|
+
|
|
175
|
+
### Admin
|
|
176
|
+
|
|
177
|
+
Power BI Admin API operations.
|
|
178
|
+
|
|
179
|
+
| Method | Description |
|
|
180
|
+
|---|---|
|
|
181
|
+
| `get_report_users_as_admin(report_id)` | List users with access to a report (admin endpoint). |
|
|
182
|
+
|
|
183
|
+
### KQLDatabase
|
|
184
|
+
|
|
185
|
+
Query Kusto (KQL) databases in Microsoft Fabric.
|
|
186
|
+
|
|
187
|
+
| Method | Description |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `query_kql_database(kql_query, sort_by)` | Execute a KQL query and return results as a DataFrame. |
|
|
190
|
+
|
|
191
|
+
### Lakehouse
|
|
192
|
+
|
|
193
|
+
Query SQL databases (Lakehouse) via ODBC.
|
|
194
|
+
|
|
195
|
+
| Method | Description |
|
|
196
|
+
|---|---|
|
|
197
|
+
| `execute_query(query)` | Execute a SQL query against a lakehouse database. |
|
|
198
|
+
|
|
199
|
+
## Limitations
|
|
200
|
+
|
|
201
|
+
- The Power BI REST API has a **200 requests per hour** rate limit.
|
|
202
|
+
- Not all users can be updated via the API. See Microsoft docs: [Dataset permissions](https://learn.microsoft.com/en-us/power-bi/developer/embedded/datasets-permissions#get-and-update-dataset-permissions-with-apis).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from .auth import Auth
|
|
2
|
+
from .workspace import Workspace
|
|
3
|
+
from .dataset import Dataset
|
|
4
|
+
from .report import Report
|
|
5
|
+
from .dataflow import Dataflow
|
|
6
|
+
from .capacity import Capacity
|
|
7
|
+
from .admin import Admin
|
|
8
|
+
from .operations import Operations
|
|
9
|
+
from .kql import KQLDatabase
|
|
10
|
+
from .lakehouse import Lakehouse
|
|
11
|
+
|
|
12
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import json
|
|
3
|
+
from typing import Dict
|
|
4
|
+
|
|
5
|
+
class Admin:
|
|
6
|
+
|
|
7
|
+
def __init__(self, token: str):
|
|
8
|
+
"""
|
|
9
|
+
Initialize variables for Power BI Admin API interactions.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
token (str): The bearer token for authorization.
|
|
13
|
+
"""
|
|
14
|
+
self.main_url = 'https://api.powerbi.com/v1.0/myorg/admin'
|
|
15
|
+
self.token = token
|
|
16
|
+
self.headers = {'Authorization': f'Bearer {self.token}'}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_report_users_as_admin(self, report_id: str) -> Dict:
|
|
20
|
+
"""
|
|
21
|
+
Retrieves a list of users with access to a specific report as an administrator.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
report_id (str): The ID of the report to get users for.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
Dict: A dictionary containing the status message and content (list of users).
|
|
28
|
+
"""
|
|
29
|
+
request_url = f'{self.main_url}/reports/{report_id}/users'
|
|
30
|
+
|
|
31
|
+
r = requests.get(url=request_url, headers=self.headers)
|
|
32
|
+
|
|
33
|
+
status = r.status_code
|
|
34
|
+
response = json.loads(r.content)
|
|
35
|
+
|
|
36
|
+
if status == 200:
|
|
37
|
+
return {'message': 'Success', 'content': response.get('value', [])}
|
|
38
|
+
else:
|
|
39
|
+
error_message = response.get('error', {}).get('message', 'Unknown error')
|
|
40
|
+
return {'message': {'error': error_message, 'status_code': status}, 'content': ''}
|
|
41
|
+
|
|
42
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from azure.identity import ClientSecretCredential, InteractiveBrowserCredential, TokenCachePersistenceOptions
|
|
2
|
+
|
|
3
|
+
class Auth:
|
|
4
|
+
|
|
5
|
+
def __init__(self, tenant_id: str, client_id: str, client_secret: str):
|
|
6
|
+
"""
|
|
7
|
+
Initialize variables.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
tenant_id (str, optional): tenant ID.
|
|
11
|
+
client_id (str, optional): client ID (app registration).
|
|
12
|
+
client_secret (str, optional): client secret/credentials (app registration).
|
|
13
|
+
"""
|
|
14
|
+
self.tenant_id = tenant_id
|
|
15
|
+
self.client_id = client_id
|
|
16
|
+
self.client_secret = client_secret
|
|
17
|
+
|
|
18
|
+
def get_token(self, service: str = 'pbi') -> str:
|
|
19
|
+
"""
|
|
20
|
+
Generates the bearer token to be used on Power BI or Fabric REST API requests.
|
|
21
|
+
|
|
22
|
+
Authenticates using a service principal (app account).
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
service (str, optional): which service to get token to: pbi or fabric.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
str: token for authorization.
|
|
29
|
+
"""
|
|
30
|
+
if service == 'pbi':
|
|
31
|
+
scope = 'https://analysis.windows.net/powerbi/api/.default'
|
|
32
|
+
elif service == 'fabric':
|
|
33
|
+
scope = 'https://api.fabric.microsoft.com/.default'
|
|
34
|
+
else:
|
|
35
|
+
raise ValueError("Invalid service specified. Choose 'pbi' or 'fabric'.")
|
|
36
|
+
|
|
37
|
+
auth = ClientSecretCredential(
|
|
38
|
+
authority = 'https://login.microsoftonline.com/',
|
|
39
|
+
tenant_id = self.tenant_id,
|
|
40
|
+
client_id = self.client_id,
|
|
41
|
+
client_secret = self.client_secret)
|
|
42
|
+
|
|
43
|
+
response = auth.get_token(scope)
|
|
44
|
+
access_token = response.token
|
|
45
|
+
|
|
46
|
+
return access_token
|
|
47
|
+
|
|
48
|
+
def get_token_for_user(self, service: str = 'pbi') -> str:
|
|
49
|
+
"""
|
|
50
|
+
Generates the bearer token to be used on Microsoft REST API requests.
|
|
51
|
+
|
|
52
|
+
Authenticates interactively (user account).
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
service (str, optional): which service to get token to: pbi, fabric or azure.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
str: token for authorization.
|
|
59
|
+
"""
|
|
60
|
+
if service == 'pbi':
|
|
61
|
+
scope = 'https://analysis.windows.net/powerbi/api/.default'
|
|
62
|
+
elif service == 'fabric':
|
|
63
|
+
scope = 'https://api.fabric.microsoft.com/.default'
|
|
64
|
+
elif service == 'azure':
|
|
65
|
+
scope = 'https://management.azure.com/.default'
|
|
66
|
+
else:
|
|
67
|
+
raise ValueError("Invalid service specified. Choose 'pbi', 'fabric' or'azure'.")
|
|
68
|
+
|
|
69
|
+
auth = InteractiveBrowserCredential(cache_persistence_options=TokenCachePersistenceOptions())
|
|
70
|
+
|
|
71
|
+
response = auth.get_token(scope)
|
|
72
|
+
access_token = response.token
|
|
73
|
+
|
|
74
|
+
return access_token
|
|
75
|
+
|