'Can I iterate through the widgets in a databricks notebook?

Can I iterate through the widgets in a databricks notebook? Something like this pseudocode?

# NB - not valid
inputs = {widget.name: widget.value for widget in dbutuils.widgets}


Solution 1:[1]

Yes. You can get all of the widgets returned as a JavaMap. Then you can convert that to a Python dictionary.

%python
my_widgets = dbutils.notebook.entry_point.getCurrentBindings()
{key: my_widgets[key] for key in my_widgets}

Note that "entry_point" is not a supported part of the dbutils API. Databricks could change or remove it without notice.

Solution 2:[2]

i'm not 100% sure but i think so but if not then you might have to manually input the widgets in by them self and not grouped

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 James Klingensmith