Convert Figma logo to code with AI

youfou logowxpy

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

13,948
2,383
13,948
303

Top Related Projects

25,429

A complete and graceful API for Wechat. 微信个人号接口、微信机器人及命令行微信,三十行即可自定义个人号机器人。

19,998

Conversational RPA SDK for Chatbot Makers. Join our Discord: https://discord.gg/7q8NBZbQzt

Python Wechaty is a Conversational RPA SDK for Chatbot Makers written in Python

网页版微信API,包含终端版微信及微信机器人

Quick Overview

wxpy is a Python library that provides a simple and efficient way to control WeChat through the WeChat Web API. It allows developers to automate WeChat operations, build chatbots, and create custom WeChat applications using Python.

Pros

  • Easy to use with a Pythonic API
  • Supports both personal and official WeChat accounts
  • Provides comprehensive documentation and examples
  • Actively maintained with regular updates

Cons

  • Relies on the WeChat Web API, which may have limitations compared to the mobile app
  • Potential risk of account suspension if used improperly
  • Limited support for some advanced WeChat features
  • May be affected by changes in WeChat's policies or API

Code Examples

  1. Sending a message to a friend:
from wxpy import *

bot = Bot()
friend = bot.friends().search('Friend Name')[0]
friend.send('Hello from wxpy!')
  1. Responding to messages automatically:
from wxpy import *

bot = Bot()

@bot.register()
def reply_message(msg):
    return 'I received: ' + msg.text

embed()
  1. Creating a group chat and inviting friends:
from wxpy import *

bot = Bot()
friend1 = bot.friends().search('Friend1')[0]
friend2 = bot.friends().search('Friend2')[0]

group = bot.create_group([friend1, friend2], 'New Group')
group.send('Welcome to the new group!')

Getting Started

To get started with wxpy, follow these steps:

  1. Install wxpy using pip:

    pip install -U wxpy
    
  2. Import the library and create a Bot instance:

    from wxpy import *
    bot = Bot()
    
  3. Use the bot instance to interact with WeChat:

    # Send a message to yourself
    bot.self.send('Hello, wxpy!')
    
    # Listen for new messages
    @bot.register()
    def print_messages(msg):
        print(msg)
    
    # Keep the bot running
    embed()
    

Note: When running the script for the first time, you'll need to scan a QR code with your WeChat mobile app to log in.

Competitor Comparisons

25,429

A complete and graceful API for Wechat. 微信个人号接口、微信机器人及命令行微信,三十行即可自定义个人号机器人。

Pros of ItChat

  • More comprehensive documentation and examples
  • Supports both personal and enterprise WeChat accounts
  • Better handling of complex message types (e.g., voice messages, files)

Cons of ItChat

  • Less active development and maintenance
  • Slightly more complex API compared to wxpy
  • May have compatibility issues with newer WeChat versions

Code Comparison

ItChat:

import itchat

@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
    return msg.text

itchat.auto_login()
itchat.run()

wxpy:

from wxpy import *

bot = Bot()

@bot.register()
def reply_message(msg):
    return msg.text

bot.join()

Both libraries provide similar functionality for interacting with WeChat, but wxpy offers a more streamlined and Pythonic API. ItChat provides more detailed control over message types and account types, while wxpy focuses on simplicity and ease of use.

ItChat's documentation is more extensive, making it easier for beginners to get started. However, wxpy's active development and maintenance may make it a better choice for long-term projects.

In terms of performance, both libraries are comparable, with slight variations depending on specific use cases. The choice between the two often comes down to personal preference and specific project requirements.

19,998

Conversational RPA SDK for Chatbot Makers. Join our Discord: https://discord.gg/7q8NBZbQzt

Pros of Wechaty

  • Multi-platform support (Web, Pad, Windows, Mac)
  • Supports multiple messaging protocols beyond just WeChat
  • More active development and larger community

