Skip to main content

Python SDK for Browser RPC System

Project description

RPC SDK

Python SDK for Browser RPC System.

Installation

pip install rpc-sdk

Or install from source:

cd src/sdk-python
pip install -e .

Quick Start

Basic Usage

from rpc_sdk import RPCClient, RPCAdmin

# Initialize client with node ID
client = RPCClient(
    endpoint='https://rpc-gateway.pub2022.workers.dev',
    node='browser-abc123'
)

# Call platform methods
profile = client.call('douyin.getUserProfile', ['user123'])
print(f"User: {profile['nickname']}, Followers: {profile['followers']}")

# Like a video
result = client.call('douyin.likeVideo', ['video123'])

# Post on Facebook
client.call('facebook.post', ['Hello World!'])

Browser Capabilities

# Get agent info
info = client.agent.getInfo()
print(f"Node: {info['nodeId']}, Type: {info['agentType']}")

# Cookie management
cookies = client.agent.getCookies('douyin.com')
client.agent.setCookies('douyin.com', [
    {'name': 'session', 'value': 'xxx', 'domain': '.douyin.com'}
])
client.agent.clearCookies('douyin.com')

# Tab management
tabs = client.agent.getTabs()
client.agent.openTab('https://douyin.com')
client.agent.switchTab(tabs[0]['id'])

# Screenshot
result = client.agent.screenshot()
# result['dataUrl'] contains base64 PNG

Admin Operations

admin = RPCAdmin(endpoint='https://rpc-gateway.pub2022.workers.dev')

# List all online nodes
nodes = admin.list_nodes()
for node in nodes:
    print(f"{node['nodeId']}: {node['envType']}/{node['agentType']} - {'online' if node['online'] else 'offline'}")

# Filter by environment or service
browser_nodes = admin.list_nodes(env_type='browser')
douyin_nodes = admin.list_nodes(service='douyin')

# Check node status
status = admin.get_node_status('browser-abc123')
print(f"Online: {status['online']}, Last seen: {status['lastSeen']}")

# List available services
services = admin.list_services()
for svc in services:
    print(f"{svc['name']}: {svc['online']}/{svc['total']} nodes online")

# Disconnect a node
admin.delete_node('browser-abc123')

Error Handling

from rpc_sdk import RPCClient, NodeOfflineError, MethodNotFoundError, ExecutionError

client = RPCClient(endpoint='...', node='browser-abc123')

try:
    result = client.call('douyin.sendMessage', ['user123', 'Hello'])
except NodeOfflineError as e:
    print(f"Node {e.node_id} is offline")
except MethodNotFoundError as e:
    print(f"Method {e.method} not found")
except ExecutionError as e:
    print(f"Execution failed: {e.message}")

Custom Timeout

# Global timeout (milliseconds)
client = RPCClient(endpoint='...', node='...', timeout=60000)

# Per-call timeout
result = client.call('douyin.uploadVideo', ['video_path'], timeout=120000)

API Reference

RPCClient

Method Description
call(method, params, timeout) Call a remote method
agent.getInfo() Get agent information
agent.getCookies(domain) Get cookies for domain
agent.setCookies(domain, cookies) Set cookies
agent.clearCookies(domain) Clear cookies
agent.getTabs() Get all tabs
agent.openTab(url, active) Open new tab
agent.closeTab(tabId) Close tab
agent.switchTab(tabId) Switch to tab
agent.navigate(url, tabId) Navigate to URL
agent.getCurrentUrl(tabId) Get current URL
agent.screenshot(tabId) Take screenshot

RPCAdmin

Method Description
list_nodes(env_type, service) List nodes with optional filters
get_node(node_id) Get node details
get_node_status(node_id) Get node online status
delete_node(node_id) Disconnect node
list_services() List all services

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

mp_rpc_sdk-1.0.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file mp_rpc_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mp_rpc_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for mp_rpc_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8773dad4c79474e4c5568415be05705f947ac2d4c2638aa26b33baa54fb74991
MD5 dad52c2857ebe5c5e4fc022185902e2e
BLAKE2b-256 83c153d508c836dca54048709a916db78f0d53864244be9fb7a1302e9502a5c4

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