Run a Python file on a cluster by using the Databricks extension for Visual Studio Code

This article describes how to run a Python file on an Azure Databricks cluster by using the Databricks extension for Visual Studio Code. See What is the Databricks extension for Visual Studio Code?.

To debug a Python file instead, see Debug code by using Databricks Connect for the Databricks extension for Visual Studio Code. To run a Python file as an Azure Databricks job instead, see Run a Python file as a job by using the Databricks extension for Visual Studio Code.

This information assumes that you have already installed and set up the Databricks extension for Visual Studio Code. See Install the Databricks extension for Visual Studio Code.

With the extension and your code project opened, do the following:

  1. In your code project, open the Python file that you want to run on the cluster.
  2. Do one of the following:
    • In Explorer view (View > Explorer), right-click the file, and then select Upload and Run File on Databricks from the context menu.

      Run File on Databricks context menu command

    • In the file editor’s title bar, click the drop-down arrow next to the play (Run or Debug) icon. Then in the drop-down list, click Upload and Run File on Databricks.

      Run File on Databricks editor command

The file runs on the cluster, and any output is printed to the Debug Console (View > Debug Console).