Create a parameterized notebook by using the notebook URI
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
URI parameterization
URI parameterization programmatically adds parameters to the query of the Azure Data Studio URI to open the notebook in Azure Data Studio with new parameters.
Azure Data Studio notebook URI supports HTTPS, HTTP, and FILE URI schema and uses this format:
azuredatastudio://microsoft.notebook/open?url=
To pass in parameters with an Azure Data Studio notebook URI, use this format:
azuredatastudio://microsoft.notebook/open?url=LinkToNotebook?x=1&y=2
In the URI query, use &
to indicate a new parameter to be injected.
Parameterization example
You can use an example notebook file to go through the steps in this article:
- Go to the notebook file in GitHub. Select Raw.
- Select Ctrl+S or right-click, and then save the file with the .ipynb extension.
- Open the file in Azure Data Studio.
Here are the contents and structure of the notebook:
x = 2.0
y = 5.0
addition = x + y
multiply = x * y
print("Addition: " + str(addition))
print("Multiplication: " + str(multiply))
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.
The first code cell must be tagged with parameters. If you're using a new notebook file, make a new code cell. Select Parameters to tag the cell as a parameters cell.
You can use either the search bar of any browser or a Markdown cell to open the notebook URI link. Using the Azure Data Studio notebook URI (shown next), you can parameterize the example input notebook on GitHub.
Copy the following notebook URI to parameterize the example input notebook on GitHub with new values for x and y. Paste the URI in a browser search bar:
azuredatastudio://microsoft.notebook/open?url=https://raw.githubusercontent.com/microsoft/sql-server-samples/master/samples/applications/azure-data-studio/parameterization.ipynb?x=10&y=20
When you open the link from the web browser, you're prompted to open the notebook in Azure Data Studio. Select Open Azure Data Studio.
You're prompted to download and open the notebook with new parameters.
Select Yes, and then 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:
Next steps
Learn more about notebooks and parameterization: