Simplify usage of Power Bi Rest API
This is a simple library that makes it easy to use the Power Bi REST API. One day SimplePBI will contain all the categories in the API (Admin, datasets, reports, etc).
Feel free to check the doc to get a deeper understanding of a specific request: https://docs.microsoft.com/en-us/rest/api/power-bi/
We are doing our best to make this library useful for the community. This project is not a remunerable job for us. It's a public community project. Please be patient if you submit an issue and it's not fixed right away. It's a way to express our passion of sharing knowledge.
Each category is an Object. This means we need to initialize an object to start using its methods. In order to create them we need the Bearer token that can be obtain from a Token Object. Let's see how we can create an Admin Object to try the requests in that category.
# Import library from simplepbi import token from simplepbi import admin
We always need to import token object to create the object to run requests. Then we can pick the object of the Power Bi Rest API category we need. For instance "admin". The token can be created in two ways, the regular authentication and the service principal one. It depends which one you pick to complete the request. These are the necessary arguments to get a token:
- tenant_id (you can get it from subscription resource in azure portal or ask for it to the IT department)
- app_client_id (your app_id/client_id from the App registered in Azure with permissions to Power Bi Service)
- username (professional email account in Azure AD)
- password (professional password)
- app_secret_key (secret key generated for the client id)
- use_service_principal (True to athenticate with Service Principal and False to continue with user credentials)
NOTE: if you want to use service principal, be sure to have your tenant ready for that.
Register app example: https://blog.ladataweb.com.ar/post/188045227735/get-access-token
Service Principal permissions for admin api: https://docs.microsoft.com/en-us/power-bi/admin/read-only-apis-service-principal-authentication
# Creating objects #Regular Login tok = token.Token(tenant_id, app_client_id, username, password, None, use_service_principal=False) #Service Principal tok = token.Token(tenant_id, app_client_id, None, None, app_secret_key, use_service_principal=True) ad = admin.Admin(tok.token)
As you can see the Token object contains a token attribute with the Bearer used by Azure to run rest methods. That attribute will be user to create the category objects like admin. Once we create our Object like admin, we can start using the requests adding the correct parameters if they are needed.
# Getting objects All_Datasets = ad.get_datasets() Datasets_In_Groups = ad.get_datasets_in_group(workspace_id)
The library get requests will return a response object .json() that python reads it as a Dict.
There are some methods in the classes that still need more testing. Those will have a "preview" at the end of the name. Please let us know if something goes wrong with those.
Right now the library is consuming endpoints from:
- Pipelines (Preview)
- Scorecards (Preview)
If you want to get a deeper look on complex Admin methods and unique methods. Check this doc
There an aditional library Utils for transformations. It is used to help some requests returning different values. The most useful method in the Utils class might be to_pandas. You can use the method to convert simple dicts to pandas. It needs the dict and the key father of a list of dicts in the response. The usual get responses are using "value" as the key. We are also adding new methods with the requests to help get new actions. Examples:
Example of our amazing unique requests
- get_orphan_dataflows_preview: get dataflows without dataset
- simple_import_pbix: makes publishing a pbix file easier
- simple_import_pbix_as_parameter: import a pbix from api response content
- simple_import_pbix_folder_in_group_preview: post a all pbix files in a local folder
- simple_import_from_devops: import a pbix from azure devops repo
- simple_copy_reports_between_groups: copy report from workspace to a workspace
- enhanced_refresh_dataset_in_group: a special request feature that not only eliminates the need for synchronous client connections to perform a refresh, but also unlocks enterprise-grade refresh capabilities.
- get_activity_events_preview (already iterating): makes the get activity events specified by date easier
- get_user_artifact_access_preview (already iterating): makes the get user artifact access easier
- get_widely shared_artifacts_published_to_web (already iterating): makes geting the published to web repos info easier
Small categories like Dataflow Storage Accounts and Available Features were moved to Groups and Admin.
We are still developing the library. The following endpoints from admin are still missing
- Set and Remove LabelsAsAdmin
- Update group User
- Export To File (full request, there is a smaller simpler one)
- Get Export To File Status (regular and in groups)
- Get File Of Export To File (regular and in groups)
- Update Datasources (rdl files regular and in groups)
- Update Report Content (regular and in groups)
- Create Temporary Upload Location
- Create Temporary Upload Location In Group
- Post Import (for xlsx, json and rdl)
- Post Import In Group (for xlsx, json and rdl)
- Create Datasource (looks like there is a bug on the API)
- Update Datasource
- Delete Datasource
- Patch By Id
- Move Goals
- All requests
- All requests
- All requests
Next Steps (planned items)
- Keep completing missing endpoints category.
- Creating new awesome ideas.
- Analyzing how to include embeding and pushing dataset requests.
- First Commit
- Completing almost all the requests in Admin Section
- Creating aditional content to admin and adding first commit for groups and datasets category
- Repo/source going public. Adding datasets and groups Power Bi Rest API category.
- Fixing error handling. Adding dataflows Power Bi Rest API category
- Fixing install module issues
- Fixing datasets for dax queries
- Fixing typo for dax queries avoiding nulls
- Adding new preview requests for subscriptions in Admin category. Those released this month by Power Bi.
- Adding all dashboards requests and 80% of reports requests.
- Adding widely shared artifacts requests for admin category.
- Adding App category requests.
- Adding "get" requests from import category.
- Fixing reports bugs and adding export to file as preview
- Adding post import file to workspace (only pbix files of less than 1gb)
- Updating Import request ExecuteQueries with the new update from Microsoft making it GA.
- Creating a new method to import all pbix files in an specified local folder to a workspace
- Adding almost all gateway category requests
- Adding new special request from ladataweb. Migrating reports between workspaces. Importing pbix files from Reponse.Content requests library to a Power Bi Service Workspace
- Adding capacities category requests.
- Fixing descriptions
- Adding pipelines and scorecards category requests.
- All componentes category are now available with a little missing endpoints
- Completing at least 80% of request for all most frequent items at Power Bi. The only categories unavailables are push datasets and embedding.
- Bug fixing requests
Minor bug fixing for imports to read filesystem
Improving get activity events for single day after PowerBi updates. Adding new request to get last 30 days of activity logs automatically.
Adding update sources for datasets. It's a complex body request. Adding new unique request for publishing pbix file from azure devops repo. Changing pandas coding to work with 2.0.1 version. Fixing deprecated methods.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for SimplePBI-0.1.3-py3-none-any.whl