Skip to main content

A Python client library to communicate with a Dart VM Service gRPC server for controlling Flutter applications

Project description

Dart VM Service Client

A Python client library to communicate with a Dart VM Service gRPC server for controlling Flutter applications.

Installation

  1. Install dependencies using pip:
pip install -r requirements.txt
  1. Ensure you have the Dart SDK installed on your system

    • The client can automatically find Dart in your PATH
    • Alternatively, you can specify the path to the Dart executable
  2. If needed, generate the Python gRPC code:

python -m grpc_tools.protoc -I./protos --python_out=. --grpc_python_out=. ./protos/dart_vm_service.proto

This will create the following files:

  • dart_vm_service_pb2.py
  • dart_vm_service_pb2_grpc.py

Usage

Basic Usage

from dart_vm_client import DartVmClient

# Create a client and start the Dart VM Service automatically
with DartVmClient() as client:
    # Connect to a Flutter app
    response = client.connect("ws://127.0.0.1:8181/ws")
    print(f"Connection status: {response.success}, Message: {response.message}")
    
    if response.success:
        # Interact with the app
        client.tap_widget_by_text("Login")
        
        # Enable debug features
        client.toggle_debug_paint(enable=True)
        client.toggle_performance_overlay(enable=True)

# Service is automatically stopped when exiting the "with" block

Manual Service Management

from dart_vm_client import DartVmClient, DartVmServiceClient, DartVmServiceManager

# Start the service separately
service_manager = DartVmServiceManager(port=8080)
if service_manager.start():
    # Create a client that connects to the running service
    client = DartVmServiceClient("localhost:8080")
    
    try:
        # Use the client...
        client.connect("ws://127.0.0.1:8181/ws")
        
    finally:
        # Clean up
        client.close()
        service_manager.stop()

Available Methods

The client provides numerous methods for interacting with Flutter apps, including:

Connection Management

  • connect(vm_service_uri): Connect to a Flutter app VM service
  • close(): Close the connection

Debug Visualization

  • toggle_debug_paint(enable=True): Toggle debug painting
  • toggle_repaint_rainbow(enable=True): Toggle repaint rainbow
  • toggle_performance_overlay(enable=True): Toggle performance overlay
  • toggle_baseline_painting(enable=True): Toggle baseline painting
  • toggle_debug_banner(enable=True): Toggle debug banner

Widget Interaction

  • tap_widget_by_key(key_value): Tap a widget by key
  • tap_widget_by_text(text): Tap a widget by text
  • enter_text(key_value, text): Enter text in a widget by key
  • scroll_into_view_by_key(key_value, alignment=0): Scroll a widget into view by key

Inspection

  • dump_widget_tree(): Get the widget tree
  • dump_layer_tree(): Get the layer tree
  • dump_render_tree(): Get the render tree
  • toggle_inspector(enable=True): Toggle the inspector

And many more. See the dart_vm_service_client.py file for a complete list of available methods.

Example

See example_usage.py for a more detailed example of how to use the client.

Custom Server Address

If your gRPC server is running on a different host or port, specify it when creating the client:

client = DartVmServiceClient(server_address="192.168.1.100:8080")

Error Handling

Use try/except to handle gRPC errors:

import grpc
from dart_vm_service_client import DartVmServiceClient

client = DartVmServiceClient()

try:
    response = client.connect("ws://127.0.0.1:8181/")
    # Your code here
except grpc.RpcError as e:
    print(f"RPC Error: {e.code()}, {e.details()}")
finally:
    client.close()

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

dart_vm_client-0.0.1.dev3.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

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

dart_vm_client-0.0.1.dev3-py3-none-any.whl (1.8 MB view details)

Uploaded Python 3

File details

Details for the file dart_vm_client-0.0.1.dev3.tar.gz.

File metadata

  • Download URL: dart_vm_client-0.0.1.dev3.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for dart_vm_client-0.0.1.dev3.tar.gz
Algorithm Hash digest
SHA256 1a5f4b12a35256eea0933edd7a5c5077ec7fad58e6e809873a7cfb4049ec6c2f
MD5 79f5cd82481a1e7e6656ad7186b60381
BLAKE2b-256 f8a566a151cc9a955e83b75dc1b7171b0a2f3e26dc141f59c0ed2744676459ea

See more details on using hashes here.

File details

Details for the file dart_vm_client-0.0.1.dev3-py3-none-any.whl.

File metadata

File hashes

Hashes for dart_vm_client-0.0.1.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 7c99bd3624a31aaae6c6e66eba0ccb3d3347fb0aec31768ecabcfeeff1ac5b5b
MD5 430ca9427bdce9a22f2d6f3cd1a37b66
BLAKE2b-256 285c9a665e01894e0bba4964e3ea32c36bca452a6f644a404620f4a036b1fce2

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