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
Metadata
Release files for mp-rpc-sdk 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mp_rpc_sdk-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / mp_rpc_sdk-1.0.0-py3-none-any.whl
| Download URL | mp_rpc_sdk-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8773dad4c79474e4c5568415be05705f947ac2d4c2638aa26b33baa54fb74991
|
|
BLAKE2b-256 checksum How to use checksums |
83c153d508c836dca54048709a916db78f0d53864244be9fb7a1302e9502a5c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|