Skip to content

Local

swerex.deployment.local.LocalDeployment

LocalDeployment(*, logger: Logger | None = None, **kwargs: Any)

Bases: AbstractDeployment

The most boring of the deployment classes. This class does nothing but wrap around Runtime so you can switch out your deployment method.

Parameters:

Name Type Description Default
**kwargs Any

Keyword arguments (see LocalDeploymentConfig for details).

{}
Source code in swerex/deployment/local.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def __init__(
    self,
    *,
    logger: logging.Logger | None = None,
    **kwargs: Any,
):
    """The most boring of the deployment classes.
    This class does nothing but wrap around `Runtime` so you can switch out
    your deployment method.

    Args:
        **kwargs: Keyword arguments (see `LocalDeploymentConfig` for details).
    """
    self._runtime = None
    self.logger = logger or get_logger("rex-deploy")
    self._config = LocalDeploymentConfig(**kwargs)
    self._hooks = CombinedDeploymentHook()

logger instance-attribute

logger = logger or get_logger('rex-deploy')

runtime property

runtime: LocalRuntime

Returns the runtime if running.

Raises:

Type Description
DeploymentNotStartedError

If the deployment was not started.

add_hook

add_hook(hook: DeploymentHook)
Source code in swerex/deployment/local.py
36
37
def add_hook(self, hook: DeploymentHook):
    self._hooks.add_hook(hook)

from_config classmethod

from_config(config: LocalDeploymentConfig) -> Self
Source code in swerex/deployment/local.py
39
40
41
@classmethod
def from_config(cls, config: LocalDeploymentConfig) -> Self:
    return cls(**config.model_dump())

is_alive async

is_alive(*, timeout: float | None = None) -> IsAliveResponse

Checks if the runtime is alive. The return value can be tested with bool().

Raises:

Type Description
DeploymentNotStartedError

If the deployment was not started.

Source code in swerex/deployment/local.py
43
44
45
46
47
48
49
50
51
52
async def is_alive(self, *, timeout: float | None = None) -> IsAliveResponse:
    """Checks if the runtime is alive. The return value can be
    tested with bool().

    Raises:
        DeploymentNotStartedError: If the deployment was not started.
    """
    if self._runtime is None:
        return IsAliveResponse(is_alive=False, message="Runtime is None.")
    return await self._runtime.is_alive(timeout=timeout)

start async

start()

Starts the runtime.

Source code in swerex/deployment/local.py
54
55
56
async def start(self):
    """Starts the runtime."""
    self._runtime = LocalRuntime(logger=self.logger)

stop async

stop()

Stops the runtime.

Source code in swerex/deployment/local.py
58
59
60
61
62
async def stop(self):
    """Stops the runtime."""
    if self._runtime is not None:
        await self._runtime.close()
        self._runtime = None