Python SDK Quick Start
Connect to a cloud browser through API Key, Session, View verification, and Playwright CDP.
This page follows the same path as the product Quick Start: prepare API Key and Project ID, create a session, verify the remote View, then connect to the cloud browser with Playwright over CDP.
Verify the console flow first
If you have not created an API Key yet, finish Quick Start in the console first. The SDK code below uses the same Project ID and API Key.
1. Install dependencies
python3 -m venv .venv
source .venv/bin/activate
pip install lexmount==0.5.16 playwright python-dotenv
playwright install chromiumIf you are using the quickstart example repository, install its dependencies instead:
pip install -r requirements.txt2. Configure credentials
Use environment variables or a .env file so API keys do not appear in source code.
export LEXMOUNT_API_KEY="sk_..."
export LEXMOUNT_PROJECT_ID="project_..."
# Optional for test environments
export LEXMOUNT_BASE_URL="https://api.lexmount.cn"| Field | Where to get it | Purpose |
|---|---|---|
LEXMOUNT_API_KEY | Settings / API Keys | SDK authentication |
LEXMOUNT_PROJECT_ID | Same API Key page | Selects the project that owns the session |
LEXMOUNT_BASE_URL | Environment config | Points to production or test API service |
3. Create one cloud browser session
from lexmount import Lexmount
client = Lexmount()
with client.sessions.create(browser_mode="normal") as session:
print("session id:", session.id)
print("view url:", session.inspect_url)
print("connect url:", session.connect_url)This maps to “create session” in the console:
session.id: the cloud browser instance ID used for listing, stopping, and downloads.session.inspect_url: the remote View URL for observing the browser screen.session.connect_url: the CDP endpoint used by Playwright / Puppeteer.
4. Connect with Playwright and navigate
from lexmount import Lexmount
from playwright.sync_api import sync_playwright
client = Lexmount()
with client.sessions.create(browser_mode="normal") as session:
with sync_playwright() as p:
browser = p.chromium.connect_over_cdp(session.connect_url)
context = browser.contexts[0] if browser.contexts else browser.new_context()
page = context.pages[0] if context.pages else context.new_page()
page.goto("https://example.com", wait_until="domcontentloaded")
print("title:", page.title())
browser.close()This is the SDK version of “View navigation”:
- The SDK creates a cloud browser session.
- Playwright connects to the remote browser through
connect_url. - Code runs
goto, reads page state, and performs browser actions remotely. - The session is released when the context manager exits.
5. Enable downloads or replay storage
Downloads and replay storage are opt-in. Enable only the artifact type that the task needs.
download_session = client.sessions.create(
browser_mode="normal",
downloads={"enabled": True},
)
with sync_playwright() as p:
browser = p.chromium.connect_over_cdp(download_session.connect_url)
cdp = browser.new_browser_cdp_session()
cdp.send(
"Browser.setDownloadBehavior",
{
"behavior": "allow",
"downloadPath": "/config/Downloads",
"eventsEnabled": True,
},
)
replay_session = client.sessions.create(
browser_mode="normal",
recording={"persistent": True},
)Use client.sessions.downloads.list/get/archive after a download-enabled session produces files. Use the console session detail page after a recording-enabled session closes to inspect replay output.
6. How examples map to quickstart
| Example | Quickstart step | When to use it |
|---|---|---|
demo.py | Create session, connect browser, visit page | First SDK smoke test |
inspect_url_demo.py | Create session, open View, keep the browser visible | Debug while watching the remote browser |
session_list.py | Inspect session state | Check which browsers are running in the project |
session_downloads.py | Retrieve files downloaded by the remote browser | Browser tasks that produce downloaded files |
context_basic.py | Reuse browser context | Persist login state or browser data |
extension_basic.py | Mount extension during session creation | Browser tasks that require Chrome extensions |
proxy_demo.py | Create session with proxy | Tasks that need a custom upstream proxy |
See Python Examples for detailed explanations.
Common questions
Why verify in the console first?
The console shows credentials, project, session, View, and connection entries in one place. Running it manually first tells you whether the issue is account setup, browser startup, or code connection.
When does a session end?
Sessions are managed by the platform. Close them when a task is done. If a configured timeout is reached, cleanup considers recent CDP activity before reclaiming the browser.
Do View and Playwright conflict?
No. View is for observation and manual takeover. Playwright uses connect_url to control the same remote browser. During debugging, you can run code and watch the page through View at the same time.
Lexmount Docs