Hyperbrowser Python SDK

0.90.3 · active · verified Thu Apr 16

Hyperbrowser Python SDK is a client library for interacting with the Hyperbrowser platform, offering cloud-based headless browser automation. It enables developers to perform advanced web scraping, create AI-driven browser agents, and manage scalable browser sessions with built-in features like CAPTCHA solving, proxy management, and anti-bot detection. The library provides both synchronous and asynchronous clients for flexible integration, with frequent updates to its `0.90.x` series.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an asynchronous Hyperbrowser session, connect to the remote browser using `puppeteer_core` (ensure it's installed via `pip install puppeteer-core`), navigate to a page, and then properly close the session. The `HYPERBROWSER_API_KEY` is retrieved from environment variables for secure authentication. You can also use `playwright-core` and `connect_over_cdp` instead of `puppeteer_core` and `connect` respectively.

import asyncio
import os
from hyperbrowser import AsyncHyperbrowser
from puppeteer_core import connect # Or from playwright_core import connect_over_cdp

async def main():
    hyperbrowser_api_key = os.environ.get('HYPERBROWSER_API_KEY', '')
    if not hyperbrowser_api_key:
        print("Error: HYPERBROWSER_API_KEY environment variable not set.")
        print("Please get your API key from https://app.hyperbrowser.ai/dashboard and set it.")
        return

    async with AsyncHyperbrowser(api_key=hyperbrowser_api_key) as client:
        print("Creating Hyperbrowser session...")
        session = await client.sessions.create()
        print(f"Session created: {session.id}, WS Endpoint: {session.ws_endpoint}")

        try:
            # Connect to the remote browser using puppeteer_core (or playwright_core)
            browser = await connect(browserWSEndpoint=session.ws_endpoint, defaultViewport=None)
            page = (await browser.pages())[0]

            print("Navigating to example.com...")
            await page.goto("https://example.com")
            page_title = await page.title()
            print(f"Page title: {page_title}")

            await page.close()
            await browser.disconnect()
        except Exception as e:
            print(f"Error during browser interaction: {e}")
        finally:
            print(f"Stopping session {session.id}...")
            await client.sessions.stop(session.id)
            print("Session stopped.")

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →