Skip to main content

Python SDK for automating browser sessions via Webfuse

Project description

Webfuse Python SDK

A Python client for automating browser sessions via the Webfuse RPC service.

Installation

pip install webfuse

Quick Start

from webfuse import WebfuseClient

# Initialize the client with your API key
client = WebfuseClient(api_key="rk_your_api_key")

# Create a browser session
session = client.create_session(space_id="1234")

# Automate the browser
session.goto("https://example.com")
session.click("#login-button")
session.type("#username", "user@example.com")
session.type("#password", "secret123")
session.click("#submit")

# Take a screenshot
screenshot = session.screenshot()
with open("result.png", "wb") as f:
    f.write(screenshot)

# End the session when done
session.end()

# Don't forget to close the client
client.close()

Using Context Managers

from webfuse import WebfuseClient

with WebfuseClient(api_key="rk_your_api_key") as client:
    session = client.create_session(space_id="1234")
    session.goto("https://example.com")
    session.click("button.submit")
    session.end()

Async Support

import asyncio
from webfuse import AsyncWebfuseClient

async def main():
    async with AsyncWebfuseClient(api_key="rk_your_api_key") as client:
        session = await client.create_session(space_id="1234")

        await session.goto("https://example.com")
        await session.click("#button")
        await session.type("#input", "Hello World")

        screenshot = await session.screenshot()

        await session.end()

asyncio.run(main())

Available Methods

Navigation

  • session.goto(url, new_tab=False) - Navigate to a URL
  • session.open_tab(url) - Open a new browser tab

Mouse Actions

  • session.click(selector) - Left-click an element
  • session.right_click(selector) - Right-click an element
  • session.middle_click(selector) - Middle-click an element
  • session.hover(selector) - Move mouse to element
  • session.scroll(selector, amount, direction="vertical") - Scroll an element

Keyboard Actions

  • session.type(selector, text) - Type text into an input
  • session.press(selector, key, modifiers=None) - Press a keyboard key

Screenshots & DOM

  • session.screenshot() - Take a screenshot (returns PNG bytes)
  • session.dom_snapshot() - Get text representation of the DOM

Utilities

  • session.wait(ms) - Wait for specified milliseconds
  • session.get_functions() - List available automation functions

Session Management

  • session.end() - End the session
  • session.is_active - Check if session is still active

Configuration

client = WebfuseClient(
    api_key="rk_your_api_key",
    rpc_url="https://rpc.webfuse.com",  # Custom RPC URL
    timeout=60.0,  # Request timeout in seconds
)

Error Handling

from webfuse import WebfuseClient, WebfuseError, AuthenticationError, AutomationError

try:
    with WebfuseClient(api_key="rk_your_api_key") as client:
        session = client.create_session(space_id="1234")
        session.click("#nonexistent-element")
except AuthenticationError:
    print("Invalid API key")
except AutomationError as e:
    print(f"Automation failed: {e.message}")
except WebfuseError as e:
    print(f"Error: {e.message}")

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

webfuse-0.0.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

webfuse-0.0.1-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file webfuse-0.0.1.tar.gz.

File metadata

  • Download URL: webfuse-0.0.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for webfuse-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9de86ba702822cd81a57d60563790a6141ba41facb3a54555b92ac516ebb8099
MD5 545ff7d5204293b48b03462e0a72d4bf
BLAKE2b-256 97d52e10485fa702c19f9f30a4199c626ecf55ac24ec5f3fb452b3b3447d42a0

See more details on using hashes here.

File details

Details for the file webfuse-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: webfuse-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for webfuse-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0cae520d9fc4a8edb3415690ed269e2ca127d82c3d94f0c36fb5f1ad95f9bc9e
MD5 143ea085f3d778661b66996835d9178b
BLAKE2b-256 cd0fa1b9600db3a93e590fa069fa50e5691c4dfdb33d1bb8809ce8645241d52b

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