cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I pass arguments/variables to notebooks?

__Databricks_Su
Contributor
 
17 REPLIES 17

Manoj12421
Valued Contributor II

You can use % run and then provide exact path of another notebook which one you want to call and for passing parameter ​in Pyspark just use Variable1= 'Valuea'

Variable2= 'Valueb'

For scala use :

$ Vara='Valuea'

$ Varb=' Valueb'

luis_herrera
Contributor

You can use a JSON file to temporarily store the arguments that you want to use in your notebook when passing arguments/variables to it. Using json.You can define the argument list and convert it to a JSON file ().Once the argument file is created, you can open it in a notebook and use the arguments by reading the contents and converting the JSON back into a dictionary with json.loads().

https://kb.databricks.com/jobs/pass-arguments-to-a-notebook-as-a-list

luis_herrera
Contributor

To pass arguments/variables to a notebook, you can use a JSON file to temporarily store the arguments and then pass it as one argument to the notebook. After passing the JSON file to the notebook, you can parse it with json.loads(). The argument list should be defined and converted to a JSON file using json.dumps(). Once the argument file is created, you can open it inside a notebook and use the arguments by reading the contents and converting the JSON back into a dictionary using json.loads().

PS: Check #DAIS2023 talks

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group