- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2025 08:50 PM
@lingareddy_Alva Thanks for your response.
But, I exactly doing what you explained. The dbutils.widgets are all extracted in the DatabricksParams and returns the params dictionary. This dictionary params is passed to my subsequent methods.
Please see my code below:
class DatabricksParams:
def __init__(self, dbutils):
self.dbutils = dbutils
self.params = {}
self._load_params()
def _load_params(self):
try:
# Load widget values
widgets = self.dbutils.notebook.entry_point.getCurrentBindings()
for key in widgets:
self.params[key] = self.dbutils.widgets.get(key)
# Load notebook context
notebook_info = json.loads(self.dbutils.notebook.entry_point.getDbutils().notebook().getContext().toJson())
self.params['job_id'] = notebook_info["tags"]["jobId"]
self.params['job_run_id'] = notebook_info["tags"]["jobRunId"]
logger.info(f"Loaded parameters: {self.params}")
except Exception as e:
raise RuntimeError(f"Error loading parameters: {e}")
def get_param(self, key, default=None):
return self.params.get(key, default)