Skip to main content

Python visualizations in Power BI Service

Headshot of article author Santosh Chandwani

With our February update of Power BI, you can now share, publish and view Python visuals in your reports and dashboards. This update extends the support for Python in the Power BI Desktop to the Power BI service.

This ability completes the support for Python in Power BI, enabling you to use Python scripts to prepare your dataset, apply sophisticated analytics or machine learning in the Power BI Desktop & personal gateway, and then plot the results in your Power BI reports using any of the hundreds of open-source Python visualization packages. Publishing your reports to the Power BI service will automatically refresh these visuals with the latest data when a user views the report. Just like the support for R visualizations in Power BI, your Python visualizations will update with cross-filtering in the report, but the visuals are not interactive.

Publishing Power BI reports with Python visuals

You can add a Python visual to your Power BI report by selecting the Python visual icon from the Visualizations pane in the Power BI Desktop, which adds a placeholder Python script to the report. Adding the fields from your dataset to the Values pane of the Python visual, automatically adds the fields to the pandas DataFrame in the placeholder Python script. You can then use the Python script to create the visualization you’d like. See Create Power BI visuals using Python for instructions.

When you publish the report the report to your Power BI workspace, the visuals are automatically refreshed when the report is viewed. Note, there are a few constraints on the size of the serialized Python dataframe, and the execution resources used by the Python scripts, that are summarized below.

Python packages and versions

The initial version of the Python runtime supported in Power BI includes versions 2.7.15 and 3.7.1. We will periodically update the runtime to keep it current.

The following Python packages (non-Intel MKL) are currently supported for use in your Power BI reports:

  • matplotlib
  • numpy
  • pandas
  • scikit-learn
  • scipy
  • seaborn
  • statsmodels

We’ll include the versions of the packages supported in the documentation for the Python support in Power BI.

Security and execution constraints

The Python scripts in your reports are executed by the Power BI service in an isolated sandbox that restricts the access of the scripts to the network and the other machine resources. This ensures that your datasets and the Power BI service are not vulnerable to attacks.

The Power BI service also imposes other limits on Python script execution.

Constraint Limit
Dataframe size 150,000 rows
250MB when serialized in CSV format
Execution time 60 seconds
Memory consumption 1 GB
Disk I/O 1 GB/sec
Image size for a visual in PNG format 2 MB

These limits ensure that user-provided scripts are performant, and moderate in the consumption of resources.

These constraints apply to the execution of Python scripts in Power BI service. Python script execution on the Power BI Desktop and personal gateway has the same dataframe size and PNG image size limits, but the execution time limit is 300 seconds. Other constraints are not applicable to Power BI Desktop and personal gateway.

Python support in Power BI personal gateway

Python can be used for data preparation or for analytics in your Power BI reports, either with a Python script data connector or by using a Python script in the Power Query editor for data transformation.

When you publish a Power BI report with Python scripts to the service, these scripts will also be executed when your data is refreshed through the on-premises data gateway in personal mode (personal gateway).

To enable this, you must ensure that the Python runtime with the dependent Python packages are also installed on the machine hosting your personal gateway. Note, Python script execution is not supported for on-premises data gateways shared by multiple users.

Sample files

A version of the Power BI file with sample Python visuals from the earlier post, updated for publishing to the Power BI service is available here.

If you have any questions, you can post them on the community forums, or you can reach me at @santoshc1. We’d love to hear your feedback and ideas. Hope you enjoy scripting with Python in Power BI!