-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
Through the python-pbi
package, you can interact with the Power BI service to download and upload reports, etc.
Add all the required configuration to create the Pbi
object like so:
config = {
'DOWNLOAD_FOLDER': './downloads/',
'UPLOAD_FOLDER': './upload/'
}
You can download a report from the Power BI service like so:
from pbi.pbi import PowerBI
from tests.config import config
test_pbi = PowerBI(config)
report = test_pbi.download(
'test_report',
test_pbi.download_folder,
workspace_id=<your_powerbi_workspace_id>
)
NB: Power BI service will ask you to authenticate and download all reports containing the string 'test_report'
.
You can upload a report to the Power BI service like so:
from pbi.pbi import PowerBI
from tests.config import config
test_pbi = PowerBI(config)
test_pbi.upload(
test_pbi.upload_folder,
workspace_id=<your_workspace_id>
)
NB: Power BI service will ask you to authenticate and upload all reports contained in the given folder to the Power BI workspace.
You can save a PowerBI report with a different dataset connection. This enables automatic deployment from a development environment to the production environment for example. See an example below:
from pbi.pbi import PowerBI
from pbi.report import PbiReport
from tests.config import config
test_pbi = PowerBI(config)
# Download the report from the development workspace into an arbitrary folder
test_pbi.download(
'test_report',
'temp_folder',
workspace_id=<development_workspace_id>
)
# Brings the report to memory with python-pbi
report = PbiReport(
'temp_folder',
'test_report'
)
# Changes the dataset from development to production dataset
report.save(
dataset_id_from=<development_dataset_id>,
dataset_id_to=<production_dataset_id>,
)
# Uploads the contents of the folder to the production workspace
test_pbi.upload(
'temp_folder',
workspace_id=<production_workspace_id>
)
As already introduced above, the python-pbi
package enables to create Python PbiReport
objects to manipulate them.
Assume you have a Power BI report named test_report.pbix
in the folder test_folder
. You can bring this file to memory as a Python PbiReport
object using the commands below:
from pbi.report import PbiReport
report = PbiReport(
'test_folder',
'test_report'
)
NB: At this stage, the Power BI report is accessible in memory. Please check the PbiReport
section for a more detailed description.
Assume you have a PbiReport
object in memory named report
. After manipulating it, you can easily save it via the command below:
report.save()
NB: The save
method also allows to change the dataset connection if needed.