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.
Profiles
Create a profile and save its UUID for later use:AsyncSurfsky client context. Start the same UUID on subsequent runs; do not create a new profile for each job. Sessions describes the login-and-reuse workflow.
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.