Template Async
AsyncTemplate
class AsyncTemplate(TemplateBase)Asynchronous template builder for E2B sandboxes.
build
@staticmethod
async def build(template: TemplateClass,
alias: str,
cpu_count: int = 2,
memory_mb: int = 1024,
skip_cache: bool = False,
on_build_logs: Optional[Callable[[LogEntry], None]] = None,
**opts: Unpack[ApiParams]) -> BuildInfoBuild and deploy a template to E2B infrastructure.
Arguments:
template: The template to buildalias: Alias name for the templatecpu_count: Number of CPUs allocated to the sandboxmemory_mb: Amount of memory in MB allocated to the sandboxskip_cache: If True, forces a complete rebuild ignoring cacheon_build_logs: Callback function to receive build logs during the build process Example
from e2b import AsyncTemplate
template = (
AsyncTemplate()
.from_python_image('3')
.copy('requirements.txt', '/home/user/')
.run_cmd('pip install -r /home/user/requirements.txt')
)
await AsyncTemplate.build(
template,
alias='my-python-env',
cpu_count=2,
memory_mb=1024
)build_in_background
@staticmethod
async def build_in_background(template: TemplateClass,
alias: str,
cpu_count: int = 2,
memory_mb: int = 1024,
skip_cache: bool = False,
on_build_logs: Optional[Callable[[LogEntry],
None]] = None,
**opts: Unpack[ApiParams]) -> BuildInfoBuild and deploy a template to E2B infrastructure without waiting for completion.
Arguments:
template: The template to buildalias: Alias name for the templatecpu_count: Number of CPUs allocated to the sandboxmemory_mb: Amount of memory in MB allocated to the sandboxskip_cache: If True, forces a complete rebuild ignoring cache
Returns:
BuildInfo containing the template ID and build ID Example
from e2b import AsyncTemplate
template = (
AsyncTemplate()
.from_python_image('3')
.run_cmd('echo "test"')
.set_start_cmd('echo "Hello"', 'sleep 1')
)
build_info = await AsyncTemplate.build_in_background(
template,
alias='my-python-env',
cpu_count=2,
memory_mb=1024
)get_build_status
@staticmethod
async def get_build_status(build_info: BuildInfo,
logs_offset: int = 0,
**opts: Unpack[ApiParams])Get the status of a build.
Arguments:
build_info: Build identifiers returned from build_in_backgroundlogs_offset: Offset for fetching logs
Returns:
TemplateBuild containing the build status and logs Example
from e2b import AsyncTemplate
build_info = await AsyncTemplate.build_in_background(template, alias='my-template')
status = await AsyncTemplate.get_build_status(build_info, logs_offset=0)alias_exists
@staticmethod
async def alias_exists(alias: str, **opts: Unpack[ApiParams]) -> boolCheck if a template with the given alias exists.
Arguments:
alias: Template alias to check
Returns:
True if the alias exists, False otherwise Example
from e2b import AsyncTemplate
exists = await AsyncTemplate.alias_exists('base')
if exists:
print('Template exists!')check_alias_exists
async def check_alias_exists(client: AuthenticatedClient, alias: str) -> boolCheck if a template with the given alias exists.
Arguments:
client- Authenticated API clientalias- Template alias to check
Returns:
True if the alias exists, False otherwise