diff --git a/README.md b/README.md index c91cd79..b2adccb 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,16 @@ Quick start examples for Lexmount Python SDK. - Query the public endpoint catalog through `client.catalog_info()` - Print available regions, host, and endpoint IPs +### context_basic.py - Context Description Demo +- Create a context with `description` +- Start a `read_write` session with that context +- Print the context display name and ID + +### context_list_get.py - Context List/Get Demo +- List contexts and print `display_name` +- Get details for a specific context +- Print `description` when present + ### context_fork.py - Context Fork Demo - Accept an existing source `context_id` - Fork it into a new context @@ -103,6 +113,8 @@ cp .env.example .env # 4. Run examples python3 demo.py # Basic demo python3 light_demo.py # Light browser demo +python3 context_basic.py # Context description demo +python3 context_list_get.py # Context list/get demo python3 context_fork.py # Context fork demo python3 extension_basic.py # Extension demo python3 proxy_demo.py # Proxy demo diff --git a/README.zh.md b/README.zh.md index fef7cde..1b2b5fc 100644 --- a/README.zh.md +++ b/README.zh.md @@ -46,6 +46,16 @@ - 通过 `client.catalog_info()` 查询 public endpoint catalog - 打印可用 region、host 和 endpoint IP +### context_basic.py - Context 描述演示 +- 创建带 `description` 的 context +- 使用该 context 启动 `read_write` 会话 +- 打印 context 展示名称和 ID + +### context_list_get.py - Context 列表与详情演示 +- 列出 context 并打印 `display_name` +- 获取指定 context 详情 +- 存在 `description` 时打印描述 + ### context_fork.py - Context Fork 演示 - 传入一个已有的 source `context_id` - 基于 source fork 出新的 context @@ -97,6 +107,8 @@ cp .env.example .env # 4. 运行示例 python3 demo.py # 基础演示 python3 light_demo.py # 轻量浏览器演示 +python3 context_basic.py # Context 描述演示 +python3 context_list_get.py # Context 列表与详情演示 python3 context_fork.py # Context Fork 演示 python3 extension_basic.py # 插件演示 python3 proxy_demo.py # 代理演示 diff --git a/context_basic.py b/context_basic.py index 032af85..5cadb6d 100644 --- a/context_basic.py +++ b/context_basic.py @@ -32,11 +32,13 @@ def main(): print(f"\n1. Using existing context ID: {context_id}") else: context = client.contexts.create( + description="Quickstart login context", metadata={ # add your metadata here } ) context_id = context.id + print(f"\n1. Created context: {context.display_name} ({context_id})") with sync_playwright() as playwright: with client.sessions.create(context={"id": context_id, "mode": "read_write"}) as session: @@ -46,7 +48,7 @@ def main(): context = browser.contexts[0] page = context.pages[0] page.goto("https://www.baidu.com/") - print(f" ✓ Context created with ID: {context_id}") + print(f" ✓ Session created with context: {context_id}") input("\n Press Enter to continue...") except Exception as e: print(f" ✗ Failed to connect to the remote session: {e}") diff --git a/context_list_get.py b/context_list_get.py index 2f69245..c2e3bee 100644 --- a/context_list_get.py +++ b/context_list_get.py @@ -34,8 +34,11 @@ def list_all_contexts(): for ctx in contexts: status_icon = "🔒" if ctx.is_locked() else "✅" - print(f"\n {status_icon} Context ID: {ctx.id}") + print(f"\n {status_icon} Context: {ctx.display_name}") + print(f" ID: {ctx.id}") print(f" Status: {ctx.status}") + if ctx.description: + print(f" Description: {ctx.description}") if ctx.created_at: print(f" Created: {ctx.created_at}") if ctx.updated_at: @@ -51,7 +54,10 @@ def get_context_details(context_id: str): try: ctx = client.contexts.get(context_id) + print(f" Display Name: {ctx.display_name}") print(f" Status: {ctx.status}") + if ctx.description: + print(f" Description: {ctx.description}") if ctx.is_locked(): print(f" 🔒 Locked") else: diff --git a/requirements.txt b/requirements.txt index 398b438..8fe09a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Lexmount SDK -lexmount==0.5.12 +lexmount==0.5.15 # Browser automation playwright>=1.40.0