Python quickstart
-
Install
Terminal window pip install rayobrowse playwrightPython 3.10 or newer. Skip
playwright install: the browser runs on Rayobyte’s side, so there is no local browser to download. -
Launch a browser
from rayobrowse import Rayobrowsefrom playwright.sync_api import sync_playwrightPROXY = "http://USERNAME:PASSWORD@us-east.gw.rayobyte.com:8000"client = Rayobrowse(api_key="rb_live_YOUR_KEY")ws_url = client.connect_url(os="windows", proxy=PROXY)try:with sync_playwright() as p:browser = p.chromium.connect_over_cdp(ws_url)context = browser.contexts[0]page = context.pages[0] if context.pages else context.new_page()page.goto("https://quotes.toscrape.com/")print(page.title()) # Quotes to Scrapefinally:client.close()The client calls
https://browser.rayobyte.comon its own.proxyhas no default, so leaving it out raisesBrowserCreateErrorwithstatus_code400 and abodythat startsA proxy is required for this account.client.close()infinallyends the session even when the page load raises. Playwright’sbrowser.close()only detaches from a browser it did not launch. -
Watch it run
ws_url = client.connect_url(os="windows", proxy=PROXY, vnc=True)print(f"CDP: {ws_url}")print(f"Live: {client.last_vnc_url}") -
Handle the limits
import timefrom rayobrowse import ConcurrencyLimitError, RateLimitErrortry:ws_url = client.connect_url(os="windows", proxy=PROXY)except ConcurrencyLimitError as e:print(f"{e.active}/{e.limit} browsers running")time.sleep(e.retry_after) # 5 secondsexcept RateLimitError as e:time.sleep(e.retry_after) # 60 secondsBoth are a
429and they mean different things.ConcurrencyLimitErroris all your browsers already running, and it carrieslimitandactive.RateLimitErroris more than 60 launches in the last minute.retry_aftercomes from theretry-afterheader and is always a whole number of seconds, never negative.
client.close() closes the browser from the most recent connect_url() call,
or the session id you pass it. Skip it and the session runs until maxLifetime,
7,200 seconds by default, and all of it counts against your browser hours.
Next: Python reference and Limits.
Was this page helpful?
Thanks. That helps us fix it.