Cons of Wechaty

  • Steeper learning curve due to more complex architecture
  • Requires more setup and configuration
  • Potentially higher resource usage due to broader feature set

Code Comparison

Wechaty example:

const { Wechaty } = require('wechaty')

const bot = new Wechaty()
bot.on('scan', (qrcode, status) => console.log(`Scan QR Code to login: ${status}\nhttps://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`))
bot.on('login', user => console.log(`User ${user} logged in`))
bot.on('message', message => console.log(`Message: ${message}`))
bot.start()

Wxpy example:

from wxpy import *

bot = Bot()
@bot.register()
def print_messages(msg):
    print(msg)
bot.join()

Both libraries provide similar functionality for creating WeChat bots, but Wechaty offers a more comprehensive solution with broader platform support and protocol compatibility. Wxpy, on the other hand, provides a simpler, Python-specific implementation focused solely on WeChat. The choice between the two depends on the specific requirements of your project and your preferred programming language.

Python Wechaty is a Conversational RPA SDK for Chatbot Makers written in Python

Pros of python-wechaty

  • Multi-platform support (WeChat, WhatsApp, etc.)
  • More active development and larger community
  • Better documentation and examples

Cons of python-wechaty

  • Steeper learning curve
  • Requires more setup and configuration
  • Potentially slower performance due to its cross-platform nature

Code Comparison

wxpy:

from wxpy import Bot, Friend

bot = Bot()
my_friend = bot.friends().search('friend_name')[0]
my_friend.send('Hello, friend!')

python-wechaty:

from wechaty import Wechaty, Contact

async def on_message(msg):
    if msg.text() == 'ding':
        await msg.say('dong')

bot = Wechaty()
bot.on('message', on_message)
bot.start()

Key Differences

  • wxpy is specifically designed for WeChat, while python-wechaty supports multiple platforms
  • python-wechaty uses an asynchronous programming model, while wxpy is synchronous
  • wxpy has a simpler API for basic tasks, but python-wechaty offers more flexibility and features

Use Cases

  • Choose wxpy for quick WeChat-specific projects with simple requirements
  • Opt for python-wechaty for cross-platform chatbot development or more complex applications

Community and Support

  • python-wechaty has a larger and more active community, with regular updates and contributions
  • wxpy has a smaller but dedicated user base, primarily focused on WeChat automation

网页版微信API,包含终端版微信及微信机器人

Pros of WeixinBot

  • More comprehensive documentation and examples
  • Supports a wider range of WeChat features and functionalities
  • Actively maintained with regular updates and bug fixes

Cons of WeixinBot

  • More complex setup and configuration process
  • Steeper learning curve for beginners
  • Requires more system resources due to its extensive feature set

Code Comparison

WeixinBot:

from WeixinBot import WeixinBot

bot = WeixinBot()
bot.login()
bot.send_msg('Hello, WeChat!', 'Friend_Name')

wxpy:

from wxpy import Bot

bot = Bot()
friend = bot.friends().search('Friend_Name')[0]
friend.send('Hello, WeChat!')

Summary

WeixinBot offers more advanced features and comprehensive documentation, making it suitable for complex WeChat automation tasks. However, it may be overkill for simpler use cases and can be more challenging for beginners to set up and use.

wxpy, on the other hand, provides a more straightforward and user-friendly approach, making it ideal for those who need basic WeChat bot functionality without the added complexity. It's easier to get started with wxpy, but it may lack some of the more advanced features found in WeixinBot.

Choose WeixinBot for more complex projects requiring extensive WeChat integration, and wxpy for simpler, more straightforward WeChat bot development.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

wxpy: 用 Python 玩微信

.. image:: https://badge.fury.io/py/wxpy.svg :target: https://badge.fury.io/py/wxpy

.. image:: https://img.shields.io/pypi/pyversions/wxpy.svg :target: https://github.com/youfou/wxpy

.. image:: https://readthedocs.org/projects/wxpy/badge/?version=latest :target: http://wxpy.readthedocs.io/zh/latest/?badge=latest

