Logo of LexmountLexmount Docs
Logo of LexmountLexmount Docs
Homepage

Introduction

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

Python Examples

Explain Python examples by quickstart flow, use case, command, and expected result.

Read the examples from basic to advanced. Start with demo.py to confirm that the SDK can create a session and connect to the remote browser. Then choose View debugging, downloads, context, extensions, proxy, or light mode based on your scenario.

Before running examples

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

cp .env.example .env
# Fill LEXMOUNT_API_KEY and LEXMOUNT_PROJECT_ID

Common .env fields:

LEXMOUNT_API_KEY=sk_...
LEXMOUNT_PROJECT_ID=project_...
LEXMOUNT_BASE_URL=https://api.lexmount.cn

Recommended order

OrderExamplePurpose
1demo.pyMinimal loop: create session, connect browser, visit page
2inspect_url_demo.pyKeep remote View open while debugging
3session_list.pyList current and historical sessions
4session_downloads.pyRetrieve files downloaded by the remote browser
5context_basic.pyPersist and reuse browser context
6extension_basic.pyUpload and mount Chrome extension
7proxy_demo.pyCreate session with custom proxy
8light_demo.pyUnderstand light browser mode for content extraction

demo.py: minimal browser loop

Run:

python3 demo.py

What it does:

  1. Initializes Lexmount() from environment variables.
  2. Calls client.sessions.create() to create one cloud browser.
  3. Uses session.connect_url to connect through Playwright CDP.
  4. Opens a page, reads the title, and saves a screenshot.
  5. Closes the browser connection and session.

Use this to confirm that the API Key is valid, quota is available, and Playwright can control the remote browser.

inspect_url_demo.py: keep remote View open

Run:

python3 inspect_url_demo.py

It prints inspect_url and keeps the session alive until you press enter. This maps to the View step in the console quickstart and helps debug:

  • whether the page opens in the remote browser;
  • where the agent or script currently is;
  • whether a human needs to copy, paste, or click.

session_list.py: inspect project sessions

Run:

python3 session_list.py

Use it to:

  • check whether browsers were not released;
  • inspect active and closed sessions;
  • verify instance count during parallel task debugging.

session_downloads.py: retrieve downloaded files

Run:

python3 session_downloads.py

Downloaded files live in the remote browser, not on your local machine. This example shows the full path:

  1. Configure download behavior through CDP.
  2. Trigger a file download in the remote page.
  3. Query downloads through the SDK.
  4. Fetch one file or archive all downloads.

Use this for agent tasks that produce PDF, CSV, ZIP, or other downloaded artifacts.

context_basic.py: reuse browser context

Run:

python3 context_basic.py

Context stores browser data such as cookies, login state, and local storage. Use it when tasks need to reuse state across runs.

Note that a context can be locked by an active session. Parallel tasks should handle lock and release behavior.

extension_basic.py: upload and mount extension

Run:

python3 extension_basic.py

It shows how to:

  • upload an extension zip;
  • list uploaded extensions;
  • mount extensions with extension_ids when creating a session.

Only use this layer when the browser task depends on Chrome extension behavior.

proxy_demo.py: custom proxy

Run:

python3 proxy_demo.py

It shows how to pass proxy when creating a session. Use it for upstream proxy, regional egress, or authenticated proxy scenarios.

light_demo.py: light browser mode

Run:

python3 light_demo.py

This example explains light browser usage for content extraction scenarios. It is not the first demo to run; read it after demo.py and inspect_url_demo.py both work.

Troubleshooting

Authentication failed

Check that .env contains LEXMOUNT_API_KEY and LEXMOUNT_PROJECT_ID, and that the Project ID belongs to the same project as the API Key.

Playwright cannot connect

Print both session.connect_url and session.inspect_url. If View opens but CDP cannot connect, check network access, base URL, and whether the session was already closed.

Session was not released

Prefer context managers:

with client.sessions.create() as session:
    ...

This gives the SDK a chance to release the session even if the script fails.

Capabilities

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

Node.js SDK

Import-ready Lexmount Node.js SDK documentation for Lex Home.

Table of Contents

Before running examples
Recommended order
demo.py: minimal browser loop
inspect_url_demo.py: keep remote View open
session_list.py: inspect project sessions
session_downloads.py: retrieve downloaded files
context_basic.py: reuse browser context
extension_basic.py: upload and mount extension
proxy_demo.py: custom proxy
light_demo.py: light browser mode
Troubleshooting
Authentication failed
Playwright cannot connect
Session was not released