flow.sdk.client
Unified GPU workload orchestration.
A concise, explicit interface for submitting, monitoring, and managing GPU workloads across providers. Designed for the common path with clear escape hatches.
Client
Clean SDK facade for Flow - simple for 90%, powerful for 10%.
This client provides a simplified interface to Flow's functionality, abstracting away complexity while maintaining power user access.
Client.cancel
cancel(self, task_id: str, force: bool = False) -> boolCancel a running task.
Parameters:
task_id: Task to cancel
force: Force termination
Returns:
True if cancelled successfully
Client.provider_port
provider_port(self)Get direct access to provider port (power users).
Returns:
Provider port for advanced operations
Client.reserve
Reserve GPU capacity.
Parameters:
gpu: GPU type to reserve
duration_hours: Reservation duration
auto_renew: Auto-renew reservation
Returns:
Reservation ID
Client.run
Run a task with specified resources.
Parameters:
command: Command to run or task specification
gpu: GPU type (e.g., "a100", "v100")
cpus: Number of CPUs
memory_gb: Memory in GB
wait: Wait for task completion
**kwargs: Additional task configuration
Returns:
Task handle for monitoring and management
Client.ssh
Get SSH command for task.
Parameters:
task_id: Task to connect to
Returns:
SSH command string
Client.status
Get status of task(s).
Parameters:
task_id: Specific task ID or None for all tasks
Returns:
List of tasks with current status
Client.volumes
List available volumes.
Returns:
List of volumes
Flow
Primary client for submitting and managing GPU jobs.
Simple for 90% of use cases (one obvious way to run a task)
Explicit configuration via
TaskConfigwhen neededClean access to logs, SSH, volumes, and instance discovery
Flow.cancel
Request cancellation of a running or pending task.
Flow.close
Release provider resources (idempotent).
Flow.create_platform_ssh_key
Create a platform SSH key via provider (preferred).
Falls back to SSH key manager ensure path when available.
Flow.create_volume
Create a persistent volume.
Parameters:
size_gb: Capacity in GB.
name: Optional display name (used in
volume://name).interface: "block" (exclusive attach) or "file" (multi-attach).
region: Optional region to create the volume in. When omitted, the provider's configured/default region is used.
Returns:
Volume.
Examples:
Flow.delete_platform_ssh_key
Delete a platform SSH key via provider (preferred), else manager.
Flow.delete_volume
Delete a volume permanently (no recovery).
Examples:
Flow.dev_context
Context manager for the dev VM.
Parameters:
auto_stop: Stop the VM on context exit.
Returns:
DevEnvironment.
Flow.ensure_default_ssh_key
Ensure a default SSH key exists for the current project when supported.
Returns the key id when created or already present; None when unsupported.
Flow.find_instances
Return available instances that match the given constraints.
Examples:
Flow.get_provider_init
Return the provider's initialization interface.
Flow.get_remote_operations
Return the provider's remote operations interface.
Flow.get_reservation
Get a reservation if supported by the provider.
Returns None when unsupported.
Flow.get_ssh_key_manager
Return the provider's SSH key manager interface.
Flow.get_ssh_tunnel_manager
Return the provider's SSH tunnel manager.
Flow.get_task
Return a Task handle for an existing job.
Examples:
Flow.get_task_ssh_connection_info
Return (ssh_key_path, error_message) for a task, if provider supports it.
Flow.get_user
Get user info if provider exposes it; otherwise None.
Falls back to raw HTTP via provider.http when available.
Flow.get_user_teammates
Return teammates for a given user when supported; else [].
Flow.list_platform_ssh_keys
List platform SSH keys via provider (preferred).
Falls back to provider init interface if provider does not implement the SSH key methods. If the current provider lacks SSH key support (e.g., local), fall back to calling the Mithril API directly using the configured auth token and base URL. This keeps SSH key management available regardless of the active compute provider.
Flow.list_projects
List provider projects accessible to the current credentials.
Flow.list_reservations
List reservations if supported by the provider.
Facet-first; falls back to provider method when available. Returns an empty list when unsupported.
Flow.list_ssh_keys
List SSH keys (optionally filtered by project).
Flow.list_tasks
List recent tasks, optionally filtered by status.
Examples:
Flow.list_volumes
List volumes for the current project (newest first).
Examples:
Flow.logs
Return recent logs or stream them in real time.
Parameters:
task_id: The task to read logs from.
follow: If True, stream logs until the task completes.
tail: Number of trailing lines to fetch when
followis False.stderr: If True, select stderr (may be merged by some providers).
Returns:
str | Iterator[str]: A string (when follow=False) or an iterator of lines.
Examples:
Flow.mount_volume
Attach a volume to a task's configuration at an optional mount point.
Examples:
Flow.normalize_instance_request
Normalize a GPU request to an instance_type and instance count.
Provider-first: attempts provider.normalize_instance_request(). Accepts both legacy tuple shape
(instance_type, num_instances, warning)and dict shape{"instance_type": str, "num_instances": int, ...}.Robust fallback: uses a simple heuristic (2x/4x/8x) when unsupported or when provider returns an unexpected shape.
Flow.reservation_availability
Return reservation availability if supported by the provider.
Parameters:
params: Keys include instance_type, region, earliest_start_time, latest_end_time
Returns:
A list of slots (as dicts). Empty list when unsupported or on error.
Flow.resolve_ssh_endpoint
Resolve SSH endpoint (host, port) for a task (provider fallback).
Flow.run
Submit a task.
Parameters:
task:
TaskConfig, path to YAML, or string path for YAML.wait: If True, block until the task is running before returning.
mounts: Optional data mounts; string or mapping of target->source.
Returns:
Task: Handle for status, logs, SSH, cancel, etc.
Examples:
Flow.shell
Open an interactive shell or run a command on the task instance.
Examples:
Flow.status
Return the task status string (pending, running, completed, failed, cancelled).
Flow.submit
Submit a shell command with minimal configuration.
Parameters:
command: Passed to the container shell.
gpu: e.g. "a100", "a100:4", or "gpu:40gb". Ignored if
instance_typeis set.mounts: Optional data mounts (string or mapping of target->source).
instance_type: Explicit override of the instance type.
wait: If True, block until the task completes.
Returns:
Task.
Examples:
Flow.upload_code_to_task
Upload code to an existing task (facet/provider fallback).
Prefers provider's richer upload (with progress). Falls back to storage facet upload_directory if available.
Flow.wait_for_ssh
Block until SSH is ready for the task or time out.
Last updated