apps/docs/src/content/docs/en/python-sdk/sync/snapshot.mdx
class Snapshot(SyncSnapshotDto)
Represents a Daytona Snapshot which is a pre-configured sandbox.
Attributes:
id str - Unique identifier for the Snapshot.organization_id str | None - Organization ID of the Snapshot.general bool - Whether the Snapshot is general.name str - Name of the Snapshot.image_name str - Name of the Image of the Snapshot.state str - State of the Snapshot.size float | int | None - Size of the Snapshot.entrypoint list[str] | None - Entrypoint of the Snapshot.cpu float | int - CPU of the Snapshot.gpu float | int - GPU of the Snapshot.mem float | int - Memory of the Snapshot in GiB.disk float | int - Disk of the Snapshot in GiB.error_reason str | None - Error reason of the Snapshot.created_at str - Timestamp when the Snapshot was created.updated_at str - Timestamp when the Snapshot was last updated.last_used_at str - Timestamp when the Snapshot was last used.class SnapshotService()
Service for managing Daytona Snapshots. Can be used to list, get, create and delete Snapshots.
@intercept_errors(message_prefix="Failed to list snapshots: ")
@with_instrumentation()
def list(page: int | None = None,
limit: int | None = None) -> PaginatedSnapshots
Returns paginated list of Snapshots.
Arguments:
page int | None - Page number for pagination (starting from 1).limit int | None - Maximum number of items per page.Returns:
PaginatedSnapshots - Paginated list of Snapshots.Example:
daytona = Daytona()
result = daytona.snapshot.list(page=2, limit=10)
for snapshot in result.items:
print(f"{snapshot.name} ({snapshot.image_name})")
@intercept_errors(message_prefix="Failed to delete snapshot: ")
@with_instrumentation()
def delete(snapshot: Snapshot) -> None
Delete a Snapshot.
Arguments:
snapshot Snapshot - Snapshot to delete.Example:
daytona = Daytona()
snapshot = daytona.snapshot.get("test-snapshot")
daytona.snapshot.delete(snapshot)
print("Snapshot deleted")
@intercept_errors(message_prefix="Failed to get snapshot: ")
@with_instrumentation()
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:
daytona = Daytona()
snapshot = daytona.snapshot.get("test-snapshot-name")
print(f"{snapshot.name} ({snapshot.image_name})")
@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:
params CreateSnapshotParams - Parameters for snapshot creation.on_logs Callable[[str], None] - This callback function handles snapshot creation logs.timeout float | None - 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=""),
)
@with_instrumentation()
def activate(snapshot: Snapshot) -> Snapshot
Activate a snapshot.
Arguments:
snapshot Snapshot - The Snapshot instance.Returns:
Snapshot - The activated Snapshot instance.@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:
image Image - The Image instance.Returns:
list[str] - List of context hashes stored in object storage.class PaginatedSnapshots(PaginatedSnapshotsDto)
Represents a paginated list of Daytona Snapshots.
Attributes:
items list[Snapshot] - List of Snapshot instances in the current page.total int - Total number of Snapshots across all pages.page int - Current page number.total_pages int - Total number of pages available.class CreateSnapshotParams(BaseModel)
Parameters for creating a new snapshot.
Attributes:
name str - Name of the snapshot.image 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 Resources | None - Resources of the snapshot.entrypoint list[str] | None - Entrypoint of the snapshot.region_id str | None - ID of the region where the snapshot will be available.
Defaults to organization default region if not specified.