dspy.PythonInterpreter
dspy.PythonInterpreter(deno_command: List[str] | None = None, enable_read_paths: List[PathLike | str] | None = None, enable_write_paths: List[PathLike | str] | None = None, enable_env_vars: List[str] | None = None, enable_network_access: List[str] | None = None, sync_files: bool = True)
PythonInterpreter that runs code in a sandboxed environment using Deno and Pyodide.
Prerequisites: - Deno (https://docs.deno.com/runtime/getting_started/installation/).
Example Usage:
code_string = "print('Hello'); 1 + 2"
with PythonInterpreter() as interp:
output = interp(code_string) # If final statement is non-None, prints the numeric result, else prints captured output
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deno_command
|
List[str] | None
|
command list to launch Deno. |
None
|
enable_read_paths
|
List[PathLike | str] | None
|
Files or directories to allow reading from in the sandbox. |
None
|
enable_write_paths
|
List[PathLike | str] | None
|
Files or directories to allow writing to in the sandbox. |
None
|
enable_env_vars
|
List[str] | None
|
Environment variable names to allow in the sandbox. |
None
|
enable_network_access
|
List[str] | None
|
Domains or IPs to allow network access in the sandbox. |
None
|
sync_files
|
bool
|
If set, syncs changes within the sandbox back to original files after execution. |
True
|
Source code in dspy/primitives/python_interpreter.py
Functions
__call__(code: str, variables: Dict[str, Any] | None = None) -> Any
execute(code: str, variables: Dict[str, Any] | None = None) -> Any
Source code in dspy/primitives/python_interpreter.py
shutdown() -> None
Source code in dspy/primitives/python_interpreter.py
:::