Can I iterate through the widgets in a databricks notebook?

2.9k views Asked by At

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 dbutils.widgets}
2

There are 2 answers

1
James Klingensmith On

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

3
J. Peach On

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.