Running notebooks with parameters¶
Parameters passed in the ARGUMENTS list are placed into the sys.argv list, with one entry per argument.
The examples on this page use EXECUTE CODE BUNDLE, which takes a list of argument strings. The older EXECUTE NOTEBOOK PROJECT command takes a single string instead. To pass a value that’s computed at runtime, such as a task configuration value, see Pass arguments computed at runtime.
Example: Execute a Code Bundle with parameters¶
The following example passes two arguments (env and prod) using ARGUMENTS = ('env', 'prod').
The first element (sys.argv[0]) is the notebook filename, followed by each argument in the list.
The compute pool, runtime, query warehouse, and dependencies are defined in the Code Bundle’s code_bundle.yml specification.
View all arguments¶
To inspect the full list of parameters passed to the session, use the sys module.
Output example:
Print each argument¶
To process or log each parameter individually, loop through the sys.argv list.
Output example:
Access a specific argument¶
Parameters are accessed by their index in the list. Because sys.argv[0] is the notebook name, the first user parameter starts at index[1].
Output example:
For full syntax and parameter details, see EXECUTE CODE BUNDLE.