bundle.lambdalabs

Lambda Labs cloud GPU integration for TheBundle.

Submodules

Exceptions

LambdaApiError

Common base class for all non-exit exceptions.

Classes

LambdaClient

Async client for the Lambda Labs Cloud API v1.

LambdaLabsConfig

Base data model class, providing utilities for serialization and deserialization

Filesystem

A Lambda Labs persistent NFS filesystem.

Instance

Base data model class, providing utilities for serialization and deserialization

InstanceStatus

str(object='') -> str

InstanceType

Base data model class, providing utilities for serialization and deserialization

SshKey

Base data model class, providing utilities for serialization and deserialization

RemoteJob

Manages a single remote training job on Lambda Labs.

Package Contents

exception bundle.lambdalabs.LambdaApiError(status_code: int, message: str)

Bases: Exception

Common base class for all non-exit exceptions.

status_code
class bundle.lambdalabs.LambdaClient(api_key: str)

Async client for the Lambda Labs Cloud API v1.

Usage:
async with LambdaClient(api_key=”…”) as client:

types = await client.instance_types() instance = await client.launch(“gpu_1x_a10”, ssh_key_names=[“mykey”]) await client.wait_active(instance.id) await client.terminate([instance.id])

async instance_types() → dict[str, bundle.lambdalabs.models.InstanceType]

Return available instance types keyed by name.

async instances() → list[bundle.lambdalabs.models.Instance]

Return all active instances.

async get_instance(instance_id: str) → bundle.lambdalabs.models.Instance

Return a single instance by ID.

async filesystems() → list[bundle.lambdalabs.models.Filesystem]

Return all filesystems in the account.

async create_filesystem(name: str, region_name: str = 'us-east-1') → bundle.lambdalabs.models.Filesystem

Create a persistent filesystem.

async launch(instance_type_name: str, ssh_key_names: list[str], region_name: str = 'us-east-1', name: str | None = None, quantity: int = 1, file_system_names: list[str] | None = None) → list[str]

Launch instances. Returns list of instance IDs.

async terminate(instance_ids: list[str]) → list[str]

Terminate instances. Returns list of terminated instance IDs.

async ssh_keys() → list[bundle.lambdalabs.models.SshKey]

Return all SSH keys in the account.

async add_ssh_key(name: str, public_key: str) → bundle.lambdalabs.models.SshKey

Add an SSH key to the account.

async delete_ssh_key(key_id: str) → None

Delete an SSH key by ID.

async wait_active(instance_id: str, poll_interval: float = DEFAULT_POLL_INTERVAL, timeout: float = 600) → bundle.lambdalabs.models.Instance

Poll until the instance is active with an IP. Raises TimeoutError on timeout.

class bundle.lambdalabs.LambdaLabsConfig(/, **data: Any)

Bases: bundle.core.data.Data

Base data model class, providing utilities for serialization and deserialization from/to JSON, along with JSON Schema generation.

model_config

Default model configuration settings.

api_key: str = ''
default_ssh_key: str = ''
default_region: str = 'us-east-1'
default_instance_type: str = 'gpu_1x_a10'
default_filesystem: str = ''
classmethod load() → LambdaLabsConfig
save() → None
property is_configured: bool
class bundle.lambdalabs.Filesystem(/, **data: Any)

Bases: bundle.core.data.Data

A Lambda Labs persistent NFS filesystem.

Auto-mounted on instances at /home/ubuntu/<name>/. Survives instance termination — ideal for storing datasets and results across multiple training jobs without re-uploading.

id: str
name: str
region: dict[str, Any]
mount_point: str = ''
property path: pathlib.Path

Mount path on the instance.

class bundle.lambdalabs.Instance(/, **data: Any)

Bases: bundle.core.data.Data

Base data model class, providing utilities for serialization and deserialization from/to JSON, along with JSON Schema generation.

model_config

Default model configuration settings.

id: str
name: str | None = None
status: InstanceStatus
instance_type: InstanceType
ip: str | None = None
region: dict[str, Any]
ssh_key_names: list[str] = []
file_system_names: list[str] = []
property is_active: bool
property is_ready: bool
class bundle.lambdalabs.InstanceStatus

Bases: str, enum.Enum

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

BOOTING = 'booting'
ACTIVE = 'active'
UNHEALTHY = 'unhealthy'
TERMINATING = 'terminating'
TERMINATED = 'terminated'
class bundle.lambdalabs.InstanceType(/, **data: Any)

Bases: bundle.core.data.Data

Base data model class, providing utilities for serialization and deserialization from/to JSON, along with JSON Schema generation.

model_config

Default model configuration settings.

name: str
description: str
price_cents_per_hour: int
specs: InstanceSpecs
property price_per_hour: float
class bundle.lambdalabs.SshKey(/, **data: Any)

Bases: bundle.core.data.Data

Base data model class, providing utilities for serialization and deserialization from/to JSON, along with JSON Schema generation.

model_config

Default model configuration settings.

id: str
name: str
public_key: str
class bundle.lambdalabs.RemoteJob(config: bundle.lambdalabs.config.LambdaLabsConfig | None = None, api_key: str | None = None, ssh_key_path: pathlib.Path | None = None, ssh_user: str = 'ubuntu', auto_terminate: bool = False, filesystem_name: str | None = None)

Manages a single remote training job on Lambda Labs.

Lifecycle:
  1. launch() — start a GPU instance (or attach to an existing one)

  2. wait() — poll until active + has IP

  3. setup() — install bundle on the remote instance

  4. upload() — rsync local workspace → remote (skips unchanged files)

  5. run() — execute a command via SSH

  6. download() — rsync remote results → local

  7. terminate()— shut down the instance (optional)

Filesystem mode (recommended):

Pass filesystem_name to mount a Lambda Labs persistent NFS volume. The workspace lives at /home/ubuntu/<filesystem_name>/ and survives instance termination — images and SfM output are never re-uploaded. Only the small runs/ results are downloaded after each job.

config
ssh_key_path
ssh_user = 'ubuntu'
auto_terminate = False
filesystem_name: str
instance: bundle.lambdalabs.models.Instance | None = None
async launch(instance_type: str | None = None, ssh_key_name: str | None = None, region: str | None = None, name: str | None = None, instance_id: str | None = None) → bundle.lambdalabs.models.Instance

Launch a new instance or attach to an existing one by ID.

async wait(timeout: float = 600) → bundle.lambdalabs.models.Instance

Poll until the instance is active with an IP.

async setup() → None

Install bundle on the remote instance.

async upload(local: pathlib.Path, remote: pathlib.Path, skip_existing: bool = False) → None

rsync local directory → remote instance.

When skip_existing=True (set automatically in filesystem mode), files already on the remote are not re-transferred — saving time and bandwidth for large image datasets on subsequent runs.

async download(remote: pathlib.Path, local: pathlib.Path) → None

rsync remote directory → local.

async run(command: str) → None

Execute a shell command on the remote instance via SSH.

async terminate() → None

Terminate the instance.