Create a parameterized notebook by using the Run with Parameters action

Parameterization in Azure Data Studio is running the same notebook with a different set of parameters.

This article shows you how to create and run a parameterized notebook in Azure Data Studio by using the Python kernel.

Note

Currently, you can use parameterization with Python, PySpark, PowerShell, and .NET Interactive kernels.

Prerequisites

Run with Parameters action

When you use the Run with Parameters notebook action, the user can input new parameters in the UI to quickly set new parameters for your notebook. The user can then run the notebook with the new parameters.

Note

It's important to format the parameter cell with each new parameter on a new line.

Parameterization example

You can use an example notebook file to go through the steps in this article:

  1. Go to the notebook file in GitHub. Select Raw.
  2. Select Ctrl+S or right-click, and then save the file with the .ipynb extension.
  3. Open the file in Azure Data Studio.

Set up a notebook for parameterization

You can begin with the example notebook open in Azure Data Studio or complete the following steps to create a notebook. Then, try using different parameters. All the steps run inside an Azure Data Studio notebook.

  1. Create a new notebook. Change Kernel to Python 3:

    Screenshot that shows the New notebook menu option and setting the Kernel value to Python 3.

  2. If you're prompted to upgrade your Python packages when your packages need updating, select Yes:

    Screenshot that shows the dialog prompt to update Python packages.

  3. Verify that Kernel is set to Python 3:

    Screenshot that shows the Kernel value to Python 3.

  4. Make a new code cell. Select Parameters to tag the cell as a parameters cell.

    x = 2.0
    y = 5.0
    

    Screenshot that shows creating a new parameters cell with Parameters selected.

  5. Add other cells to test different parameters:

    addition = x + y
    multiply = x * y
    
    print("Addition: " + str(addition))
    print("Multiplication: " + str(multiply))
    

    The output will look similar to this example:

    Screenshot that shows the output of cells added to test new parameters.

  6. Save the notebook as Input.ipynb:

    Screenshot that shows saving the notebook file.

Run the notebook with parameters

  1. On the notebook toolbar, select the Run with Parameters icon:

    Screenshot that shows the Run with Parameters icon selected on the toolbar.

  2. A series of new dialogs prompt you to input new parameters for x and y:

    Screenshot that shows entering a new parameter for x.

    Screenshot that shows entering a new parameter for y.

  3. After you enter the new parameters, view the new parameterized notebook. On the toolbar, select Run all to run all cells and see the new output. A new cell labeled # Injected-Parameters contains the new parameter values that were passed in:

    Screenshot that shows the output for new parameters.

Next steps

Learn more about notebooks and parameterization: