Pass parameters from Synapse Pipeline to Notebook

Jona 885 Reputation points
2025-07-30T03:03:06.74+00:00

Hi,

I have this situation:

  1. A Synapse pipeline with parameters
  2. A Notebook activity inside it

I don't see in the Notebook activity to pass paramerts to PySpark, and I don't know how to get them from code in the case the parameters could be be passed from the pipeline to the notebook

Can you give me a hand?

Regards

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Venkat Reddy Navari 5,255 Reputation points Microsoft External Staff Moderator
    2025-07-30T04:05:37.0166667+00:00

    Hi Jona You can definitely pass parameters from a Synapse pipeline to a notebook activity, and then access those parameters inside your PySpark code. Here's how you can do it:

    Step 1: Define Parameters in the Notebook

    At the top of your notebook, define the parameters using the mssparkutils library:

    
    # Import the required utility
    from notebookutils import mssparkutils
    
    # Get the parameters
    param1 = mssparkutils.notebookutils.getArgument("param1")
    param2 = mssparkutils.notebookutils.getArgument("param2")
    

    Note: If you're using a newer runtime, you can also use dbutils.widgets.get("param1"), but mssparkutils is preferred in Synapse.

    Step 2: Pass Parameters in the Pipeline

    In your Synapse pipeline, select the Notebook activity.

    In the Settings tab, under Base parameters, you can add parameters by name and assign them pipeline expressions like:

    
    @pipeline().parameters.param1
    

    Example: Pipeline Parameters:

    param1: string

    param2: string

    Notebook Activity Base Parameters:

    Name Value
    param1 @pipeline().parameters.param1
    param2 @pipeline().parameters.param2

    Notebook Code:

    
    param1 = mssparkutils.notebookutils.getArgument("param1")
    param2 = mssparkutils.notebookutils.getArgument("param2")
    
    print(f"Received param1: {param1}")
    print(f"Received param2: {param2}")
    
    
    

    Hope this helps. If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.