Snapshot | Daytona

Snapshot

class Snapshot(SyncSnapshotDto)

Represents a Daytona Snapshot which is a pre-configured sandbox.

Attributes:

SnapshotService

class SnapshotService()

Service for managing Daytona Snapshots. Can be used to list, get, create and delete Snapshots.

SnapshotService.list

@intercept_errors(message_prefix="Failed to list snapshots: ")
@with_instrumentation()

def list(page: int | None = None,
         limit: int | None = None,
         source_sandbox_id: str | None = None) -> PaginatedSnapshots:

Returns paginated list of Snapshots.

Arguments:

Returns:

Example:

daytona = Daytona()

page = daytona.snapshot.list(page=2, limit=10)

print(f"Page {page.page} of {page.total_pages} ({page.total} snapshots total)")

for snapshot in page.items:
    print(f"{snapshot.name} ({snapshot.image_name})")

SnapshotService.delete

@intercept_errors(message_prefix="Failed to delete snapshot: ")
@with_instrumentation()

def delete(snapshot: Snapshot | str) -> None:

Delete a Snapshot.

Arguments:

Example:

daytona = Daytona()

daytona.snapshot.delete("test-snapshot")

print("Snapshot deleted")

SnapshotService.get

@intercept_errors(message_prefix="Failed to get snapshot: ")
@with_instrumentation()

def get(name: str) -> Snapshot:

Get a Snapshot by ID or name.

Arguments:

Returns:

Example:

daytona = Daytona()

snapshot = daytona.snapshot.get("test-snapshot-name")

print(f"{snapshot.name} ({snapshot.image_name})")

SnapshotService.create

@intercept_errors(message_prefix="Failed to create snapshot: ")
@with_timeout()
@with_instrumentation()

def create(params: CreateSnapshotParams,
           *,
           on_logs: Callable[[str], None] | None = None,
           timeout: float | None = 0) -> Snapshot:

Creates and registers a new snapshot from the given Image definition.

Arguments:

Example:

image = Image.debianSlim('3.12').pipInstall('numpy')

daytona.snapshot.create(
    CreateSnapshotParams(name='my-snapshot', image=image),
    on_logs=lambda chunk: print(chunk, end=""),
)

SnapshotService.activate

@with_instrumentation()

def activate(snapshot: Snapshot | str) -> Snapshot:

Activate a snapshot.

Arguments:

Returns:

SnapshotService.process_image_context

@staticmethod
@with_instrumentation()

def process_image_context(object_storage_api: ObjectStorageApi,
                          image: Image) -> list[str]:

Processes the image context by uploading it to object storage.

Arguments:

Returns:

PaginatedSnapshots

class PaginatedSnapshots(PaginatedSnapshotsDto)

Represents a paginated list of Daytona Snapshots.

Attributes:

CreateSnapshotParams

class CreateSnapshotParams(BaseModel)

Parameters for creating a new snapshot.

Attributes: