Choose a Python session type
A snapshot saves filesystem state and stops the VM. Processes, memory, open file handles, and connections do not survive it. The next lazy-session command starts compute from the saved image. Call
snapshot() before changing branches in a lazy session. An exception leaving its context discards changes since the last completed snapshot.
Select ContreeSession when each command needs a separate operation. Its disposable=False default saves API-successful operations even when the command exits nonzero. Set disposable=True on a regular session for a read or test that must leave history unchanged, and check the process exit code before choosing a checkpoint. Lazy sessions reject disposable commands.
Run a command
Complete the Python quickstart setup. This complete synchronous program uses the same connection variables or saved profile:uv add "contree-sdk[async]==0.5.1" "contree-client==0.6.0" and use the matching async client and session:
hello. Synchronous run() returns the result directly; async run() must be awaited. The old Contree, ContreeSync, and popen() interfaces were removed in SDK 0.5.
Observe and control work
With a regular session,
run() commits eligible results automatically. After spawn(), wait and call commit_result(operation) to advance history. spawn_detached() records work without starting an event reader; a SQLite store and stable session ID allow collection in another Python process. See detached operations.
An additional process shares its parent operation’s VM, filesystem, resources, and lifetime. It cannot outlive that operation or create a separate checkpoint. See Run subprocesses and send input.
Other session boundaries
SDK history uses an in-memory store by default. Supply a SQLite store and the same session ID to resume after Python exits. Stored history references server images; it does not extend their retention.