Skip to main content

Unofficial Python SDK for the iLink-compatible Weixin bot protocol.

Project description

wechat-link

Unofficial Python SDK for iLink-compatible Weixin Bot integration.

wechat-link 是一个面向 iLink-compatible Weixin Bot 集成的 Python SDK,重点放在协议层、媒体链路和一个可选的轻量 Relay 上,而不是去做一个大而全的 Bot 平台。

What it currently provides

  • QR login primitives: get_bot_qrcode() / get_qrcode_status()
  • Long polling: get_updates()
  • Text messaging: send_text()
  • Typing support: get_config() / send_typing()
  • Media workflow:
    • get_upload_url()
    • upload_image() / send_image()
    • upload_file() / send_file()
    • upload_video() / send_video()
    • upload_voice() / send_voice()
  • Optional FastAPI relay layer

Installation

pip install wechat-link

Relay extras:

pip install "wechat-link[relay]"

Getting started order

If this is your first time using the SDK, follow this order:

  1. Run QR login first and obtain bot_token
  2. Initialize Client(bot_token=...)
  3. Start polling and sending messages

The SDK returns bot_token, baseurl, ilink_bot_id, and ilink_user_id after QR confirmation. The value you need for Client(...) is bot_token.

For QR display, qrcode_img_content is currently a URL. If that URL points to a QR page instead of a raw image, the SDK generates a real QR locally. Client.save_qrcode_image(...) saves it to a local file, while Client.render_qrcode_terminal(...) / Client.print_qrcode_terminal(...) can render it directly in the terminal.

Minimal usage example

from wechat_link import Client

client = Client(bot_token="your-bot-token")
messages = client.get_updates(cursor="").messages

print("messages:", len(messages))

client.close()

Quick example

from wechat_link import Client, FileCursorStore

client = Client(bot_token="your-bot-token")
store = FileCursorStore(".state/get_updates_buf.json")
cursor = store.load() or ""

updates = client.get_updates(cursor=cursor)
if updates.next_cursor:
    store.save(updates.next_cursor)

for message in updates.messages:
    text = message.text().strip()
    if text and message.from_user_id and message.context_token:
        client.send_text(
            to_user_id=message.from_user_id,
            text=f"echo: {text}",
            context_token=message.context_token,
        )

client.close()

Full three-step example

If you want the full onboarding flow in one runnable file, use:

python examples/quickstart_three_steps.py

The repository version of that example handles QR login, session persistence, and the echo loop end to end. When run from the repository, it prefers local src/wechat_link first and writes runtime files into the repository .state/ directory.

Project links

Notes

  • This is an unofficial project.
  • It should not be described as a Tencent official SDK or official platform replacement.
  • The PyPI page keeps the package overview concise; the full documentation and examples live in the GitHub repository.

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

wechat_link-0.2.1.tar.gz (37.6 kB view details)

Uploaded Source

Built Distribution

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

wechat_link-0.2.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

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