Skip to content

Quickstart

Install ipybox with:

pip install ipybox

Execute Python code in an ipybox container:

import asyncio

from ipybox import ExecutionClient, ExecutionContainer


async def main():
    tag = "ghcr.io/gradion-ai/ipybox:minimal"  # (1)!
    async with ExecutionContainer(tag) as container:  # (2)!
        async with ExecutionClient(port=container.executor_port) as client:  # (3)!
            result = await client.execute("print('Hello, world!')")  # (4)!
            print(f"Output: {result.text}")  # (5)!


if __name__ == "__main__":
    asyncio.run(main())
  1. Name and tag of a prebuilt ipybox Docker image.
  2. Create and start a code execution container and remove it on context manager exit.
  3. Create an IPython kernel in the container and remove it on context manager exit.
  4. Execute Python code in the kernel and await the result.
  5. Prints: Output: Hello, world!