微信机器人 / 可能是最优雅的微信个人号 API wxpy 在 itchat 的基础上,通过大量接口优化提升了模块的易用性,并进行丰富的功能扩展

.. attention::

| **强烈建议仅使用小号运行机器人!**

| 从近期 (17年6月下旬) 反馈来看,使用机器人存在一定概率被限制登录的可能性。
| 主要表现为无法登陆 Web 微信 (但不影响手机等其他平台)。

用来干啥

一些常见的场景

  • 控制路由器、智能家居等具有开放接口的玩意儿
  • 运行脚本时自动把日志发送到你的微信
  • 加群主为好友,自动拉进群中
  • 跨号或跨群转发消息
  • 自动陪人聊天
  • 逗人玩
  • ...

总而言之,可用来实现各种微信个人号的自动化操作

.. 体验一下 ----------------

**这有一个现成的微信机器人,想不想调戏一下?**

记得填写入群口令 👉 [ **wxpy** ],与群里的大神们谈笑风生 😏

..  image:: https://github.com/youfou/wxpy/raw/master/docs/wechat-group.png

轻松安装

wxpy 支持 Python 3.4-3.6,以及 2.7 版本

将下方命令中的 "pip" 替换为 "pip3" 或 "pip2",可确保安装到对应的 Python 版本中

  1. 从 PYPI 官方源下载安装 (在国内可能比较慢或不稳定):

.. code:: shell

pip install -U wxpy

2. 从豆瓣 PYPI 镜像源下载安装 (推荐国内用户选用):

.. code:: shell

pip install -U wxpy -i "https://pypi.doubanio.com/simple/"

简单上手

登陆微信:

.. code:: python

# 导入模块
from wxpy import *
# 初始化机器人,扫码登陆
bot = Bot()

找到好友:

.. code:: python

# 搜索名称含有 "游否" 的男性深圳好友
my_friend = bot.friends().search('游否', sex=MALE, city="深圳")[0]

发送消息:

.. code:: python

# 发送文本给好友
my_friend.send('Hello WeChat!')
# 发送图片
my_friend.send_image('my_picture.jpg')

自动响应各类消息:

.. code:: python

# 打印来自其他好友、群聊和公众号的消息
@bot.register()
def print_others(msg):
    print(msg)

# 回复 my_friend 的消息 (优先匹配后注册的函数!)
@bot.register(my_friend)
def reply_my_friend(msg):
    return 'received: {} ({})'.format(msg.text, msg.type)

# 自动接受新的好友请求
@bot.register(msg_types=FRIENDS)
def auto_accept_friends(msg):
    # 接受好友请求
    new_friend = msg.card.accept()
    # 向新的好友发送消息
    new_friend.send('哈哈,我自动接受了你的好友请求')

保持登陆/运行:

.. code:: python

# 进入 Python 命令行、让程序保持运行
embed()

# 或者仅仅堵塞线程
# bot.join()

模块特色

  • 全面对象化接口,调用更优雅

  • 默认多线程响应消息,回复更快

  • 包含 聊天机器人、共同好友 等 实用组件 <http://wxpy.readthedocs.io/zh/latest/utils.html>_

  • 只需两行代码,在其他项目中用微信接收警告

  • 愉快的探索和调试 <http://wxpy.readthedocs.io/zh/latest/console.html>_,无需涂涂改改

  • 可混合使用 itchat 的原接口

  • 当然,还覆盖了各类常见基本功能:

    • 发送文本、图片、视频、文件
    • 通过关键词或用户属性搜索 好友、群聊、群成员等
    • 获取好友/群成员的昵称、备注、性别、地区等信息
    • 加好友,建群,邀请入群,移出群

说明文档

http://wxpy.readthedocs.io

更新日志

https://github.com/youfou/wxpy/releases

项目主页

https://github.com/youfou/wxpy