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_playwrightclient = Rayobrowse(endpoint="https://browser.rayobyte.com", 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()endpointis the gateway you are calling and belongs on every client you build.proxyhas no default either. 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, RateLimitError) as e:time.sleep(e.retry_after) # 5 s for a full account, 60 s for the rate limitA
429, too many running browsers or too many creates in a minute, raises one of these two. Catch both: in 2.2.0 the class does not reliably say which limit was hit.retry_aftercomes from theretry-afterheader and is right for either.
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.