Skip to main content

Python client for UI Bridge Framework

Project description

UI Bridge Python Client

Python client library for controlling UI elements via the UI Bridge HTTP API.

Installation

pip install ui-bridge-python

Quick Start

from ui_bridge import UIBridgeClient

# Connect to the UI Bridge server
client = UIBridgeClient("http://localhost:9876")

# Click a button
client.click("submit-btn")

# Type into an input
client.type("email-input", "user@example.com")

# Select from a dropdown
client.select("country-select", "US")

# Execute a component action
client.component("login-form").action("submit", {
    "email": "user@example.com",
    "password": "secret"
})

# Run a workflow
result = client.workflow("login-flow").run({
    "email": "user@example.com",
    "password": "secret"
})

Features

  • Element Control: Click, type, select, scroll, and more
  • Component Actions: Execute high-level component actions
  • Workflows: Run multi-step automation workflows
  • Discovery: Find controllable elements in the UI
  • Render Logging: Capture and analyze DOM snapshots
  • Debug Tools: Access action history and performance metrics

Element Actions

# Click actions
client.click("btn")
client.double_click("btn")
client.right_click("btn")

# Input actions
client.type("input", "text")
client.type("input", "text", clear=True)  # Clear first
client.clear("input")

# Selection
client.select("dropdown", "value")
client.select("dropdown", ["val1", "val2"])  # Multi-select
client.select("dropdown", "Option Text", by_label=True)

# Checkbox/radio
client.check("checkbox")
client.uncheck("checkbox")
client.toggle("checkbox")

# Focus
client.focus("input")
client.blur("input")

# Scroll
client.scroll("container", direction="down", amount=100)
client.scroll("container", to_element="#target")

Component Actions

Components expose high-level actions that can orchestrate multiple element interactions:

# Get component control
login_form = client.component("login-form")

# Execute action
result = login_form.action("submit", {
    "email": "user@example.com",
    "password": "secret"
})

# Alternative syntax
result = login_form("submit", params)

Workflows

Workflows are pre-defined multi-step automations:

# Run a workflow
result = client.workflow("checkout").run({
    "product_id": "123",
    "quantity": 2
})

# Check status
print(result.status)  # completed, failed, etc.
print(result.steps)   # Individual step results

Discovery

Find controllable elements in the UI:

# Discover all interactive elements
response = client.discover(interactive_only=True)
for element in response.elements:
    print(f"{element.id}: {element.type} - {element.actions}")

# Filter by type
response = client.discover(types=["button", "input"])

# Get full snapshot
snapshot = client.get_snapshot()

Render Logging

Capture and analyze DOM state:

# Capture snapshot
client.render_log.snapshot()

# Get entries
entries = client.render_log.get(limit=10)

# Filter by type
entries = client.render_log.get(entry_type="snapshot")

# Clear log
client.render_log.clear()

Debug Tools

# Get action history
history = client.get_action_history(limit=50)

# Get performance metrics
metrics = client.get_metrics()
print(f"Success rate: {metrics.success_rate * 100}%")
print(f"Average duration: {metrics.avg_duration_ms}ms")

# Highlight an element (visual debugging)
client.highlight_element("submit-btn")

Wait Options

Most actions support wait options:

client.click("btn",
    wait_visible=True,   # Wait for element to be visible
    wait_enabled=True,   # Wait for element to be enabled
    timeout=10000        # Timeout in milliseconds
)

Error Handling

from ui_bridge import UIBridgeClient, ElementNotFoundError, ActionFailedError

client = UIBridgeClient()

try:
    client.click("non-existent-btn")
except ElementNotFoundError:
    print("Element not found")
except ActionFailedError as e:
    print(f"Action failed: {e}")

Context Manager

with UIBridgeClient("http://localhost:9876") as client:
    client.click("btn")
    # Client is automatically closed

Async Support

For async applications, use httpx's async client:

import httpx
from ui_bridge.types import ActionResponse

async def main():
    async with httpx.AsyncClient() as http_client:
        response = await http_client.post(
            "http://localhost:9876/ui-bridge/control/element/btn/action",
            json={"action": "click"}
        )
        result = ActionResponse.model_validate(response.json()["data"])

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

ui_bridge_python-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

ui_bridge_python-0.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ui_bridge_python-0.1.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for ui_bridge_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f18593d3c78f690f015cefd08142fe4e7ab6bdda29d7bad9fd574d4cf7e5d5e4
MD5 78a60d988cf417f3397b079fec1a0196
BLAKE2b-256 fad65be7e1f5ae6dd6ab4bf6d540bc3043d530e5f3b19323b7d810a35d00b1d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ui_bridge_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3a994542ba273a834911a6795bff7a6a3bae12457e3e37914c740b6e6c337bb
MD5 26a7862e9d811617184cce6f4a23f627
BLAKE2b-256 3083843ffe1501c8e3e6d1053fe695a8cebee0ec8780316e3c84b04e15e8fb71

See more details on using hashes here.

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