sda.dashboard.utils.decorators#

Callback Decorators and Utilities.


Reusable decorators and utilities to reduce callback boilerplate.

Classes#

CallbackBuilder

Builder pattern for creating callbacks with consistent configuration.

Functions#

with_error_handling([context, severity, ...])

Add error handling to callbacks.

with_state_validation(*state_keys)

Validate state before callback execution.

with_performance_monitoring([threshold_ms])

Monitor callback performance.

with_logging([verbose])

Add logging to callbacks.

auto_callback(inputs, outputs[, prevent_initial_call])

Auto-register callback with common decorators.

create_standard_plot_callback(app, plot_type, ...)

Create a standard plot callback with common configuration.

Module Contents#

sda.dashboard.utils.decorators.with_error_handling(context=ErrorContext.CALLBACK, severity=ErrorSeverity.MEDIUM, fallback_value=None, retry_count=0)#

Add error handling to callbacks.

Parameters:
  • context (ErrorContext) – Context where error occurred

  • severity (ErrorSeverity) – Default error severity

  • fallback_value (Any) – Value to return on error

  • retry_count (int) – Number of retries on failure

sda.dashboard.utils.decorators.with_state_validation(*state_keys)#

Validate state before callback execution.

Parameters:

*state_keys (str) – State keys to validate

sda.dashboard.utils.decorators.with_performance_monitoring(threshold_ms=1000.0)#

Monitor callback performance.

Parameters:

threshold_ms (float) – Performance threshold in milliseconds

sda.dashboard.utils.decorators.with_logging(verbose=True)#

Add logging to callbacks.

Parameters:

verbose (bool) – Whether to enable verbose logging

sda.dashboard.utils.decorators.auto_callback(inputs, outputs, prevent_initial_call=True, **decorator_kwargs)#

Auto-register callback with common decorators.

Parameters:
  • inputs (List[Union[Input, State]]) – Callback inputs

  • outputs (List[Output]) – Callback outputs

  • prevent_initial_call (bool) – Whether to prevent initial call

  • **decorator_kwargs – Arguments for decorators

class sda.dashboard.utils.decorators.CallbackBuilder(app)#

Builder pattern for creating callbacks with consistent configuration.

app#
add_input(component_id, property)#

Add input to callback.

Parameters:
  • component_id (str) – Component ID

  • property (str) – Component property

Returns:

Builder instance for chaining

Return type:

CallbackBuilder

add_state(component_id, property)#

Add state to callback.

Parameters:
  • component_id (str) – Component ID

  • property (str) – Component property

Returns:

Builder instance for chaining

Return type:

CallbackBuilder

add_output(component_id, property)#

Add output to callback.

Parameters:
  • component_id (str) – Component ID

  • property (str) – Component property

Returns:

Builder instance for chaining

Return type:

CallbackBuilder

with_error_handling(context=ErrorContext.CALLBACK, severity=ErrorSeverity.MEDIUM)#

Enable error handling.

Parameters:
  • context (ErrorContext) – Error context

  • severity (ErrorSeverity) – Error severity

Returns:

Builder instance for chaining

Return type:

CallbackBuilder

with_logging(verbose=True)#

Enable logging.

Parameters:

verbose (bool) – Whether to enable verbose logging

Returns:

Builder instance for chaining

Return type:

CallbackBuilder

with_performance_monitoring(threshold_ms=1000.0)#

Enable performance monitoring.

Parameters:

threshold_ms (float) – Performance threshold in milliseconds

Returns:

Builder instance for chaining

Return type:

CallbackBuilder

with_state_validation(*state_keys)#

Enable state validation.

Parameters:

*state_keys (str) – State keys to validate

Returns:

Builder instance for chaining

Return type:

CallbackBuilder

prevent_initial_call(prevent=True)#

Set prevent initial call.

Parameters:

prevent (bool) – Whether to prevent initial call

Returns:

Builder instance for chaining

Return type:

CallbackBuilder

build(handler)#

Build and register the callback.

Parameters:

handler (Callable) – Callback handler function

Returns:

Decorated callback function

Return type:

Callable

sda.dashboard.utils.decorators.create_standard_plot_callback(app, plot_type, graph_id, axis_ids, handler, **kwargs)#

Create a standard plot callback with common configuration.

Parameters:
  • app (dash.Dash) – Dash application

  • plot_type (str) – Type of plot (scatter, line, etc.)

  • graph_id (str) – Graph component ID

  • axis_ids (List[str]) – List of axis component IDs

  • handler (Callable) – Plot handler function

  • **kwargs – Additional configuration

Returns:

Configured callback function

Return type:

Callable