Python Quick Start
Create Chromium and Moli sessions and connect to Chromium with Playwright.
Prepare credentials first
Create an API Key and copy its Project ID from Settings → API Keys. You can verify the same flow in the console quick start before running code.
1. Install
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade lexmount playwright python-dotenv
playwright install chromium2. Configure credentials
export LEXMOUNT_API_KEY=<your-api-key>
export LEXMOUNT_PROJECT_ID=<your-project-id>
# Optional; defaults to the CN API
export LEXMOUNT_BASE_URL=https://api.lexmount.cnUse https://api.lexmount.com for the global service. Never commit the API Key to source control.
3. Create and control Chromium
from lexmount import Lexmount
from playwright.sync_api import sync_playwright
with Lexmount() as client:
with client.sessions.create(browser_mode="normal") as session:
print("session:", session.id)
print("view:", session.inspect_url)
with sync_playwright() as p:
browser = p.chromium.connect_over_cdp(session.connect_url)
context = browser.contexts[0]
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()The context managers close the HTTP client and session even if browser code raises an exception.
4. Create Moli
Moli is the product name for the stable SDK/API value light:
from lexmount import Lexmount
with Lexmount() as client:
with client.sessions.create(browser_mode="light") as session:
print(session.id)
print(session.inspect_url)Use Moli for lightweight agent browsing and content-oriented tasks. Persistent replay is always disabled for Moli. Use Chromium when a task depends on the full persistent-browser feature set.
5. Know the defaults
| Behavior | Current default |
|---|---|
| Session create path | Async create, polling until active |
| Activation timeout | 600 seconds |
| Stored downloads | Enabled unless downloads={"enabled": False} |
| Chromium persistent replay | Enabled by the current platform unless explicitly disabled |
| Moli persistent replay | Always disabled |
| Region | Default catalog region when available; otherwise the configured base URL |
Explicitly disable artifacts that the task does not need:
session = client.sessions.create(
browser_mode="normal",
downloads={"enabled": False},
recording={"persistent": False},
)6. Select a region
from lexmount import Lexmount
client = Lexmount(region="<region-id>")
print(client.region_info())
print(client.catalog_info())
client.close()If catalog lookup or host probing is unavailable, the SDK falls back to LEXMOUNT_BASE_URL.
Troubleshooting
- Authentication error: confirm the API Key and Project ID come from the same project.
- Create timeout: inspect the exception and console session list before retrying; async create may already have reserved a session ID.
- View works but Playwright does not connect: confirm the session is still active and that your network can reach
session.connect_url. - Resources remain active: use nested context managers or close the session in
finally.
Continue with Python Capabilities or run a script from Python Examples.
Lexmount Browser