WeChat iLink bot channel — async Python SDK for WeChat messaging
Project description
wx-channel
wx-channel is an async Python SDK for the WeChat iLink bot channel. It lets you log in via QR code, send/receive messages (text, image, file, video, voice), and build WeChat bots with just a few lines of code.
Features
- QR code login with account persistence
- Receive real-time messages via long-polling (text, image, file, video, voice)
- Send text, image, file messages
- CDN upload/download with AES-ECB encryption
- Multi-handler subscription and async message iterator
- Session management (connect/disconnect with auto-reconnect)
Installation
pip install wx-channel
Or from source:
pip install git+https://github.com/manymore13/wx_channel.git
Quick Start
Login
import asyncio
from wx_channel import WxChannel
async def login():
# Generates a QR code in terminal. Scan with WeChat.
channel = await WxChannel.from_login(timeout_sec=300)
print(f"Logged in as: {channel.bot_id}")
print(f"Wx user: {channel.wx_user_id}")
asyncio.run(login())
Receive messages
import asyncio
from wx_channel import WxChannel, WeixinMessage
async def listen():
channel = await WxChannel.from_saved("your_bot_id")
await channel.connect()
async for msg in channel.messages():
if msg.is_user and msg.is_finished:
print(f"[{msg.from_user_id}] {msg.text}")
asyncio.run(listen())
Send messages
await channel.send_text(to_user_id="wx_user_id", text="Hello from bot!")
await channel.send_image(to_user_id="wx_user_id", file_path="./cat.jpg")
await channel.send_file(to_user_id="wx_user_id", file_path="./doc.pdf")
Handler mode
def on_msg(msg: WeixinMessage):
if msg.is_user and msg.is_finished:
print(f"[{msg.from_user_id}] {msg.text}")
channel.on_message(on_msg)
await channel.connect()
# Messages arrive in real-time via the callback
API Overview
WxChannel
| Method | Description |
|---|---|
WxChannel.from_login() |
QR code login, returns a new channel |
WxChannel.from_saved(bot_id) |
Load saved account by bot_id |
WxChannel.list_accounts() |
List all saved accounts |
channel.connect() |
Start long-polling message loop |
channel.disconnect() |
Stop loop and close connection |
channel.send_text(to, text) |
Send a text message |
channel.send_image(to, path) |
Upload and send an image |
channel.send_file(to, path) |
Upload and send a file |
channel.save_media(item) |
Download and decrypt media from a message |
channel.on_message(handler) |
Subscribe to incoming messages |
channel.messages() |
Async iterator over incoming messages |
Message Types
TextItem— text contentImageItem— image with CDN mediaFileItem— file with CDN mediaVoiceItem— voice recordingVideoItem— video with CDN media
Error Types
LoginFailed— QR login failedLoginTimeout— QR login timed outSessionTimeout— session expired, re-login neededNetworkError— HTTP or CDN errorApiError— iLink API returned an error
Requirements
- Python >= 3.10
- aiohttp >= 3.9.0
- qrcode >= 7.4.0
- Pillow >= 10.0.0
- cryptography >= 41.0.0
License
MIT © manymore13
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
wx_channel-1.0.0.tar.gz
(16.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wx_channel-1.0.0.tar.gz.
File metadata
- Download URL: wx_channel-1.0.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24266ae4c9d92ee179f32b77e816eb16fbc2f1810c8aa04bfd0d580792096d7a
|
|
| MD5 |
5824bb760bad3804333621f00e68e352
|
|
| BLAKE2b-256 |
6b199c7f88632019e77225c64d746fbe493c8e68e1eb135e199b624690306b4b
|
File details
Details for the file wx_channel-1.0.0-py3-none-any.whl.
File metadata
- Download URL: wx_channel-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d2e9a23fa709978965b2fe70fa4dccc8997c200a4bc7cb5b793516782f771b8
|
|
| MD5 |
9a8cb18b891eba30c4568f336080eac8
|
|
| BLAKE2b-256 |
da76e3984f51c5b3517e268a4ce27e58cedb62afac892b0728da57851d0c3463
|