Skip to main content

Unofficial Feishu/Lark Web SDK - WebSocket listener, message search, send, and drive operations

Project description

lark-bridge

Unofficial Feishu/Lark Web SDK using cookie-based authentication. Provides real-time message listening via WebSocket, message search/fetch, sending, and Drive operations.

⚠️ This library is reverse-engineered from Feishu's web client. It is not an official API and may break without notice.

Installation

pip install lark-bridge

Quick Start

import asyncio
from lark_bridge import LarkBridge

bridge = LarkBridge("your_cookie_string_here")

# For enterprise tenants with custom domain:
bridge = LarkBridge("your_cookie_string_here", domain="yourcompany.feishu.cn")

Listen to Messages

async def main():
    async for msg in bridge.listen(watch_chats=["chat_id"]):
        print(f"[{msg['chat_id']}] {msg['from_id']}: {msg['text']}")

asyncio.run(main())

Search History

# Simple: auto-paginate up to limit
result = await bridge.search_messages(
    chat_id="7052636707732193282",
    start_time=1716192000,
    end_time=1716278400,
    limit=50,
)
print(result["msg_ids"])

# Manual pagination:
page = await bridge.search_messages_page(chat_id="7052636707732193282")
while page["has_more"]:
    page = await bridge.search_messages_page(
        chat_id="7052636707732193282",
        page_token=page["page_token"],
    )
    print(page["msg_ids"])

Fetch Messages

messages = await bridge.fetch_messages(["msg_id_1", "msg_id_2"])
for msg in messages:
    print(msg["text"])
# Each message dict contains:
# msg_id, type, from_id, chat_id, chat_type, parent_id, root_id, create_time, text
# chat_type: 0=unknown, 1=P2P(private), 2=GROUP, 3=TOPIC_GROUP

Send Message

await bridge.send_message(
    chat_id="7052636707732193282",
    text="Hello!",
    reply_id="optional_msg_id",
    at_user_ids=["user_id"],
)

Drive Operations

folder = await bridge.create_folder("My Folder", parent_token="root_token")
# folder = {"token": "...", "url": "https://domain/drive/folder/..."}

result = await bridge.upload_file(folder["token"], "report.txt", b"file content")
# result = {"file_token": "...", "node_token": "...", "url": "https://domain/file/..."}

Export Document

# Export a docx/wiki page as markdown
content = await bridge.export_document(
    token="GSeJdHQbQo3b2jxg8CYc1Zqqnah",
    type="docx",              # "docx" | "sheet" | "doc"
    file_extension="markdown",  # "markdown" | "docx" | "pdf" | "xlsx" | "csv"
)
if content:
    Path("output.md").write_bytes(content)

Supported combinations:

  • type="docx" (wiki/docx pages) → markdown, docx, pdf
  • type="sheet" → xlsx only

MCP Server

Expose lark-bridge as an MCP server so AI clients (Claude Desktop, Cursor, Kiro, etc.) can call Feishu tools directly.

Install

pip install lark-bridge[mcp]

Run

FEISHU_COOKIE="your_cookie_string" lark-bridge-mcp

For enterprise tenants with a custom domain:

FEISHU_COOKIE="your_cookie_string" FEISHU_DOMAIN="yourcompany.feishu.cn" lark-bridge-mcp

If your cookie changes frequently, use a file instead of an environment variable. The server reads the file on every tool call, so updates take effect immediately without restarting:

FEISHU_COOKIE_FILE="/path/to/cookie.txt" lark-bridge-mcp

MCP Client Config

{
  "mcpServers": {
    "lark-bridge": {
      "command": "lark-bridge-mcp",
      "env": {
        "FEISHU_COOKIE": "your_cookie_string"
      }
    }
  }
}

Available tools: send_message, search_messages, fetch_messages, create_folder, upload_file.

Cookie Setup

  1. Open Feishu Web in your browser and log in
  2. Open DevTools (F12) → Application → Cookies
  3. Copy the full cookie string (all key=value pairs joined by ; )
  4. Pass it to LarkBridge("your_cookie_string")

Example cookie format:

cookie = "passport_web_did=YOUR_DID; session=YOUR_SESSION; _csrf_token=YOUR_CSRF_TOKEN"

bridge = LarkBridge(cookie)

Cookie typically stays valid as long as the WebSocket connection is maintained.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lark_bridge-0.3.0.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lark_bridge-0.3.0-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

Details for the file lark_bridge-0.3.0.tar.gz.

File metadata

  • Download URL: lark_bridge-0.3.0.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lark_bridge-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4a4cd570d031e1c2b59c1e03144334487360a1bb6e727f8c17f3f1ec1706b839
MD5 3768d4bed52b7062bf71343bee8ffd1b
BLAKE2b-256 0a09a1c13bb785c67a0b3c46ddbf3572ab4e846fd83cae7fb3a081fffd4d7939

See more details on using hashes here.

Provenance

The following attestation bundles were made for lark_bridge-0.3.0.tar.gz:

Publisher: publish.yml on ryanwx/lark-bridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lark_bridge-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lark_bridge-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 30.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lark_bridge-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9302c98920f0a13e0f40baddc178dff4fab72be06c0b79af9246b80d30aa6594
MD5 37949b90be0c89e7c8e328e9db7ea9a9
BLAKE2b-256 a2d5dba0cea118f1aeb1f1880bbd8f93ce32f344523e4359b8799d0486d71f75

See more details on using hashes here.

Provenance

The following attestation bundles were made for lark_bridge-0.3.0-py3-none-any.whl:

Publisher: publish.yml on ryanwx/lark-bridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page