msfabricpysdkcore 0.0.3__tar.gz → 0.0.5__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.
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/PKG-INFO +163 -15
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/README.md +163 -15
- msfabricpysdkcore-0.0.5/msfabricpysdkcore/__init__.py +2 -0
- msfabricpysdkcore-0.0.5/msfabricpysdkcore/admin_item.py +106 -0
- msfabricpysdkcore-0.0.5/msfabricpysdkcore/admin_workspace.py +127 -0
- msfabricpysdkcore-0.0.5/msfabricpysdkcore/adminapi.py +535 -0
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/capacity.py +3 -0
- msfabricpysdkcore-0.0.5/msfabricpysdkcore/client.py +22 -0
- msfabricpysdkcore-0.0.3/msfabricpysdkcore/client.py → msfabricpysdkcore-0.0.5/msfabricpysdkcore/coreapi.py +7 -19
- msfabricpysdkcore-0.0.5/msfabricpysdkcore/domain.py +378 -0
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/item.py +9 -4
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/job_instance.py +3 -1
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/lakehouse.py +0 -1
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/long_running_operation.py +6 -9
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/onelakeshortcut.py +3 -0
- msfabricpysdkcore-0.0.5/msfabricpysdkcore/otheritems.py +17 -0
- msfabricpysdkcore-0.0.5/msfabricpysdkcore/tests/test_admin_apis.py +69 -0
- msfabricpysdkcore-0.0.5/msfabricpysdkcore/tests/test_domains.py +125 -0
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/tests/test_git.py +1 -1
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/tests/test_items_incl_lakehouse.py +35 -1
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/tests/test_jobs.py +1 -3
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/tests/test_shortcuts.py +1 -1
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/tests/test_workspaces_capacities.py +1 -1
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/workspace.py +119 -17
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore.egg-info/PKG-INFO +163 -15
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore.egg-info/SOURCES.txt +8 -0
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/pyproject.toml +1 -1
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/setup.py +1 -1
- msfabricpysdkcore-0.0.3/msfabricpysdkcore/__init__.py +0 -1
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/LICENSE +0 -0
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/auth.py +0 -0
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore/tests/__init__.py +0 -0
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore.egg-info/dependency_links.txt +0 -0
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore.egg-info/requires.txt +0 -0
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/msfabricpysdkcore.egg-info/top_level.txt +0 -0
- {msfabricpysdkcore-0.0.3 → msfabricpysdkcore-0.0.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: msfabricpysdkcore
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.5
|
4
4
|
Summary: A Python SDK for Microsoft Fabric
|
5
5
|
Author: Andreas Rederer
|
6
6
|
Project-URL: Homepage, https://github.com/DaSenf1860/ms-fabric-sdk-core
|
@@ -13,7 +13,7 @@ License-File: LICENSE
|
|
13
13
|
Requires-Dist: requests>=2.30.0
|
14
14
|
Requires-Dist: azure-identity>=1.15.0
|
15
15
|
|
16
|
-
#
|
16
|
+
# Python SDK for Microsoft Fabric
|
17
17
|
|
18
18
|
This is a Python SDK for Microsoft Fabric. It is a wrapper around the REST APIs (v1) of Fabric*.
|
19
19
|
|
@@ -34,17 +34,26 @@ Additionally it brings some extra features like:
|
|
34
34
|
|
35
35
|
See the latest release notes [here](releasenotes/release_notes.md).
|
36
36
|
|
37
|
-
Currently it supports all Core APIs and Lakehouse APIs, i.e.:
|
38
|
-
-
|
39
|
-
- [
|
40
|
-
- [
|
41
|
-
- [
|
42
|
-
-
|
43
|
-
-
|
44
|
-
- [
|
45
|
-
- [
|
46
|
-
|
47
|
-
|
37
|
+
Currently it supports all Core APIs, Admin APIs and Lakehouse APIs, i.e.:
|
38
|
+
- Core APIs
|
39
|
+
- [Capacities](#working-with-capacities)
|
40
|
+
- [Git](#working-with-git)
|
41
|
+
- [Items](#working-with-items)
|
42
|
+
- [Job Scheduler](#working-with-job-scheduler)
|
43
|
+
- Long Running Operations
|
44
|
+
- [OneLakeShortcuts](#working-with-one-lake-shortcuts)
|
45
|
+
- [Workspaces](#working-with-workspaces)
|
46
|
+
- Lakehouse APIs
|
47
|
+
- [Tables](#tables)
|
48
|
+
- Admin APIs
|
49
|
+
- [Domains](#admin-api-for-domains)
|
50
|
+
- [Items](#admin-api-for-items)
|
51
|
+
- [Tenants](#admin-api-for-tenants)
|
52
|
+
- [Users](#admin-api-for-users)
|
53
|
+
- [Workspaces](#admin-api-for-workspaces)
|
54
|
+
|
55
|
+
It is planned to support also the APIs of the user experiences and new APIs which are not released yet.
|
56
|
+
Also we have plans to support APIs to interact with Fabric capacities on the Azure Side.
|
48
57
|
Eventually Power BI APIs like the Scanner API will be covered as well.
|
49
58
|
|
50
59
|
*Because this SDK uses the API in the background, all limitations and restrictions of the API apply to this SDK as well. This includes rate limits, permissions, etc.
|
@@ -366,11 +375,13 @@ item.cancel_item_job_instance(job_instance_id="job_instance_id")
|
|
366
375
|
|
367
376
|
```
|
368
377
|
|
369
|
-
|
378
|
+
### Tables
|
379
|
+
|
370
380
|
|
371
|
-
# List tables in a Lakehouse
|
372
381
|
|
373
382
|
```python
|
383
|
+
# List tables in a Lakehouse
|
384
|
+
|
374
385
|
from msfabricpysdkcore import FabricClientCore
|
375
386
|
|
376
387
|
fc = FabricClientCore()
|
@@ -395,5 +406,142 @@ fc.load_table(workspace_id = "someworkspaceid", item_id = "someitemid", table_na
|
|
395
406
|
|
396
407
|
```
|
397
408
|
|
409
|
+
### Admin API for Workspaces
|
410
|
+
|
411
|
+
```python
|
412
|
+
from msfabricpysdkcore import FabricClientAdmin
|
413
|
+
|
414
|
+
fca = FabricClientAdmin()
|
415
|
+
|
416
|
+
|
417
|
+
# List workspaces
|
418
|
+
ws = fca.list_workspaces(name="testworkspace")[0]
|
419
|
+
|
420
|
+
# Get workspace
|
421
|
+
ws = fca.get_workspace(workspace_id="workspace_id")
|
422
|
+
|
423
|
+
# Get workspace access details
|
424
|
+
|
425
|
+
ws_access = fca.get_workspace_access_details("workspace_id")
|
426
|
+
# or
|
427
|
+
ws_access = ws.get_access_details()
|
428
|
+
```
|
429
|
+
|
430
|
+
### Admin API for Users
|
431
|
+
|
432
|
+
```python
|
433
|
+
from msfabricpysdkcore import FabricClientAdmin
|
434
|
+
|
435
|
+
fca = FabricClientAdmin()
|
436
|
+
|
437
|
+
# Get access entities
|
438
|
+
|
439
|
+
user_id = 'b4fuhaidc2'
|
440
|
+
access_entities = fca.get_access_entities(user_id, type="Notebook")
|
441
|
+
|
442
|
+
```
|
443
|
+
|
444
|
+
### Admin API for Tenants
|
445
|
+
|
446
|
+
```python
|
447
|
+
from msfabricpysdkcore import FabricClientAdmin
|
448
|
+
|
449
|
+
fca = FabricClientAdmin()
|
450
|
+
|
451
|
+
# Get tenant settings
|
452
|
+
|
453
|
+
tenant_settings = fca.get_tenant_settings()
|
454
|
+
|
455
|
+
# Get capacity tenant settings overrides
|
456
|
+
|
457
|
+
overrides = fca.get_capacities_tenant_settings_overrides()
|
458
|
+
|
459
|
+
```
|
460
|
+
|
461
|
+
### Admin API for Items
|
462
|
+
|
463
|
+
```python
|
464
|
+
from msfabricpysdkcore import FabricClientAdmin
|
465
|
+
|
466
|
+
fca = FabricClientAdmin()
|
467
|
+
|
468
|
+
# List items
|
469
|
+
|
470
|
+
item_list = fca.list_items(workspace_id="wsid")
|
471
|
+
|
472
|
+
# Get item
|
473
|
+
|
474
|
+
item = fca.get_item(workspace_id="wsid", item_id=item_list[0].id)
|
475
|
+
# or
|
476
|
+
item = ws.get_item(item_id=item_list[0].id)
|
477
|
+
|
478
|
+
# Get item access details
|
479
|
+
|
480
|
+
item_access = fca.get_item_access_details(workspace_id="wsid", item_id=item_list[0].id)
|
481
|
+
#or
|
482
|
+
item_access = ws.get_item_access_details(item_id=item_list[0].id)
|
483
|
+
# or
|
484
|
+
item_access = item.get_access_details()
|
485
|
+
|
486
|
+
```
|
487
|
+
|
488
|
+
### Admin API for Domains
|
489
|
+
|
490
|
+
```python
|
491
|
+
from msfabricpysdkcore import FabricClientAdmin
|
492
|
+
|
493
|
+
fca = FabricClientAdmin()
|
494
|
+
|
495
|
+
# Create domain
|
496
|
+
domain_name = "sdktestdomains"
|
497
|
+
domain = fca.create_domain(display_name=domain_name)
|
498
|
+
|
499
|
+
# Get domain by name
|
500
|
+
domain_clone = fca.get_domain_by_name(domain_name)
|
501
|
+
|
502
|
+
# Get domain by id
|
503
|
+
domain_clone = fca.get_domain_by_id(domain.id)
|
504
|
+
|
505
|
+
# List domains
|
506
|
+
domains = fca.list_domains()
|
507
|
+
|
508
|
+
# Update domain
|
509
|
+
domain_new_name = "sdktestdomains2"
|
510
|
+
domain_clone = fca.update_domain(domain.id, display_name=domain_new_name)
|
511
|
+
|
512
|
+
# Assign domain workspaces by Ids
|
513
|
+
fca.assign_domain_workspaces_by_ids(domain.id, ["workspace_id_1", "workspace_id_2"])
|
514
|
+
|
515
|
+
# List domain workspaces
|
516
|
+
workspaces = fca.list_domain_workspaces(domain.id, workspace_objects=True)
|
517
|
+
|
518
|
+
# Unassign domain workspaces by ids
|
519
|
+
status_code = fca.unassign_domain_workspaces_by_ids(domain.id, ["workspace_id_1", "workspace_id_2"])
|
520
|
+
|
521
|
+
# Assign domain workspaces by capacities
|
522
|
+
status_code = fca.assign_domain_workspaces_by_capacities(domain.id, ["cap_id1", "cap_id2"])
|
523
|
+
|
524
|
+
# Unassign all domain workspaces
|
525
|
+
status_code = fca.unassign_all_domain_workspaces(domain.id)
|
526
|
+
|
527
|
+
# Assign domain workspaces by principals
|
528
|
+
principal1 = {'id': '6edbsdfbfdgdf656', 'type': 'User'}
|
529
|
+
principal2 = {'id': '6eyxcbyyxc57', 'type': 'User'}
|
530
|
+
|
531
|
+
status_code = fca.assign_domains_workspaces_by_principals(domain.id, [principal1, principal2], wait_for_completion=True)
|
532
|
+
|
533
|
+
# Role assignments bulk assign
|
534
|
+
|
535
|
+
principals = [principal, principal_2]
|
536
|
+
status_code = fca.role_assignments_bulk_assign(domain.id, "Contributors", principals)
|
537
|
+
|
538
|
+
# Role assignments bulk unassign
|
539
|
+
status_code = fca.role_assignments_bulk_unassign(domain.id, "Contributors", [principal_2])
|
540
|
+
|
541
|
+
# Delete domain
|
542
|
+
status_code = fca.delete_domain(domain.id)
|
543
|
+
```
|
544
|
+
|
545
|
+
|
398
546
|
Note: This SDK is not an official SDK from Microsoft. It is a community project and not supported by Microsoft. Use it at your own risk.
|
399
547
|
Also the API is still in preview and might change. This SDK is not yet feature complete and might not cover all APIs yet. Feel free to contribute to this project to make it better.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Python SDK for Microsoft Fabric
|
2
2
|
|
3
3
|
This is a Python SDK for Microsoft Fabric. It is a wrapper around the REST APIs (v1) of Fabric*.
|
4
4
|
|
@@ -19,17 +19,26 @@ Additionally it brings some extra features like:
|
|
19
19
|
|
20
20
|
See the latest release notes [here](releasenotes/release_notes.md).
|
21
21
|
|
22
|
-
Currently it supports all Core APIs and Lakehouse APIs, i.e.:
|
23
|
-
-
|
24
|
-
- [
|
25
|
-
- [
|
26
|
-
- [
|
27
|
-
-
|
28
|
-
-
|
29
|
-
- [
|
30
|
-
- [
|
31
|
-
|
32
|
-
|
22
|
+
Currently it supports all Core APIs, Admin APIs and Lakehouse APIs, i.e.:
|
23
|
+
- Core APIs
|
24
|
+
- [Capacities](#working-with-capacities)
|
25
|
+
- [Git](#working-with-git)
|
26
|
+
- [Items](#working-with-items)
|
27
|
+
- [Job Scheduler](#working-with-job-scheduler)
|
28
|
+
- Long Running Operations
|
29
|
+
- [OneLakeShortcuts](#working-with-one-lake-shortcuts)
|
30
|
+
- [Workspaces](#working-with-workspaces)
|
31
|
+
- Lakehouse APIs
|
32
|
+
- [Tables](#tables)
|
33
|
+
- Admin APIs
|
34
|
+
- [Domains](#admin-api-for-domains)
|
35
|
+
- [Items](#admin-api-for-items)
|
36
|
+
- [Tenants](#admin-api-for-tenants)
|
37
|
+
- [Users](#admin-api-for-users)
|
38
|
+
- [Workspaces](#admin-api-for-workspaces)
|
39
|
+
|
40
|
+
It is planned to support also the APIs of the user experiences and new APIs which are not released yet.
|
41
|
+
Also we have plans to support APIs to interact with Fabric capacities on the Azure Side.
|
33
42
|
Eventually Power BI APIs like the Scanner API will be covered as well.
|
34
43
|
|
35
44
|
*Because this SDK uses the API in the background, all limitations and restrictions of the API apply to this SDK as well. This includes rate limits, permissions, etc.
|
@@ -351,11 +360,13 @@ item.cancel_item_job_instance(job_instance_id="job_instance_id")
|
|
351
360
|
|
352
361
|
```
|
353
362
|
|
354
|
-
|
363
|
+
### Tables
|
364
|
+
|
355
365
|
|
356
|
-
# List tables in a Lakehouse
|
357
366
|
|
358
367
|
```python
|
368
|
+
# List tables in a Lakehouse
|
369
|
+
|
359
370
|
from msfabricpysdkcore import FabricClientCore
|
360
371
|
|
361
372
|
fc = FabricClientCore()
|
@@ -380,5 +391,142 @@ fc.load_table(workspace_id = "someworkspaceid", item_id = "someitemid", table_na
|
|
380
391
|
|
381
392
|
```
|
382
393
|
|
394
|
+
### Admin API for Workspaces
|
395
|
+
|
396
|
+
```python
|
397
|
+
from msfabricpysdkcore import FabricClientAdmin
|
398
|
+
|
399
|
+
fca = FabricClientAdmin()
|
400
|
+
|
401
|
+
|
402
|
+
# List workspaces
|
403
|
+
ws = fca.list_workspaces(name="testworkspace")[0]
|
404
|
+
|
405
|
+
# Get workspace
|
406
|
+
ws = fca.get_workspace(workspace_id="workspace_id")
|
407
|
+
|
408
|
+
# Get workspace access details
|
409
|
+
|
410
|
+
ws_access = fca.get_workspace_access_details("workspace_id")
|
411
|
+
# or
|
412
|
+
ws_access = ws.get_access_details()
|
413
|
+
```
|
414
|
+
|
415
|
+
### Admin API for Users
|
416
|
+
|
417
|
+
```python
|
418
|
+
from msfabricpysdkcore import FabricClientAdmin
|
419
|
+
|
420
|
+
fca = FabricClientAdmin()
|
421
|
+
|
422
|
+
# Get access entities
|
423
|
+
|
424
|
+
user_id = 'b4fuhaidc2'
|
425
|
+
access_entities = fca.get_access_entities(user_id, type="Notebook")
|
426
|
+
|
427
|
+
```
|
428
|
+
|
429
|
+
### Admin API for Tenants
|
430
|
+
|
431
|
+
```python
|
432
|
+
from msfabricpysdkcore import FabricClientAdmin
|
433
|
+
|
434
|
+
fca = FabricClientAdmin()
|
435
|
+
|
436
|
+
# Get tenant settings
|
437
|
+
|
438
|
+
tenant_settings = fca.get_tenant_settings()
|
439
|
+
|
440
|
+
# Get capacity tenant settings overrides
|
441
|
+
|
442
|
+
overrides = fca.get_capacities_tenant_settings_overrides()
|
443
|
+
|
444
|
+
```
|
445
|
+
|
446
|
+
### Admin API for Items
|
447
|
+
|
448
|
+
```python
|
449
|
+
from msfabricpysdkcore import FabricClientAdmin
|
450
|
+
|
451
|
+
fca = FabricClientAdmin()
|
452
|
+
|
453
|
+
# List items
|
454
|
+
|
455
|
+
item_list = fca.list_items(workspace_id="wsid")
|
456
|
+
|
457
|
+
# Get item
|
458
|
+
|
459
|
+
item = fca.get_item(workspace_id="wsid", item_id=item_list[0].id)
|
460
|
+
# or
|
461
|
+
item = ws.get_item(item_id=item_list[0].id)
|
462
|
+
|
463
|
+
# Get item access details
|
464
|
+
|
465
|
+
item_access = fca.get_item_access_details(workspace_id="wsid", item_id=item_list[0].id)
|
466
|
+
#or
|
467
|
+
item_access = ws.get_item_access_details(item_id=item_list[0].id)
|
468
|
+
# or
|
469
|
+
item_access = item.get_access_details()
|
470
|
+
|
471
|
+
```
|
472
|
+
|
473
|
+
### Admin API for Domains
|
474
|
+
|
475
|
+
```python
|
476
|
+
from msfabricpysdkcore import FabricClientAdmin
|
477
|
+
|
478
|
+
fca = FabricClientAdmin()
|
479
|
+
|
480
|
+
# Create domain
|
481
|
+
domain_name = "sdktestdomains"
|
482
|
+
domain = fca.create_domain(display_name=domain_name)
|
483
|
+
|
484
|
+
# Get domain by name
|
485
|
+
domain_clone = fca.get_domain_by_name(domain_name)
|
486
|
+
|
487
|
+
# Get domain by id
|
488
|
+
domain_clone = fca.get_domain_by_id(domain.id)
|
489
|
+
|
490
|
+
# List domains
|
491
|
+
domains = fca.list_domains()
|
492
|
+
|
493
|
+
# Update domain
|
494
|
+
domain_new_name = "sdktestdomains2"
|
495
|
+
domain_clone = fca.update_domain(domain.id, display_name=domain_new_name)
|
496
|
+
|
497
|
+
# Assign domain workspaces by Ids
|
498
|
+
fca.assign_domain_workspaces_by_ids(domain.id, ["workspace_id_1", "workspace_id_2"])
|
499
|
+
|
500
|
+
# List domain workspaces
|
501
|
+
workspaces = fca.list_domain_workspaces(domain.id, workspace_objects=True)
|
502
|
+
|
503
|
+
# Unassign domain workspaces by ids
|
504
|
+
status_code = fca.unassign_domain_workspaces_by_ids(domain.id, ["workspace_id_1", "workspace_id_2"])
|
505
|
+
|
506
|
+
# Assign domain workspaces by capacities
|
507
|
+
status_code = fca.assign_domain_workspaces_by_capacities(domain.id, ["cap_id1", "cap_id2"])
|
508
|
+
|
509
|
+
# Unassign all domain workspaces
|
510
|
+
status_code = fca.unassign_all_domain_workspaces(domain.id)
|
511
|
+
|
512
|
+
# Assign domain workspaces by principals
|
513
|
+
principal1 = {'id': '6edbsdfbfdgdf656', 'type': 'User'}
|
514
|
+
principal2 = {'id': '6eyxcbyyxc57', 'type': 'User'}
|
515
|
+
|
516
|
+
status_code = fca.assign_domains_workspaces_by_principals(domain.id, [principal1, principal2], wait_for_completion=True)
|
517
|
+
|
518
|
+
# Role assignments bulk assign
|
519
|
+
|
520
|
+
principals = [principal, principal_2]
|
521
|
+
status_code = fca.role_assignments_bulk_assign(domain.id, "Contributors", principals)
|
522
|
+
|
523
|
+
# Role assignments bulk unassign
|
524
|
+
status_code = fca.role_assignments_bulk_unassign(domain.id, "Contributors", [principal_2])
|
525
|
+
|
526
|
+
# Delete domain
|
527
|
+
status_code = fca.delete_domain(domain.id)
|
528
|
+
```
|
529
|
+
|
530
|
+
|
383
531
|
Note: This SDK is not an official SDK from Microsoft. It is a community project and not supported by Microsoft. Use it at your own risk.
|
384
|
-
Also the API is still in preview and might change. This SDK is not yet feature complete and might not cover all APIs yet. Feel free to contribute to this project to make it better.
|
532
|
+
Also the API is still in preview and might change. This SDK is not yet feature complete and might not cover all APIs yet. Feel free to contribute to this project to make it better.
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import json
|
2
|
+
from time import sleep
|
3
|
+
|
4
|
+
import requests
|
5
|
+
|
6
|
+
|
7
|
+
class AdminItem:
|
8
|
+
"""Class to represent a item in Microsoft Fabric"""
|
9
|
+
|
10
|
+
def __init__(self, id, type, name, workspace_id, state, description, last_updated_date, capacity_id, creator_principal, auth) -> None:
|
11
|
+
"""Constructor for the Item class
|
12
|
+
|
13
|
+
Args:
|
14
|
+
id (str): The ID of the item
|
15
|
+
type (str): The type of the item
|
16
|
+
name (str): The name of the item
|
17
|
+
workspace_id (str): The ID of the workspace
|
18
|
+
state (str): The state of the item
|
19
|
+
description (str): The description of the item
|
20
|
+
last_updated_date (str): The last updated date of the item
|
21
|
+
capacity_id (str): The ID of the capacity
|
22
|
+
creator_principal (dict): The creator principal of the item
|
23
|
+
auth (Auth): The Auth object
|
24
|
+
Returns:
|
25
|
+
Item: The Item object
|
26
|
+
"""
|
27
|
+
self.id = id
|
28
|
+
self.type = type
|
29
|
+
self.name = name
|
30
|
+
self.workspace_id = workspace_id
|
31
|
+
self.state = state
|
32
|
+
self.description = description
|
33
|
+
self.last_updated_date = last_updated_date
|
34
|
+
self.capacity_id = capacity_id
|
35
|
+
self.creator_principal = creator_principal
|
36
|
+
self.auth = auth
|
37
|
+
|
38
|
+
|
39
|
+
def __str__(self) -> str:
|
40
|
+
"""Return a string representation of the workspace object
|
41
|
+
|
42
|
+
Returns:
|
43
|
+
str: The string representation of the workspace object
|
44
|
+
"""
|
45
|
+
dict_ = {
|
46
|
+
'id': self.id,
|
47
|
+
'type': self.type,
|
48
|
+
'name': self.name,
|
49
|
+
'workspace_id': self.workspace_id,
|
50
|
+
'state': self.state,
|
51
|
+
'description': self.description,
|
52
|
+
'last_updated_date': self.last_updated_date,
|
53
|
+
'capacity_id': self.capacity_id,
|
54
|
+
'creator_principal': self.creator_principal
|
55
|
+
}
|
56
|
+
return json.dumps(dict_, indent=2)
|
57
|
+
|
58
|
+
|
59
|
+
def __repr__(self) -> str:
|
60
|
+
return self.__str__()
|
61
|
+
|
62
|
+
def from_dict(item_dict, auth):
|
63
|
+
"""Create Item object from dictionary
|
64
|
+
|
65
|
+
Args:
|
66
|
+
item_dict (dict): The dictionary containing the item information
|
67
|
+
auth (Auth): The Auth object
|
68
|
+
Returns:
|
69
|
+
Item: The Item object"""
|
70
|
+
return AdminItem(
|
71
|
+
id = item_dict['id'],
|
72
|
+
type = item_dict['type'],
|
73
|
+
name = item_dict['name'],
|
74
|
+
workspace_id = item_dict['workspaceId'],
|
75
|
+
state = item_dict['state'],
|
76
|
+
description = item_dict.get('description', None),
|
77
|
+
last_updated_date = item_dict['lastUpdatedDate'],
|
78
|
+
capacity_id = item_dict['capacityId'],
|
79
|
+
creator_principal = item_dict['creatorPrincipal'],
|
80
|
+
auth = auth
|
81
|
+
)
|
82
|
+
|
83
|
+
def get_item_access_details(self, type=None):
|
84
|
+
"""Get the access details of the item
|
85
|
+
|
86
|
+
Returns:
|
87
|
+
dict: The access details of the item"""
|
88
|
+
|
89
|
+
url = f"https://api.fabric.microsoft.com/v1/admin/workspaces/{self.workspace_id}/items/{self.id}/users"
|
90
|
+
|
91
|
+
if type:
|
92
|
+
url += f"?type={self.type}"
|
93
|
+
|
94
|
+
for _ in range(10):
|
95
|
+
response = requests.get(url=url, headers=self.auth.get_headers())
|
96
|
+
if response.status_code == 429:
|
97
|
+
print("Too many requests, waiting 10 seconds")
|
98
|
+
sleep(10)
|
99
|
+
continue
|
100
|
+
if response.status_code not in (200, 429):
|
101
|
+
print(response.status_code)
|
102
|
+
print(response.text)
|
103
|
+
raise Exception(f"Error getting item: {response.text}")
|
104
|
+
break
|
105
|
+
|
106
|
+
return json.loads(response.text)
|
@@ -0,0 +1,127 @@
|
|
1
|
+
import json
|
2
|
+
from time import sleep
|
3
|
+
|
4
|
+
import requests
|
5
|
+
|
6
|
+
from msfabricpysdkcore.admin_item import AdminItem
|
7
|
+
|
8
|
+
|
9
|
+
class AdminWorkspace:
|
10
|
+
"""Class to represent a workspace in Microsoft Fabric"""
|
11
|
+
|
12
|
+
def __init__(self, id, type, name, state, capacity_id, auth) -> None:
|
13
|
+
"""Constructor for the Workspace class
|
14
|
+
|
15
|
+
Args:
|
16
|
+
id (str): The ID of the workspace
|
17
|
+
type (str): The type of the workspace
|
18
|
+
name (str): The name of the workspace
|
19
|
+
state (str): The state of the workspace
|
20
|
+
capacity_id (str): The ID of the capacity
|
21
|
+
auth (Auth): The Auth object
|
22
|
+
Returns:
|
23
|
+
Workspace: The Workspace object
|
24
|
+
"""
|
25
|
+
self.id = id
|
26
|
+
self.type = type
|
27
|
+
self.name = name
|
28
|
+
self.state = state
|
29
|
+
self.capacity_id = capacity_id
|
30
|
+
self.auth = auth
|
31
|
+
|
32
|
+
|
33
|
+
def __str__(self) -> str:
|
34
|
+
"""Return a string representation of the workspace object
|
35
|
+
|
36
|
+
Returns:
|
37
|
+
str: The string representation of the workspace object
|
38
|
+
"""
|
39
|
+
dict_ = {
|
40
|
+
'id': self.id,
|
41
|
+
'type': self.type,
|
42
|
+
'name': self.name,
|
43
|
+
'state': self.state,
|
44
|
+
'capacity_id': self.capacity_id
|
45
|
+
}
|
46
|
+
return json.dumps(dict_, indent=2)
|
47
|
+
|
48
|
+
|
49
|
+
def __repr__(self) -> str:
|
50
|
+
return self.__str__()
|
51
|
+
|
52
|
+
def from_dict(item_dict, auth):
|
53
|
+
"""Create Workspace object from dictionary
|
54
|
+
|
55
|
+
Args:
|
56
|
+
item_dict (dict): The dictionary representing the workspace
|
57
|
+
auth (Auth): The Auth object
|
58
|
+
Returns:
|
59
|
+
Workspace: The Workspace object
|
60
|
+
"""
|
61
|
+
return AdminWorkspace(
|
62
|
+
id=item_dict['id'],
|
63
|
+
type=item_dict['type'],
|
64
|
+
name=item_dict['name'],
|
65
|
+
state=item_dict['state'],
|
66
|
+
capacity_id=item_dict['capacityId'],
|
67
|
+
auth=auth
|
68
|
+
)
|
69
|
+
|
70
|
+
def get_workspace_access_details(self):
|
71
|
+
"""Get the access details of the workspace
|
72
|
+
|
73
|
+
Returns:
|
74
|
+
dict: The access details of the workspace
|
75
|
+
"""
|
76
|
+
url = f"https://api.fabric.microsoft.com/v1/admin/workspaces/{self.id}/users"
|
77
|
+
|
78
|
+
for _ in range(10):
|
79
|
+
response = requests.get(url=url, headers=self.auth.get_headers())
|
80
|
+
if response.status_code == 429:
|
81
|
+
print("Too many requests, waiting 10 seconds")
|
82
|
+
sleep(10)
|
83
|
+
continue
|
84
|
+
if response.status_code not in (200, 429):
|
85
|
+
print(response.status_code)
|
86
|
+
print(response.text)
|
87
|
+
raise Exception(f"Error getting workspace: {response.text}")
|
88
|
+
break
|
89
|
+
|
90
|
+
return json.loads(response.text)
|
91
|
+
|
92
|
+
def get_item(self, item_id, type = None):
|
93
|
+
"""Get an item from the workspace
|
94
|
+
|
95
|
+
Args:
|
96
|
+
item_id (str): The ID of the item
|
97
|
+
type (str): The type of the item
|
98
|
+
Returns:
|
99
|
+
AdminItem: The item object
|
100
|
+
"""
|
101
|
+
url = f"https://api.fabric.microsoft.com/v1/admin/workspaces/{self.id}/items/{item_id}"
|
102
|
+
if type:
|
103
|
+
url += f"?type={type}"
|
104
|
+
for _ in range(10):
|
105
|
+
response = requests.get(url=url, headers=self.auth.get_headers())
|
106
|
+
if response.status_code == 429:
|
107
|
+
print("Too many requests, waiting 10 seconds")
|
108
|
+
sleep(10)
|
109
|
+
continue
|
110
|
+
if response.status_code not in (200, 429):
|
111
|
+
print(response.status_code)
|
112
|
+
print(response.text)
|
113
|
+
raise Exception(f"Error getting item: {response.text}")
|
114
|
+
break
|
115
|
+
item_dict = json.loads(response.text)
|
116
|
+
return AdminItem.from_dict(item_dict, self.auth)
|
117
|
+
|
118
|
+
def get_item_access_details(self, item_id, type=None):
|
119
|
+
"""Get the access details of the item
|
120
|
+
|
121
|
+
Args:
|
122
|
+
item_id (str): The ID of the item
|
123
|
+
type (str): The type of the item
|
124
|
+
Returns:
|
125
|
+
dict: The access details of the item
|
126
|
+
"""
|
127
|
+
return self.get_item(item_id, type).get_item_access_details()
|