Skip to main content
Use the Dedalus Python SDK to create and manage persistent Linux machines from your application. Create one or many machines for a project, run commands, and reuse their files across sessions. Your application calls the SDK. Commands submitted through the SDK run inside the machine. You can also change machine resources, control sleep and wake, request SSH access, and inspect usage. The library provides synchronous and asynchronous clients. Use Dedalus for sequential code. Use AsyncDedalus when your application needs to do other work while it waits for API responses.

Install

Use Python 3.9 or later.

Authenticate

Create an API key in the Dedalus Dashboard, then set it in the environment:
Dedalus() and AsyncDedalus() read DEDALUS_API_KEY automatically.

Create a machine

This creates a machine with 1 vCPU, 4,096 MiB of memory, 10 GiB of storage, and autosleep after five idle minutes:
Use the saved machine.machine_id in later requests for this machine. Machine creation is asynchronous. The response contains the requested state and the machine’s current lifecycle status. You can submit an execution immediately after creation. Dedalus waits for the machine to start before running the command.

Run a command

An execution is one command run inside a machine. Creating an execution returns an execution_id before the command finishes. Use that ID to check the command’s status and retrieve its output. This example writes a file, reads it back, and waits for the execution to finish:
Example output:
Execution status is separate from API status. A successful API request can return an execution whose status is failed. Check the execution status before using its output. timeout_ms limits how long the command can run inside the machine. The execution continues independently of your application’s polling loop until it finishes, is cancelled, expires, or reaches that timeout. See Executions for working directories, environment variables, input, cancellation, and output limits.

Reuse the machine

Dedalus Machines are persistent. Save the machine ID to reuse the same filesystem across application sessions. In a later application session, set MACHINE_ID to the saved ID and retrieve it:
The returned saved_machine contains the machine’s current state. Submit another execution with saved_machine.machine_id to continue working. Executions wake a sleeping machine automatically. Sleep preserves files on the root filesystem and resets processes and memory. See persistence for the complete lifecycle contract. When you no longer need the machine or its files, explicitly request deletion:
Deletion removes the machine and its files. Sleep and autosleep preserve the machine for another session.

Watch lifecycle changes

watch streams machine state changes using server-sent events (SSE). desired_state is the requested state. status.phase is the machine’s current state. These examples request sleep and read updates until the machine is sleeping:
Each update contains a complete machine response. The context manager closes the open stream when the loop exits. The stream closes when the machine reaches its desired state, reports a terminal error, or the five-minute watch limit expires. Retrieve the machine after the stream closes to confirm its current state:

List machines

Machine lists are paginated. limit sets the number of machines requested in each page, and cursor continues from a previous page. Use iteration to fetch pages automatically:
To request one page at a time, inspect items and call get_next_page() only when you want another request:
With the asynchronous client, await client.machines.list(...) to get a page and await get_next_page() to request the next one.

Configure requests

Constructor options apply to every request. Use client.with_options(...) to create a client with overrides for a particular call without changing the original client. This example disables retries for the client and enables two retries for one request:

Retries and timeouts

The SDK retries connection failures, HTTP 408, 409, 429, and 5xx responses twice by default, with increasing delays between attempts. An explicit x-should-retry response header overrides the status-based decision. A timeout raises APITimeoutError and can also be retried. HTTPX timeouts limit individual network operations, not the total duration of a call including retries.

SDK methods

The SDK groups related methods under resources. All methods accept keyword arguments. Methods that act on an existing machine require machine_id. The asynchronous client exposes the same methods with await. Use the API reference for every request field and response field.

Handle errors

An API request and a command can fail independently. A successful API request to executions.retrieve can describe a failed command: check execution.status, exit_code, error_message, and captured stderr before using its results. After an HTTP timeout, use the execution ID to retrieve the existing execution. Submitting another command creates another execution. The client timeout controls HTTP waiting, execution timeout_ms controls command runtime, and machine autosleep controls idle compute. Connection failures raise APIConnectionError. Unsuccessful HTTP responses raise APIStatusError with status_code, response, and body. Both inherit from APIError.
Other unsuccessful status codes use the base APIStatusError type.

Advanced client options

Work with types

Nested request parameters use TypedDict. Responses are Pydantic models with named fields, editor autocomplete, and methods to convert them to JSON (to_json()) or a dictionary (to_dict()). A missing response field and an explicit JSON null both appear as None. Check whether the field name belongs to model_fields_set to distinguish them. If it is absent from that set, the API omitted the field.

Inspect HTTP responses

Use .with_raw_response to receive the HTTP status and headers with the parsed result:
Use .with_streaming_response when you need to read the raw response body as it arrives:
The asynchronous client returns AsyncAPIResponse. Await the request and use async for to read iter_bytes().

Logging

The SDK uses Python’s standard logging module. Set DEDALUS_LOG=info for diagnostic logging or DEDALUS_LOG=debug for more detail.

Customize HTTP requests

The clients use HTTPX by default. Pass DefaultHttpxClient through http_client to configure proxies, transports, or connection pools. Request-specific options passed through with_options(...) override client options.

Use aiohttp with the asynchronous client

Install dedalus-sdk[aiohttp] and pass DefaultAioHttpClient() through http_client to use aiohttp instead of HTTPX.

Requests beyond the generated types

client.get, client.post, and the other HTTP methods let you call endpoints that do not have resource methods. Pass cast_to to choose the response type. Use extra_query, extra_body, or extra_headers for additional request fields.

Close HTTP connections

Use with Dedalus() as client or async with AsyncDedalus() as client to close connections when the block ends. Long-lived applications can keep a client open across requests, then call client.close() or await client.close() during shutdown. Closing the SDK client releases your application’s HTTP connections.

Versioning

Review the release notes before upgrading. If you depend on an internal interface, or find a compatibility issue, report it in the SDK issue tracker.
Last modified on September 9, 2026