Session Archive Retrieval
After a session is complete, you can export all of its processed data as a single ZIP archive. Archives can optionally include the videos captured during recording.
Archive preparation happens asynchronously—you request it, poll until it's ready, then download the ZIP.
Performance considerations
Including videos significantly increases preparation time, especially for sessions with many activities. Only request videos if necessary.
Requesting an Archive
- Swift
- TypeScript
- Python
let archive = try await service.prepareArchive(for: session)
print("Archive task started:", archive.id)
To include videos, pass withVideos: true:
let archive = try await service.prepareArchive(for: session, withVideos: true)
const archive = await service.prepareArchive(session);
console.log("Archive task started:", archive.archiveId);
To include videos, pass true as the second argument:
const archive = await service.prepareArchive(session, true);
archive = service.prepare_archive(session)
print("Archive task started:", archive.id)
To include videos, pass with_videos=True:
archive = service.prepare_archive(session, with_videos=True)
Monitoring Archive Preparation
Poll archiveStatus until the status is ready:
- Swift
- TypeScript
- Python
var status: ArchiveStatus = .processing
while case .processing = status {
print("Archive being prepared...")
try await Task.sleep(nanoseconds: 20_000_000_000) // 20 seconds
status = try await service.archiveStatus(for: archive)
}
switch status {
case .ready:
print("Archive ready to download")
case .failed:
print("Archive preparation failed")
default:
break
}
let status: ArchiveStatus = { type: "processing" };
while (status.type === "processing") {
console.log("Archive being prepared...");
await new Promise(resolve => setTimeout(resolve, 20000));
status = await service.archiveStatus(archive);
}
if (status.type === "ready") {
console.log("Archive ready to download");
} else if (status.type === "failed") {
console.log("Archive preparation failed");
}
import time
from modelhealth import ArchiveStatus
status = ArchiveStatus.processing
while status == ArchiveStatus.processing:
print("Archive being prepared...")
time.sleep(20)
status = service.archive_status(archive)
if status == ArchiveStatus.ready:
print("Archive ready to download")
elif status == ArchiveStatus.failed:
print("Archive preparation failed")
Downloading the Archive
Once the status is ready, download the ZIP data:
- Swift
- TypeScript
- Python
if case .ready = status {
let zipData = try await service.archiveData(for: archive)
try zipData.write(to: URL(fileURLWithPath: "session-archive.zip"))
print("Archive saved:", zipData.count, "bytes")
}
import { writeFileSync } from "fs";
if (status.type === "ready") {
const zipData = await service.archiveData(archive);
writeFileSync("session-archive.zip", zipData);
console.log("Archive saved:", zipData.byteLength, "bytes");
}
if status == ArchiveStatus.ready:
zip_data = service.archive_data(archive)
with open("session-archive.zip", "wb") as f:
f.write(zip_data)
print(f"Archive saved: {len(zip_data)} bytes")
Complete Example
- Swift
- TypeScript
- Python
// Request archive (with videos)
let archive = try await service.prepareArchive(for: session, withVideos: true)
// Wait for preparation to complete
var archiveStatus: ArchiveStatus = .processing
while case .processing = archiveStatus {
try await Task.sleep(nanoseconds: 20_000_000_000)
archiveStatus = try await service.archiveStatus(for: archive)
}
// Download
guard case .ready = archiveStatus else {
print("Archive preparation failed")
return
}
let zipData = try await service.archiveData(for: archive)
try zipData.write(to: URL(fileURLWithPath: "session-archive.zip"))
print("Archive saved:", zipData.count, "bytes")
import { writeFileSync } from "fs";
// Request archive (with videos)
const archive = await service.prepareArchive(session, true);
// Wait for preparation to complete
let archiveStatus: ArchiveStatus = { type: "processing" };
while (archiveStatus.type === "processing") {
await new Promise(resolve => setTimeout(resolve, 20000));
archiveStatus = await service.archiveStatus(archive);
}
// Download
if (archiveStatus.type !== "ready") {
console.log("Archive preparation failed");
return;
}
const zipData = await service.archiveData(archive);
writeFileSync("session-archive.zip", zipData);
console.log("Archive saved:", zipData.byteLength, "bytes");
import time
from modelhealth import ArchiveStatus
# Request archive (with videos)
archive = service.prepare_archive(session, with_videos=True)
# Wait for preparation to complete
archive_status = ArchiveStatus.processing
while archive_status == ArchiveStatus.processing:
time.sleep(20)
archive_status = service.archive_status(archive)
# Download
if archive_status != ArchiveStatus.ready:
print("Archive preparation failed")
else:
zip_data = service.archive_data(archive)
with open("session-archive.zip", "wb") as f:
f.write(zip_data)
print(f"Archive saved: {len(zip_data)} bytes")
Error Handling
- Swift
- TypeScript
- Python
do {
let archive = try await service.prepareArchive(for: session)
// Poll and download...
} catch {
print("Archive error: \(error)")
}
try {
const archive = await service.prepareArchive(session);
// Poll and download...
} catch (error) {
console.error("Archive error:", error);
}
from modelhealth import ModelHealthError
try:
archive = service.prepare_archive(session)
# Poll and download...
except ModelHealthError as e:
print(f"Archive error: {e}")