diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/404.html b/404.html new file mode 100644 index 0000000..207892b --- /dev/null +++ b/404.html @@ -0,0 +1,580 @@ + + + +
+ + + + + + + + + + + + + + + + +A context manager for executing code in an IPython kernel.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ host
+ |
+
+ str
+ |
+
+
+
+ Hostname where the code execution container is running + |
+
+ 'localhost'
+ |
+
+ port
+ |
+
+ int
+ |
+
+
+
+ Host port of the code execution container + |
+ + required + | +
+ heartbeat_interval
+ |
+
+ float
+ |
+
+
+
+ Interval in seconds between heartbeat pings. Defaults to 10. + |
+
+ 10
+ |
+
from ipybox import ExecutionClient, ExecutionContainer
+
+binds = {"/host/path": "example/path"}
+env = {"API_KEY": "secret"}
+
+async with ExecutionContainer(binds=binds, env=env) as container:
+ async with ExecutionClient(host="localhost", port=container.port) as client:
+ result = await client.execute("print('Hello, world!')")
+ print(result.text)
+
++Hello, world!
+
ipybox/executor.py
property
+
+
+The ID of the running IPython kernel.
+ + +Raises:
+Type | +Description | +
---|---|
+ ValueError
+ |
+
+
+
+ If not connected to a kernel + |
+
async
+
+
+Creates and connects to an IPython kernel.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ retries
+ |
+
+ int
+ |
+
+
+
+ Number of connection attempts. Defaults to 10. + |
+
+ 10
+ |
+
+ retry_interval
+ |
+
+ float
+ |
+
+
+
+ Delay between retries in seconds. Defaults to 1.0. + |
+
+ 1.0
+ |
+
Raises:
+Type | +Description | +
---|---|
+ ConnectionError
+ |
+
+
+
+ If connection cannot be established after all retries + |
+
ipybox/executor.py
async
+
+
+Closes the connection to the kernel and cleans up resources.
+ +ipybox/executor.py
async
+
+
+execute(code: str, timeout: float = 120) -> ExecutionResult
+
Executes code and returns the result.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ code
+ |
+
+ str
+ |
+
+
+
+ Code to execute + |
+ + required + | +
+ timeout
+ |
+
+ float
+ |
+
+
+
+ Maximum execution time in seconds. Defaults to 120. + |
+
+ 120
+ |
+
Returns:
+Type | +Description | +
---|---|
+ ExecutionResult
+ |
+
+
+
+ ExecutionResult object + |
+
Raises:
+Type | +Description | +
---|---|
+ ExecutionError
+ |
+
+
+
+ If code execution raised an error + |
+
+ TimeoutError
+ |
+
+
+
+ If execution exceeds timeout duration + |
+
ipybox/executor.py
async
+
+
+Submits code for execution and returns an Execution object to track it.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ code
+ |
+
+ str
+ |
+
+
+
+ Python code to execute + |
+ + required + | +
Returns:
+Type | +Description | +
---|---|
+ Execution
+ |
+
+
+
+ An Execution object to track the submitted code execution + |
+
ipybox/executor.py
dataclass
+
+
+The result of a code execution.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ text
+ |
+
+ str | None
+ |
+
+
+
+ Output text generated during execution + |
+ + required + | +
+ images
+ |
+
+ list[Image]
+ |
+
+
+
+ List of images generated during execution + |
+ + required + | +
Execution(client: ExecutionClient, req_id: str)
+
Represents a code execution in an IPython kernel.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ client
+ |
+
+ ExecutionClient
+ |
+
+
+
+ The client instance that created this execution + |
+ + required + | +
+ req_id
+ |
+
+ str
+ |
+
+
+
+ Unique identifier for the execution request + |
+ + required + | +
ipybox/executor.py
async
+
+
+result(timeout: float = 120) -> ExecutionResult
+
Waits for execution to complete and returns the final result.
+If a timeout is reached, the kernel is interrupted.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ timeout
+ |
+
+ float
+ |
+
+
+
+ Maximum time to wait in seconds. Defaults to 120. + |
+
+ 120
+ |
+
Returns:
+Type | +Description | +
---|---|
+ ExecutionResult
+ |
+
+
+
+ ExecutionResult object + |
+
Raises:
+Type | +Description | +
---|---|
+ TimeoutError
+ |
+
+
+
+ If execution exceeds timeout duration + |
+
ipybox/executor.py
async
+
+
+stream(timeout: float = 120) -> AsyncIterator[str]
+
Streams the execution output text as it becomes available.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ timeout
+ |
+
+ float
+ |
+
+
+
+ Maximum time to wait in seconds. Defaults to 120. + |
+
+ 120
+ |
+
Yields:
+Type | +Description | +
---|---|
+ AsyncIterator[str]
+ |
+
+
+
+ Output text chunks as they arrive + |
+
Raises:
+Type | +Description | +
---|---|
+ TimeoutError
+ |
+
+
+
+ If execution exceeds timeout duration + |
+
ipybox/executor.py
+ Bases: Exception
Exception raised when code execution in the IPython kernel fails.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ message
+ |
+
+ str
+ |
+
+
+
+ Error message + |
+ + required + | +
+ trace
+ |
+
+ str | None
+ |
+
+
+
+ Stack trace string representation + |
+
+ None
+ |
+
ipybox/executor.py
+ Bases: Exception
Exception raised when connection to an IPython kernel fails.
+ + + + + + + +A context manager for managing the lifecycle of a Docker container used for code execution.
+It handles the creation, port mapping, volume binding, and cleanup of the container.
+ + +Parameters:
+Name | +Type | +Description | +Default | +
---|---|---|---|
+ tag
+ |
+
+ str
+ |
+
+
+
+ Tag of the Docker image to use (defaults to gradion-ai/ipybox) + |
+
+ DEFAULT_TAG
+ |
+
+ binds
+ |
+
+ dict[str, str] | None
+ |
+
+
+
+ Mapping of host paths to container paths for volume mounting.
+Host paths may be relative or absolute. Container paths must be relative
+and are created as subdirectories of |
+
+ None
+ |
+
+ env
+ |
+
+ dict[str, str] | None
+ |
+
+
+
+ Environment variables to set in the container + |
+
+ None
+ |
+
Attributes:
+Name | +Type | +Description | +
---|---|---|
port |
+
+ int
+ |
+
+
+
+ Host port mapped to the container's executor port. This port is dynamically +allocated when the container is started. + |
+
from ipybox import ExecutionClient, ExecutionContainer
+
+binds = {"/host/path": "example/path"}
+env = {"API_KEY": "secret"}
+
+async with ExecutionContainer(binds=binds, env=env) as container:
+ async with ExecutionClient(host="localhost", port=container.port) as client:
+ result = await client.execute("print('Hello, world!')")
+ print(result.text)
+
++Hello, world!
+
ipybox/container.py
property
+
+
+port: int
+
The host port mapped to the container's executor port.
+This port is dynamically allocated when the container is started.
+ + +Raises:
+Type | +Description | +
---|---|
+ RuntimeError
+ |
+
+
+
+ If the container is not running + |
+
async
+
+
+Kill and remove the Docker container.
+ + +async
+
+
+