JupyterCodeExecutor

class JupyterCodeExecutor(CodeExecutor)

__init__

def __init__(jupyter_server: Union[JupyterConnectable, JupyterConnectionInfo],
             kernel_name: str = "python3",
             timeout: int = 60,
             output_dir: Union[Path, str] = Path("."))

(Experimental) A code executor class that executes code statefully using a Jupyter server supplied to this class.

Each execution is stateful and can access variables created from previous executions in the same session.

Arguments:

  • jupyter_server Union[JupyterConnectable, JupyterConnectionInfo] - The Jupyter server to use.
  • timeout int - The timeout for code execution, by default 60.
  • kernel_name str - The kernel name to use. Make sure it is installed. By default, it is “python3”.
  • output_dir str - The directory to save output files, by default ”.“.

code_extractor

@property
def code_extractor() -> CodeExtractor

(Experimental) Export a code extractor that can be used by an agent.

execute_code_blocks

def execute_code_blocks(code_blocks: list[CodeBlock]) -> IPythonCodeResult

(Experimental) Execute a list of code blocks and return the result.

This method executes a list of code blocks as cells in the Jupyter kernel. See: https://jupyter-client.readthedocs.io/en/stable/messaging.html for the message protocol.

Arguments:

  • code_blocks List[CodeBlock] - A list of code blocks to execute.

Returns:

  • IPythonCodeResult - The result of the code execution.

restart

def restart() -> None

(Experimental) Restart a new session.

stop

def stop() -> None

Stop the kernel.