Skip to main content

Snapshots

The snapshots manager supports create, list, get, and delete operations for snapshot resources.

List snapshots

from instavm import InstaVM

client = InstaVM("your_api_key")

snapshots = client.snapshots.list()
for snap in snapshots:
snap_id = snap.get("snapshot_id") or snap.get("id")
print(f"{snap.get('name', 'unnamed')}: {snap_id} ({snap.get('status')})")

Create from OCI image

client.snapshots.create(...) maps to POST /v1/snapshots and requires oci_image.

snapshot = client.snapshots.create(
oci_image="docker.io/library/python:3.11-slim",
name="python-3.11-base",
vcpu_count=2, # 1..8
memory_mb=1024, # 128..8192
type="user", # user | system
build_args={
"extra_apt_packages": "git ffmpeg",
"extra_pip_packages": "numpy pandas",
"extra_npm_packages": "playwright",
"git_clone_url": "https://github.com/example/repo.git",
"git_clone_branch": "main",
"disk_size_gb": 3, # 1..3
"envs": {"APP_ENV": "prod"},
"post_build_cmd": "pip install -r /app/repo/requirements.txt",
},
)

snapshot_id = snapshot.get("snapshot_id") or snapshot.get("id")
print("Snapshot:", snapshot_id, "status:", snapshot.get("status"))

Poll OCI build status

OCI-image builds are asynchronous. Poll snapshot status until terminal.

snapshot_id = snapshot.get("snapshot_id") or snapshot.get("id")
terminal_statuses = {"ready", "failed"} # adjust to statuses used by your deployment

while True:
current = client.snapshots.get(snapshot_id=snapshot_id)
status = current.get("status")
if status in terminal_statuses:
if status == "failed":
print("build failed:", current.get("last_error"))
break

Get snapshot details

snapshot = client.snapshots.get(snapshot_id="snap_xyz789")

print("id:", snapshot.get("snapshot_id") or snapshot.get("id"))
print("status:", snapshot.get("status"))
print("snapshot_type:", snapshot.get("snapshot_type"))
print("oci_image:", snapshot.get("oci_image"))
print("size_bytes:", snapshot.get("size_bytes"))

Delete a snapshot

client.snapshots.delete(snapshot_id="snap_xyz789")

Create from a running VM

Use the VM manager (POST /v1/vms/{vm_id}/snapshot) for VM-state snapshots:

snapshot = client.vms.snapshot(
vm_id="vm_abc123",
wait=True,
name="configured-environment",
)

See VM Management for VM lifecycle methods.

Next steps