Cua-computer is a Python framework for building rich Computer-Use Interface (CUI) applications, providing programmatic control over terminal interactions, state management, and event processing. It leverages concepts like `Computer`, `Context`, `Task`, and `State` to enable complex, interactive command-line programs. Currently at version 0.5.17, it maintains an active development cadence, with a focus on Python 3.12+ environments.
pip install cua-computerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define application `State`, create asynchronous `Task`s for logic and user interaction, and run them using the `Computer` main loop. It includes an example of spawning a sub-task and handling basic keyboard input.
Review release notes carefully for each update and test your application thoroughly after upgrading. Pin to specific patch versions if stability is critical.
Always use `await` with `context.sleep()` for delays, `context.read_key()` for input, and `context.spawn()` for long-running or parallel tasks to ensure non-blocking execution within the Cua event loop.
Test your Cua application on target terminal environments. Leverage `rich`'s robust capabilities through `cua-computer` but be aware of its limitations in less capable terminals.
Design your `State` object carefully, make state changes explicit within `Task`s, and consider using immutability where appropriate or a dedicated state management pattern for large applications.
For blocking operations, use `asyncio.to_thread()` or `ProcessPoolExecutor` to run them in separate threads/processes, allowing the Cua event loop to remain responsive. Integrate their results back into the `State` asynchronously.