Snapshot
class Snapshot(SnapshotDto)
Represents a Daytona Snapshot which is a pre-configured sandbox.
Attributes:
id
StrictStr - Unique identifier for the Snapshot.organization_id
Optional[StrictStr] - Organization ID of the Snapshot.general
Optional[bool] - Whether the Snapshot is general.name
StrictStr - Name of the Snapshot.image_name
StrictStr - Name of the Image of the Snapshot.enabled
StrictBool - Whether the Snapshot is enabled.state
StrictStr - State of the Snapshot.size
Optional[Union[StrictFloat, StrictInt]] - Size of the Snapshot.entrypoint
Optional[List[str]] - Entrypoint of the Snapshot.cpu
Union[StrictFloat, StrictInt] - CPU of the Snapshot.gpu
Union[StrictFloat, StrictInt] - GPU of the Snapshot.mem
Union[StrictFloat, StrictInt] - Memory of the Snapshot in GiB.disk
Union[StrictFloat, StrictInt] - Disk of the Snapshot in GiB.error_reason
Optional[StrictStr] - Error reason of the Snapshot.created_at
StrictStr - Timestamp when the Snapshot was created.updated_at
StrictStr - Timestamp when the Snapshot was last updated.last_used_at
StrictStr - Timestamp when the Snapshot was last used.
AsyncSnapshotService
class AsyncSnapshotService()
Service for managing Daytona Snapshots. Can be used to list, get, create and delete Snapshots.
AsyncSnapshotService.list
@intercept_errors(message_prefix="Failed to list snapshots: ")async def list() -> List[Snapshot]
List all Snapshots.
Returns:
List[Snapshot]
- List of all Snapshots.
Example:
async with AsyncDaytona() as daytona: snapshots = await daytona.snapshot.list() for snapshot in snapshots: print(f"{snapshot.name} ({snapshot.image_name})")
AsyncSnapshotService.delete
@intercept_errors(message_prefix="Failed to delete snapshot: ")async def delete(snapshot: Snapshot) -> None
Delete a Snapshot.
Arguments:
snapshot
Snapshot - Snapshot to delete.
Example:
async with AsyncDaytona() as daytona: snapshot = await daytona.snapshot.get("test-snapshot") await daytona.snapshot.delete(snapshot) print("Snapshot deleted")
AsyncSnapshotService.get
@intercept_errors(message_prefix="Failed to get snapshot: ")async def get(name: str) -> Snapshot
Get a Snapshot by name.
Arguments:
name
str - Name of the Snapshot to get.
Returns:
Snapshot
- The Snapshot object.
Example:
async with AsyncDaytona() as daytona: snapshot = await daytona.snapshot.get("test-snapshot-name") print(f"{snapshot.name} ({snapshot.image_name})")
AsyncSnapshotService.create
@intercept_errors(message_prefix="Failed to create snapshot: ")@with_timeout(error_message=lambda self, timeout: ( f"Failed to create snapshot within {timeout} seconds timeout period."))async def create(params: CreateSnapshotParams, *, on_logs: Callable[[str], None] = None, timeout: Optional[float] = 0) -> Snapshot
Creates and registers a new snapshot from the given Image definition.
Arguments:
params
CreateSnapshotParams - Parameters for snapshot creation.on_logs
Callable[[str], None] - This callback function handles snapshot creation logs.timeout
Optional[float] - Default is no timeout. Timeout in seconds (0 means no timeout).
Example:
image = Image.debianSlim('3.12').pipInstall('numpy')daytona.snapshot.create( CreateSnapshotParams(name='my-snapshot', image=image), on_logs=lambda chunk: print(chunk, end=""),)
AsyncSnapshotService.activate
async def activate(snapshot: Snapshot) -> Snapshot
Activate a snapshot.
Arguments:
snapshot
Snapshot - The Snapshot instance.
Returns:
Snapshot
- The activated Snapshot instance.
AsyncSnapshotService.process_image_context
@staticmethodasync def process_image_context(object_storage_api: ObjectStorageApi, image: Image) -> List[str]
Processes the image context by uploading it to object storage.
Arguments:
image
Image - The Image instance.
Returns:
List[str]
- List of context hashes stored in object storage.
CreateSnapshotParams
class CreateSnapshotParams(BaseModel)
Parameters for creating a new snapshot.
Attributes:
name
Optional[str] - Name of the snapshot.image
Union[str, Image] - Image of the snapshot. If a string is provided, it should be available on some registry. If an Image instance is provided, it will be used to create a new image in Daytona.resources
Optional[Resources] - Resources of the snapshot.entrypoint
Optional[List[str]] - Entrypoint of the snapshot.