Snapshot
class Snapshot(SnapshotDto)Represents a Daytona Snapshot which is a pre-configured sandbox.
Attributes:
idStrictStr - Unique identifier for the Snapshot.organization_idOptional[StrictStr] - Organization ID of the Snapshot.generalOptional[bool] - Whether the Snapshot is general.nameStrictStr - Name of the Snapshot.image_nameStrictStr - Name of the Image of the Snapshot.stateStrictStr - State of the Snapshot.sizeOptional[Union[StrictFloat, StrictInt]] - Size of the Snapshot.entrypointOptional[List[str]] - Entrypoint of the Snapshot.cpuUnion[StrictFloat, StrictInt] - CPU of the Snapshot.gpuUnion[StrictFloat, StrictInt] - GPU of the Snapshot.memUnion[StrictFloat, StrictInt] - Memory of the Snapshot in GiB.diskUnion[StrictFloat, StrictInt] - Disk of the Snapshot in GiB.error_reasonOptional[StrictStr] - Error reason of the Snapshot.created_atStrictStr - Timestamp when the Snapshot was created.updated_atStrictStr - Timestamp when the Snapshot was last updated.last_used_atStrictStr - 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(page: Optional[int] = None, limit: Optional[int] = None) -> PaginatedSnapshotsReturns paginated list of Snapshots.
Arguments:
pageOptional[int] - Page number for pagination (starting from 1).limitOptional[int] - Maximum number of items per page.
Returns:
PaginatedSnapshots- Paginated list of Snapshots.
Example:
async with AsyncDaytona() as daytona: result = await daytona.snapshot.list(page=2, limit=10) for snapshot in result.items: print(f"{snapshot.name} ({snapshot.image_name})")AsyncSnapshotService.delete
@intercept_errors(message_prefix="Failed to delete snapshot: ")async def delete(snapshot: Snapshot) -> NoneDelete a Snapshot.
Arguments:
snapshotSnapshot - 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) -> SnapshotGet a Snapshot by name.
Arguments:
namestr - 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) -> SnapshotCreates and registers a new snapshot from the given Image definition.
Arguments:
paramsCreateSnapshotParams - Parameters for snapshot creation.on_logsCallable[[str], None] - This callback function handles snapshot creation logs.timeoutOptional[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) -> SnapshotActivate a snapshot.
Arguments:
snapshotSnapshot - 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:
imageImage - The Image instance.
Returns:
List[str]- List of context hashes stored in object storage.
PaginatedSnapshots
class PaginatedSnapshots(PaginatedSnapshotsDto)Represents a paginated list of Daytona Snapshots.
Attributes:
itemsList[Snapshot] - List of Snapshot instances in the current page.totalint - Total number of Snapshots across all pages.pageint - Current page number.total_pagesint - Total number of pages available.
CreateSnapshotParams
class CreateSnapshotParams(BaseModel)Parameters for creating a new snapshot.
Attributes:
nameOptional[str] - Name of the snapshot.imageUnion[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.resourcesOptional[Resources] - Resources of the snapshot.entrypointOptional[List[str]] - Entrypoint of the snapshot.