Python SDK for Microsoft Fabric
Created by Microsoft Designer. A Python hugging a F. The F stands for Fabric

Python SDK for Microsoft Fabric

If you are an enthusiast for Microsoft Fabric, automation and Python like me, I have a gift for you. I′m super happy to reveal one of my side projects I have been working on: A Python SDK to work with the Microsoft Fabric APIs.

Check out the updated article for version 0.1.2: (1) Python SDK for Microsoft Fabric v0.1.2 | LinkedIn

Introduction

The Fabric APIs are very useful for a programmatic approach to get an overview of your items in Fabric as well as to change them. Using the APIs you can enforce standards in an automated way as well as keep an eye on your Microsoft Fabric estate. You could even use them to roll out something like Landing Zones or Project Templates.

This SDK is designed to make working with the APIs more convenient and more accessible as well as enhancing the functionalities of the APIs by building logic around them.

This SDK helps to interact with the Fabric APIs in a more Pythonic way. Additionally it brings some extra features like:

- Authentication is handled for you (currently Azure CLI Authentication and Service Principal Authentication are supported)

- Waiting for completion of long running operations

- Retry logic when hitting the API rate limits

- Referencing objects by name instead of ID

- Using granular objects, e.g. a Workspace and Item object instead of providing all parameters in each call

- Do bulk operations**

- Pagination support**

What is in there at the moment?

Currently it supports all Core APIs*, i.e.:

- Capacities

- Git

- Items

- Job Scheduler

- Long Running Operations

- OneLakeShortcuts

- Workspaces

It is planned to support also the Admin and Lakehouse APIs and new APIs which are not released yet. Eventually Power BI APIs like the Scanner API will be covered as well.

*Because this SDK uses the APIs in the background, all limitations and restrictions of the APIs apply to this SDK as well. This includes rate limits, permissions, etc.

**These features are not yet implemented but are planned for the near future.

Note as well this is not an official SDK from Microsoft. It is a community project and not supported by Microsoft.

How to get started?

Installing the library is as easy as it gets:

pip install msfabricpysdkcore        

or you can check out the releases in the corresponding git repository

DaSenf1860/ms-fabric-sdk-core (github.com)

How to use it?

To work with the SDK you initialize a Client first:

from msfabricpysdkcore import FabricClientCore

# Create a client

# Either login with the Azure CLI first and initiate the client directly
fc = FabricClientCore()

# Or use a service principal (note that not all APIs are supported with service principal)
# You can also use environment variables to set the service principal id and secret. The environment variables are:
# FABRIC_CLIENT_ID
# FABRIC_CLIENT_SECRET
# FABRIC_TENANT_ID

fc = FabricClientCore(tenant_id = "tenant_id",
                      client_id = "your_service_principal_id",
                      client_secret = "your_service_principal_secret")        

Now you can do all the things the REST APIs are doing and more.

E.g. creating, updating and listing workspaces, assigning capacities, build up a git connection, create shortcuts....

Here are some examples:

# Create a workspace
ws_created = fc.create_workspace(display_name="testworkspace",
                                 description="test workspace", 
                                 exists_ok=False)


# List workspaces
result = fc.list_workspaces()
for ws in result:
    print(ws)


# Get workspace role assignments
fc.get_workspace_role_assignments(workspace_id = ws.id)
# or
ws.get_role_assignments()        

Note that you can either provide the Client with all parameters or you can work on the object itself. E.g. a OneLake-Shortcut belongs to a Item which belongs to a Workspace. So it′s convenient that you can create an item on a workspace object and a shortcut on an item

ws = fc.create_workspace(display_name="testworkspace",
                         description="test workspace")

item = ws.create_item(display_name="lakehouse123", type="Lakehouse")


shortcut item.create_shortcut(path="path",
                              name="name",
                               target={"oneLake": {"itemId":                     
                                             "item_id_target",
                                            "path": "path_target",
                                            "workspaceId": 
                                              "workspace_id_target"}})        

For a full view of features and usage patterns check out the github-repo:

DaSenf1860/ms-fabric-sdk-core (github.com)

Conclusion

I hope this SDK helps some people to feel more confident to work with the Microsoft Fabric REST APIs and with Microsoft Fabric as their data analytics platform. My plan is to enhance and update the SDK whenever there are new API versions and new APIs released. I′m looking forward for some feedback. Feel free to reach out.

Hi Andreas, do you know if there are any plans by MS to provide an official Fabric SDK for Python, similar to the one for .NET? https://blog.fabric.microsoft.com/en-us/blog/microsoft-fabric-net-sdk/

回复
Eddie Kwon

Power BI Architect at Supreme BI, LLC

5 个月

Amazing!

回复
Andreas Rederer (geb. Essbaumer)

Technology Specialist Data & AI at Microsoft

5 个月

thank you everyone for the positive feedback. Today I released version 0.0.9 Now the SDK covers all Fabric REST APIs (Admin, Core, Lakehouse, Item specific CRUD APIs,...) You can also install and run the SDK in a Fabric notebook now

回复
Mario J. Vargas Valles

Tech Executive / Technology Agitator/ Cloud/ Data & AI lover/Mentor/Angel Tech Investor/GM/EMEA/LATAM/US

5 个月

great contribution. Congrats and thanks for

回复
回复

要查看或添加评论,请登录

Andreas Rederer (geb. Essbaumer)的更多文章

  • Python SDK for Microsoft Fabric v0.1.2

    Python SDK for Microsoft Fabric v0.1.2

    It′s been a while that I revealed one of my side projects I have been working on: A Python SDK to work with the…

  • Integrating Microsoft Fabric and Databricks Unity Catalog

    Integrating Microsoft Fabric and Databricks Unity Catalog

    This is a short guide on how to currently integrate Microsoft Fabric with Databricks Unity Catalog to get the best of…

    10 条评论
  • Write data from Power Apps to Fabric

    Write data from Power Apps to Fabric

    You may have encountered use cases where it would be quite useful to have a direct path from your Power App which is…

    3 条评论

社区洞察

其他会员也浏览了