framework.approval.PythonExecutionApprovalConfig#

class framework.approval.PythonExecutionApprovalConfig(enabled, mode)[source]#

Bases: object

Configuration model for Python code execution approval settings.

Immutable dataclass that encapsulates all settings related to Python code execution approval. The configuration includes both a high-level enabled flag and a granular mode setting that controls when approval is required based on code characteristics.

The configuration supports multiple approval modes to balance security needs with operational efficiency. The most common mode is EPICS_WRITES, which requires approval only for code that can modify accelerator systems.

Parameters:
  • enabled (bool) – Whether Python execution approval is enabled globally

  • mode (ApprovalMode) – Granular approval mode controlling when approval is required

Examples

Create configuration for EPICS writes approval:

>>> config = PythonExecutionApprovalConfig(
...     enabled=True,
...     mode=ApprovalMode.EPICS_WRITES
... )
>>> print(f"Approval enabled: {config.enabled}")
>>> print(f"Mode: {config.mode.value}")

Create configuration with all code approval:

>>> config = PythonExecutionApprovalConfig(
...     enabled=True,
...     mode=ApprovalMode.ALL_CODE
... )

Note

This is a frozen dataclass - instances cannot be modified after creation. Create new instances for different configurations.

See also

ApprovalMode : Enum values used by this configuration PythonExecutionApprovalEvaluator : Evaluator that uses this configuration ApprovalManager : Manager that provides instances of this configuration from_dict() : Factory method for creating instances from dictionaries

enabled: bool#
mode: ApprovalMode#
classmethod from_dict(data)[source]#

Create configuration instance from dictionary with comprehensive validation.

Factory method that creates a PythonExecutionApprovalConfig instance from a configuration dictionary, applying security-first defaults and comprehensive validation. The method provides helpful error messages for configuration issues.

Default Behavior:
  • Missing ‘enabled’ field defaults to True (secure default)

  • Missing ‘mode’ field defaults to ‘all_code’ (most secure mode)

  • Invalid mode values raise ValueError with valid options

Parameters:

data (dict) – Configuration dictionary containing approval settings

Returns:

Validated configuration instance

Return type:

PythonExecutionApprovalConfig

Raises:

ValueError – If data is not a dict or contains invalid mode values

Examples

Create from complete configuration:

>>> config_dict = {'enabled': True, 'mode': 'epics_writes'}
>>> config = PythonExecutionApprovalConfig.from_dict(config_dict)
>>> print(f"Enabled: {config.enabled}, Mode: {config.mode.value}")

Create with defaults (secure fallbacks):

>>> config = PythonExecutionApprovalConfig.from_dict({})
>>> print(f"Default enabled: {config.enabled}")  # True
>>> print(f"Default mode: {config.mode.value}")    # 'all_code'

Handle validation errors:

>>> try:
...     config = PythonExecutionApprovalConfig.from_dict({'mode': 'invalid'})
... except ValueError as e:
...     print(f"Validation error: {e}")

Warning

This method applies security-first defaults. Missing configuration will default to the most secure settings (approval required).

See also

PythonExecutionApprovalConfig : Configuration class created by this method ApprovalMode : Enum values validated by this method GlobalApprovalConfig.from_dict : Similar factory method for global config

__init__(enabled, mode)#