Python Execution#

Python code generation and execution service with LangGraph-based workflow, approval integration, and flexible deployment options.

Note

For implementation tutorials and usage examples, see Python Execution.

Service Interface#

Request and Response Models#

State Management#

Configuration Models#

Notebook Management#

Exceptions#

Utility Functions#

osprey.services.python_executor.models.get_execution_control_config_from_configurable(configurable)[source]#

Get execution control configuration from LangGraph configurable - raises exceptions on failure.

This provides a consistent way to access control system execution control settings from the configurable that is passed to the Python executor service, ensuring security-critical settings like control_system_writes_enabled are accessed consistently.

Parameters:

configurable (dict[str, Any]) – The LangGraph configurable dictionary

Returns:

Execution control configuration

Return type:

ExecutionControlConfig

Raises:

ContainerConfigurationError – If configuration is missing or invalid

osprey.services.python_executor.models.get_execution_mode_config_from_configurable(configurable, mode_name)[source]#

Create execution mode config from LangGraph configurable - raises exceptions on failure

Return type:

ExecutionModeConfig

osprey.services.python_executor.models.get_container_endpoint_config_from_configurable(configurable, execution_mode)[source]#

Create container endpoint config from LangGraph configurable - raises exceptions on failure

Return type:

ContainerEndpointConfig

Serialization Utilities#

osprey.services.python_executor.services.make_json_serializable(obj)[source]#

Convert complex objects to JSON-serializable format using modern Python patterns.

This is a standalone function that can be imported and used by execution wrappers and other components that need robust JSON serialization.

Parameters:

obj (Any) – Any Python object to make JSON-serializable

Returns:

JSON-serializable representation of the object

Return type:

Any

Examples

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>>
>>> # Handle numpy arrays
>>> arr = np.array([1, 2, 3])
>>> serializable = make_json_serializable(arr)
>>> print(serializable)  # [1, 2, 3]
>>>
>>> # Handle matplotlib figures
>>> fig, ax = plt.subplots()
>>> ax.plot([1, 2, 3])
>>> serializable = make_json_serializable(fig)
>>> print(serializable['_type'])  # 'matplotlib_figure'
osprey.services.python_executor.services.serialize_results_to_file(results, file_path)[source]#

Serialize results and save to JSON file with comprehensive error handling.

This function is designed to be called from execution wrappers and provides robust serialization with detailed error reporting.

Parameters:
  • results (Any) – The results object to serialize

  • file_path (str) – Path where to save the JSON file

Returns:

Metadata about the serialization operation

Return type:

dict

Examples

>>> # Called from execution wrapper
>>> metadata = serialize_results_to_file(results, 'results.json')
>>> if metadata['success']:
>>>     print(f"Results saved successfully to {metadata['file_path']}")
>>> else:
>>>     print(f"Serialization failed: {metadata['error']}")

See also

Python Execution

Complete implementation guide and examples

osprey.capabilities.python.PythonCapability

Capability interface that uses this service