Skip to main content

Simplify usage of Power Bi Rest API

Project description

SimplePBI

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.

Preview methods

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.

Complex requests

If you want to get a deeper look on complex Admin methods. Check this doc

Current Categories

Right now the library is consuming endpoints from:

Additional content

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.

Missing endpoints

We are still developing the library. The following endpoints from admin are still missing

Admin

  • Set and Remove LabelsAsAdmin

Groups

  • Update group User

Datasets

  • Update datasources (regular and in groups)

Change Log

0.0.1 (04/12/2020)

  • First Commit

0.0.2 (29/10/2021)

  • Completing almost all the requests in Admin Section

0.0.3 (14/11/2021)

  • Creating aditional content to admin and adding first commit for groups and datasets category

0.0.4 (15/11/2021)

  • Repo/source going public. Adding datasets and groups Power Bi Rest API category.

0.0.5 (16/11/2021)

  • Fixing error handling. Adding dataflows Power Bi Rest API category

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SimplePBI-0.0.5.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SimplePBI-0.0.5-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file SimplePBI-0.0.5.tar.gz.

File metadata

  • Download URL: SimplePBI-0.0.5.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

File hashes

Hashes for SimplePBI-0.0.5.tar.gz
Algorithm Hash digest
SHA256 5948581e5f28fbbbb424b328db4f6800ab53001ea460d6c3a854eb11efbd512d
MD5 8171e979b61b9a33b38b44d43417666f
BLAKE2b-256 de9f2e571855f8590ef0641565c97065203d9b117387baae0792ecfc41685f55

See more details on using hashes here.

File details

Details for the file SimplePBI-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: SimplePBI-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5

File hashes

Hashes for SimplePBI-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a98b57d1df78350f1e08e3f9556dcf39884918d2b54922bd4402727108e9a4f1
MD5 1431c656982b6772dc9fb16e98e018ae
BLAKE2b-256 f02c3f9aea8c117ced7379b6f8cd1e23c52a4d7ddad96982fcf5661c963220a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page