surfsky package:
SURFSKY_API_TOKEN and SURFSKY_API_BASE_URL from the dashboard. See credential setup. You can also pass api_token and base_url to the client constructor.
Start a browser
Save asfirst_browser.py and run python first_browser.py:
Example Domain. The browser context manager stops the session on exit, including when a page operation raises an exception. Cleanup still requires a running process and a working API connection.
AsyncSurfsky provides browser automation and asynchronous REST calls. The synchronous Surfsky client provides REST calls and managed sessions for use with other browser frameworks.
Interact with the page
Page operations run inside theclient.browser() block. Common methods include goto, click, type, hover, inner_text, and wait_for_selector. Wait timeouts are in seconds and default to 30; expiration raises BrowserTimeoutError.
Use selectors from your target page. For example, in a form with an email field:
evaluate() executes JavaScript. It uses an isolated execution context by default; pass isolated=False when the script needs variables defined by the page. The DOM is shared, so page code can observe DOM changes made by your script.
Save traffic
Passblock_resources when starting the browser:
Capture a page’s API response
Start capture before the request occurs. Adapt the URL and matching path to your application:Multiple tabs
browser operates on the first tab. browser.pages includes other tabs and popups:
Running many browsers
This example runs two jobs concurrently and reports each outcome:browser.retire() to replace it after the current lease when a job needs a fresh identity.
For manual leasing:
Proxies
Pass a proxy choice tobrowser() or session():
client.proxies exposes location lookups and quota calls. See Proxies for tier availability and targeting rules.
Sessions
By default,client.browser() starts a one-time session whose state is discarded when it stops. To reuse login state, cookies, and local storage across runs, create a persistent profile and pass its UUID to client.browser(profile_uuid=...).
Save this as reuse_session.py. On the first run it creates a profile and saves its UUID in profile-uuid.txt. Later runs read that UUID and restore the same profile:
python reuse_session.py twice from the same directory, waiting for each run to finish. The first run prints Previous run: None; the second prints Previous run: saved. Surfsky stores the browser state; the local file stores only the profile UUID.
The browser context manager stops the session and saves the selected browser state on exit. To reuse a login, replace the example page operations with your site’s sign-in flow on the first run, then open an authenticated page on later runs.
Use Playwright
Useclient.session() to let the SDK manage the session while Playwright handles page operations. Install surfsky and playwright, and set the environment variables before running this example:
Raw requests
request() returns an httpx.Response. Unlike resource methods, it does not raise for an HTTP error unless you call raise_for_status().
The SDK repository includes the full method reference and additional examples.