Skip to main content

Python SDK for the Computer Use Protocol — universal cross-platform UI accessibility

Project description

Computer Use Protocol

Python SDK for the Computer Use Protocol


PyPI MIT License Spec

The official Python SDK for the Computer Use Protocol (CUP) — a universal protocol for AI agents to perceive and interact with any desktop UI. This package provides tree capture, action execution, semantic search, and an MCP server for AI agent integration.

Installation

pip install computeruseprotocol

# Linux additionally requires system packages
sudo apt install python3-gi gir1.2-atspi-2.0

# Web adapter (Chrome DevTools Protocol, works on any OS)
pip install computeruseprotocol[web]

# Screenshot support (mss; not needed on macOS)
pip install computeruseprotocol[screenshot]

# MCP server for AI agent integration
pip install computeruseprotocol[mcp]

Quick start

import cup

# Snapshot the foreground window — optimized for LLM context windows
screen = cup.snapshot()
print(screen)

# All windows
screen = cup.snapshot("full")

# Structured CUP envelope (dict) instead of compact text
envelope = cup.snapshot_raw()

Output:

# CUP 0.1.0 | windows | 2560x1440
# app: Spotify
# 63 nodes (280 before pruning)

[e0] win "Spotify" 120,40 1680x1020
  [e1] doc "Spotify" 120,40 1680x1020
    [e2] btn "Back" 132,52 32x32 [clk]
    [e3] btn "Forward" 170,52 32x32 {dis} [clk]
    [e7] nav "Main" 120,88 240x972
      [e8] lnk "Home" 132,100 216x40 {sel} [clk]
      [e9] lnk "Search" 132,148 216x40 [clk]

CLI

# Print the foreground window tree (default)
python -m cup

# Filter by app name
python -m cup --scope full --app Discord

# Save JSON envelope to file
python -m cup --json-out tree.json

# Capture from Chrome via CDP
python -m cup --platform web --cdp-port 9222

# Include diagnostics (timing, role distribution, sizes)
python -m cup --verbose

Platform support

Platform Adapter Tree Capture Actions
Windows UIA COM (comtypes) Stable Stable
macOS AXUIElement (pyobjc) Stable Stable
Linux AT-SPI2 (PyGObject) Stable Stable
Web Chrome DevTools Protocol Stable Stable
Android Planned Planned
iOS Planned Planned

CUP auto-detects your platform. Platform-specific dependencies (comtypes on Windows, pyobjc on macOS) are installed automatically.

Architecture

cup/
├── __init__.py                 # Public API: snapshot, action, find, ...
├── __main__.py                 # CLI entry point
├── _base.py                    # Abstract PlatformAdapter interface
├── _router.py                  # Platform detection & adapter dispatch
├── format.py                   # Envelope builder, compact serializer, tree pruning
├── search.py                   # Semantic element search with fuzzy matching
├── actions/                    # Action execution layer
│   ├── executor.py             # ActionExecutor orchestrator
│   ├── _handler.py             # Abstract ActionHandler interface
│   ├── _keys.py                # Key name mapping utilities
│   ├── _windows.py             # Windows UIA actions
│   ├── _web.py                 # Chrome CDP actions
│   ├── _macos.py               # macOS actions (Quartz CGEvents + AX)
│   └── _linux.py               # Linux actions (XTest + AT-SPI2)
├── platforms/                  # Platform-specific tree capture
│   ├── windows.py              # Windows UIA adapter
│   ├── macos.py                # macOS AXUIElement adapter
│   ├── linux.py                # Linux AT-SPI2 adapter
│   └── web.py                  # Chrome CDP adapter
└── mcp/                        # MCP server integration
    ├── __main__.py             # python -m cup.mcp entry point
    └── server.py               # MCP protocol server

Adding a new platform means implementing PlatformAdapter — see cup/_base.py for the interface.

MCP Server

CUP ships an MCP server for integration with AI agents (Claude, Copilot, etc.).

# Run directly
cup-mcp

# Or via Python
python -m cup.mcp

Add to your MCP client config (e.g., .mcp.json for Claude Code):

{
    "mcpServers": {
        "cup": {
            "command": "cup-mcp",
            "args": []
        }
    }
}

Tools: snapshot, snapshot_app, overview, snapshot_desktop, find, action, open_app, screenshot

Contributing

CUP is in early development (v0.1.0). Contributions welcome — especially:

  • Android adapter (cup/platforms/android.py)
  • iOS adapter (cup/platforms/ios.py)
  • Tests — especially cross-platform integration tests
  • Documentation and examples

For protocol or schema changes, please contribute to computeruseprotocol.

See CONTRIBUTING.md for setup instructions and guidelines.

Documentation

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

computeruseprotocol-0.1.0.tar.gz (227.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

computeruseprotocol-0.1.0-py3-none-any.whl (96.1 kB view details)

Uploaded Python 3

File details

Details for the file computeruseprotocol-0.1.0.tar.gz.

File metadata

  • Download URL: computeruseprotocol-0.1.0.tar.gz
  • Upload date:
  • Size: 227.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for computeruseprotocol-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0e827cde128468e1194e0b1c0f72b263311687250ceebf96c601093eb3dcf32d
MD5 d4821211d1f498be039f52acfaf9aaf7
BLAKE2b-256 ba00d7341c42e9ddc8fcc2e215445ed63ba9611ac2ba2faf3fecc80fcfa39469

See more details on using hashes here.

Provenance

The following attestation bundles were made for computeruseprotocol-0.1.0.tar.gz:

Publisher: publish.yml on computeruseprotocol/python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file computeruseprotocol-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for computeruseprotocol-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6cda1aea98e77830b129a0b8c5bd56a6a78b8488a3a16c29f378658d32b3b855
MD5 277ec6be1ea16db67d55245da5e85057
BLAKE2b-256 c5020d2c33a78052be91456b7eb8d98ba0245dd634283c15e5ef3132448eecf1

See more details on using hashes here.

Provenance

The following attestation bundles were made for computeruseprotocol-0.1.0-py3-none-any.whl:

Publisher: publish.yml on computeruseprotocol/python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page