Part 1: Microsoft Fabric admin – How to create multiple workspaces using Python

Context

Recently I have been working a lot with the Power BI / Fabric REST APIs to perform some tasks as Fabric Administrator, such as to automate the creation of workspaces, assign users / Microsoft Entra ID groups to workspaces, assign Fabric capacity to workspaces and so on.

I will create a series of posts about this topic and how to automate such tasks using Python. The goal of this post is to show you a way to create multiple Fabric / Power BI workspaces using the Fabric and Power BI REST APIs.

Disclaimer: I am not a Python expert, so if you have any improvement suggestion regarding the Python code, feel free to comment here 🙂

Understanding the problem

Let’s imagine a scenario where a user wants 3 workspaces (DEV, TEST and PROD) so that they can start building their reports and/or Fabric items in the workspaces. The requirements are as follows:

  • User wants to get 3 workspaces (DEV, TEST and PROD)

  • User gives as input the name of the workspace for DEV environment for example “dev-test-gj” so that the name of the other workspaces should follow: “test-test-gj” and “prod-test-gj”

  • Before creating the workspace, it should verify if the workspace name already exists in the tenant

Solution – Creating multiple workspaces in Microsoft Fabric

There are of course multiple ways to solve this task, so feel free to use your imagination to change or extend the code.

What do you need to perform this task?

  • Create a service principal to use the Fabric / Power BI REST APIs

  • Allow the usage of the service principal in the Fabric tenant settings. See below:


  • Add the service principal or the Microsoft Entra ID in your workspace as admin

I won’t go through the steps above how to create a service principal, because there are already plenty of great tutorials explaining how to do that. For example, this video from Guy in a Cube.

To solve this task, you could use the request Python library to do a POST request using the REST API. But I will use in this case the pbipy Python library, which is a Python wrapper built on top of the Power BI REST APIs. In case there is something missing in the pbipy library, you could also mix with the request library to achieve what you want, or you could extend the Python wrapper itself 🙂

You can find the Python code below as screenshot:

You can find below the Python code in my Github repo:

Github Repo with the Python code

Conclusion

In this post we talked about how to create multiple workspaces in Microsoft Fabric using Python. In the next part of this Microsoft Fabric admin series, I will talk about how to add Microsoft Entra ID security groups to workspaces.

About The Author

Guilherme Joaquim is a passionate data enthusiast living in Switzerland with extensive experience building business intelligence solutions in Power BI, Azure and currently diving into Microsoft Fabric. Outside the data world, he enjoys hiking and outdoor sports.

Guilherme is a certified Fabric Analytics Engineer and Power BI Data Analyst.

Pause
Joaquim, G. (2024). Part 1: Microsoft Fabric admin – How to create multiple workspaces using Python. Available at: Part 1: Microsoft Fabric admin – How to create multiple workspaces using Python — DATA TRAVELING (data-traveling.com) [Accessed: 15th August 2024].

Share this on...

Rate this Post:

Share: