gitmyhub

wxpy

Python ★ 14k updated 7y ago ▣ archived

微信机器人 / 可能是最优雅的微信个人号 API ✨✨

A Python library for automating a WeChat personal account, log in by scanning a QR code, then send messages, auto-respond to chats, manage groups, and build chatbots with simple Python scripts.

Pythonsetup: moderatecomplexity 2/5

wxpy is a Python library for automating a WeChat personal account. WeChat is the dominant messaging platform in China, and this library provides a Python interface to its web-based login, letting you write scripts that send and receive messages programmatically without touching the app manually.

With a few lines of code you can log into WeChat by scanning a QR code, search your contacts by name or attributes like gender and city, send text messages or image and video files to friends or groups, and set up handlers that automatically respond when certain messages arrive. The library also supports creating group chats, inviting contacts into groups, forwarding messages across accounts or groups, and automatically accepting friend requests.

The README describes common use cases including sending log output from other programs directly to your WeChat, building chatbots that hold conversations, controlling smart home devices that have open APIs, and pranking friends. The library is built on top of an earlier project called itchat and adds a cleaner object-oriented interface with multi-threaded message handling for faster responses.

The project's README includes a notable warning: using a bot carries some risk that the account may be blocked from logging into the WeChat web client, though it does not affect the mobile app. The authors strongly recommend running bots on a secondary spare account rather than a primary one. The library supports Python 2.7 and Python 3.4 through 3.6 and can be installed via pip.

Where it fits