Logo of LexmountLexmount Docs
Logo of LexmountLexmount Docs
Homepage

Introduction

Documentation Overview
Python SDKPython SDK Quick StartCapabilitiesPython Examples
X (Twitter)
Python SDK

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 chromium

If you are using the quickstart example repository, install its dependencies instead:

pip install -r requirements.txt

2. 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"
FieldWhere to get itPurpose
LEXMOUNT_API_KEYSettings / API KeysSDK authentication
LEXMOUNT_PROJECT_IDSame API Key pageSelects the project that owns the session
LEXMOUNT_BASE_URLEnvironment configPoints 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”:

  1. The SDK creates a cloud browser session.
  2. Playwright connects to the remote browser through connect_url.
  3. Code runs goto, reads page state, and performs browser actions remotely.
  4. 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

ExampleQuickstart stepWhen to use it
demo.pyCreate session, connect browser, visit pageFirst SDK smoke test
inspect_url_demo.pyCreate session, open View, keep the browser visibleDebug while watching the remote browser
session_list.pyInspect session stateCheck which browsers are running in the project
session_downloads.pyRetrieve files downloaded by the remote browserBrowser tasks that produce downloaded files
context_basic.pyReuse browser contextPersist login state or browser data
extension_basic.pyMount extension during session creationBrowser tasks that require Chrome extensions
proxy_demo.pyCreate session with proxyTasks 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.

Python SDK

Import-ready Lexmount Python SDK documentation for Lex Home.

Capabilities

Session, context, extension, and download capabilities exposed by the Python SDK.

Table of Contents

1. Install dependencies
2. Configure credentials
3. Create one cloud browser session
4. Connect with Playwright and navigate
5. Enable downloads or replay storage
6. How examples map to quickstart
Common questions
Why verify in the console first?
When does a session end?
Do View and Playwright conflict?