Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

cmux Python SDK

The package root is the handwritten cmux resource API. It uses opaque prefixed string IDs, tagged selectors, typed snapshots, explicit mutation receipts, structured errors, and cancellable streams. It supports Python 3.9+ with no runtime dependencies. The distribution includes the PEP 561 py.typed marker so type checkers consume its inline annotations.

Install the cmux-sdk distribution. The Python import remains cmux, so it does not overlap the uvx cmux CLI distribution:

python -m pip install cmux-sdk
from cmux import Client, SessionId, WorkspaceId, exact
from cmux.options import RunOptions

with Client() as client:
    session = client.session(
        SessionId("session_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    )
    workspace = session.workspace(
        WorkspaceId("ws_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
    )
    created = workspace.run(
        RunOptions(exact(["printf", "%s\n", "$HOME"]))
    )
    print(created.value.terminal.id)

exact() sends its argv without shell parsing. shell() asks the server to choose the target platform shell. shell_executable() sends [executable, "-lc", script] when the caller needs a specific shell.

Mutations never retry implicitly. Omit idempotency_key to receive a fresh cryptographically random key, or supply one to control replay behavior. Snapshots update only through explicit refresh(). Handles close resources only through their explicit close() methods.

Known catalog snapshots and results are exact dataclasses. Unknown sibling fields are rejected unless the catalog declares an extra map. Terminal reads return types such as TerminalScreenResult, TerminalHistoryResult, and ProcessInfoResult; empty mutations return MutationReceipt.

If a mutation loses its response to a timeout or disconnect, MutationTransportError exposes its operation and exact supplied or generated key.

Synchronous calls can apply one local deadline or cancellation signal:

from cmux import CancellationToken, RequestOptions

cancellation = CancellationToken()
result = client.with_request_options(
    RequestOptions(timeout=1.0, cancellation=cancellation),
    session.ping,
)

After a dispatched terminal.wait or terminal.wait_exit reaches its local deadline or cancellation signal, the SDK confirms request.cancel on the same connection before reusing it. A completion that wins the server race is drained instead. Cleanup failure closes the connection while preserving the original TimeoutError or CancelledError.

Streams retain at most 256 unread messages and 16 MiB. Overflow ends only that stream with a recoverable gap and sends best-effort cancellation. Close the stream or its client explicitly. stream.next(timeout=...) raises cmux.TimeoutError without closing the stream.

Browser frames always carry pointer_frame_seq on the wire. The SDK exposes it as int | None: None means the frame cannot authorize pointer input. Mouse and wheel calls require the exact non-null token from the rendered frame and encode it as an unsigned decimal string:

from cmux import BrowserAttachFrame, BrowserId
from cmux.options import BrowserMouseOptions

browser = session.browser(
    BrowserId("browser_cccccccccccccccccccccccccccccccc")
)
with browser.attach() as frames:
    for event in frames:
        frame = event.item
        if isinstance(frame, BrowserAttachFrame):
            if frame.pointer_frame_seq is not None:
                browser.mouse(BrowserMouseOptions(
                    kind="move",
                    x_px=12.5,
                    y_px=20.0,
                    pointer_frame_seq=frame.pointer_frame_seq,
                ))
            break

The asyncio facade mirrors the resource graph:

import cmux.aio
from cmux import RequestOptions

async with cmux.aio.Client() as client:
    machines = await client.list_machines(
        request_options=RequestOptions(timeout=1.0)
    )

Creation recovery uses session.creation.resolve(correlation_key). Terminal exit waits use terminal.wait_exit(timeout_ms) and return strict pending or exited dataclasses with typed exit, signal, and unknown outcomes.

Destructive layout undo raises ConfirmationRequiredError with a typed preview token, revision, and panes. Retry with that token, its revision, and a new idempotency key.

All eight creation option dataclasses expose correlation_key. Values contain 1 to 128 UTF-8 bytes and remain stable across creation attempts.

Agent state reporting starts from the session, so a new terminal does not need an existing agent-list result:

from cmux import AgentReportOptions

reported = session.report_agent(AgentReportOptions(
    terminal_id=terminal_id,
    state="working",
    source="socket",
))

Each async stream owns its blocking reader worker. A waiting stream does not occupy a request worker. Canceling a stream closes only that stream. Closing the client releases all remaining stream, request, and reader workers.

The generated protocol-v10 client and numeric mux identities are available only from cmux.raw:

from cmux.raw import CmuxClient, COMMANDS

An explicit socket path wins. Otherwise the client checks CMUX_TUI_SOCKET, then CMUX_MUX_SOCKET, then resolves the named session under XDG_RUNTIME_DIR, TMPDIR, or /tmp.

Metadata

Release files for cmux-sdk 0.0.0a0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cmux-sdk 0.0.0a0
File Size Uploaded
cmux_sdk-0.0.0a0.tar.gz 116.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cmux-sdk 0.0.0a0
File Interpreter ABI Platform
cmux_sdk-0.0.0a0-py3-none-any.whl Python 3 none any Details

Total release size: 213.7 kB

Release files / cmux_sdk-0.0.0a0.tar.gz

Download URL cmux_sdk-0.0.0a0.tar.gz
Size 116.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8023ff6b4271f5b5bac2fa985639b0f64bee4d71edae740b75f0557dd7e64da6
BLAKE2b-256 checksum
How to use checksums
bb7d2ff9ec9c8fb91f79b5637ed6c160d9e8178df901f2df52995c6c18e8edb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

Release files / cmux_sdk-0.0.0a0-py3-none-any.whl

Download URL cmux_sdk-0.0.0a0-py3-none-any.whl
Size 97.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6dbc3d4d7929a4f2b6dec64f3cce30a69f3e0fdd33641fb16a4ba5fe59f67d78
BLAKE2b-256 checksum
How to use checksums
57e07181e00f64f6d6e17ce0fb4ab4f9b126e7e7da211dbe4b1b3a6dbfafd57e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.0a0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page