python-wechaty
Python Wechaty is a Conversational RPA SDK for Chatbot Makers written in Python
Top Related Projects
微信机器人 / 可能是最优雅的微信个人号 API ✨✨
A complete and graceful API for Wechat. 微信个人号接口、微信机器人及命令行微信,三十行即可自定义个人号机器人。
Conversational RPA SDK for Chatbot Makers. Join our Discord: https://discord.gg/7q8NBZbQzt
网页版微信API,包含终端版微信及微信机器人
查看被删的微信好友
Quick Overview
Python-wechaty is a Python SDK for Wechaty, a conversational RPA (Robotic Process Automation) SDK for chatbot makers. It allows developers to create chatbots for various messaging platforms, including WeChat, WhatsApp, and more, using a unified API.
Pros
- Cross-platform compatibility: Supports multiple messaging platforms with a single API
- Easy to use: Provides a high-level abstraction for bot development
- Active community: Regular updates and support from contributors
- Extensible: Supports plugins and custom extensions
Cons
- Limited documentation: Some features may lack detailed explanations
- Performance overhead: As a high-level SDK, it may have slightly lower performance compared to native implementations
- Learning curve: Requires understanding of the Wechaty ecosystem and concepts
Code Examples
- Creating a simple bot that responds to messages:
from wechaty import Wechaty, Contact
from wechaty.user import Message
class MyBot(Wechaty):
async def on_message(self, msg: Message):
if msg.text() == 'ding':
await msg.say('dong')
bot = MyBot()
bot.start()
- Handling friend requests:
from wechaty import Wechaty, Friendship
class MyBot(Wechaty):
async def on_friendship(self, friendship: Friendship):
if friendship.type() == Friendship.Type.RECEIVE:
await friendship.accept()
bot = MyBot()
bot.start()
- Scheduling a task:
from wechaty import Wechaty
from apscheduler.schedulers.asyncio import AsyncIOScheduler
class MyBot(Wechaty):
def __init__(self):
super().__init__()
self.scheduler = AsyncIOScheduler()
async def on_ready(self):
self.scheduler.add_job(self.scheduled_task, 'interval', hours=1)
self.scheduler.start()
async def scheduled_task(self):
# Perform scheduled task here
pass
bot = MyBot()
bot.start()
Getting Started
-
Install python-wechaty:
pip install wechaty
-
Create a new Python file (e.g.,
mybot.py
) with the following content:from wechaty import Wechaty, Contact from wechaty.user import Message class MyBot(Wechaty): async def on_message(self, msg: Message): if msg.text() == 'hello': await msg.say('Hello! I am a Wechaty bot.') bot = MyBot() bot.start()
-
Run your bot:
python mybot.py
-
Follow the console instructions to log in to your WeChat account using the provided QR code.
Competitor Comparisons
微信机器人 / 可能是最优雅的微信个人号 API ✨✨
Pros of wxpy
- Simpler API and easier to get started for beginners
- More lightweight and focused specifically on WeChat automation
- Better documentation in Chinese, catering to the primary user base
Cons of wxpy
- Less actively maintained, with fewer recent updates
- Limited cross-platform support compared to python-wechaty
- Lacks some advanced features and integrations available in python-wechaty
Code Comparison
wxpy:
from wxpy import *
bot = Bot()
my_friend = bot.friends().search('friend_name')[0]
my_friend.send('Hello, WeChat!')
python-wechaty:
from wechaty import Wechaty, Contact
async def on_message(msg: Message):
if msg.text() == 'ding':
await msg.say('dong')
bot = Wechaty()
bot.on('message', on_message)
bot.start()
The wxpy code is more concise and straightforward for simple tasks, while python-wechaty offers more flexibility and event-driven programming. python-wechaty also supports asynchronous operations, which can be beneficial for handling multiple tasks simultaneously.
A complete and graceful API for Wechat. 微信个人号接口、微信机器人及命令行微信,三十行即可自定义个人号机器人。
Pros of ItChat
- Simpler and more lightweight, making it easier to get started quickly
- Better documentation in English, improving accessibility for non-Chinese speakers
- More focused on WeChat-specific functionality
Cons of ItChat
- Less actively maintained, with fewer recent updates
- Limited cross-platform support compared to Python-Wechaty
- Lacks some advanced features and extensibility options
Code Comparison
ItChat:
import itchat
@itchat.msg_register(itchat.content.TEXT)
def text_reply(msg):
return msg.text
itchat.auto_login()
itchat.run()
Python-Wechaty:
from wechaty import Wechaty, Contact
from wechaty.user import Message
class MyBot(Wechaty):
async def on_message(self, msg: Message):
await msg.say(msg.text())
bot = MyBot()
bot.start()
Both libraries provide simple ways to create WeChat bots, but Python-Wechaty offers a more object-oriented approach with async support. ItChat's syntax is more concise, while Python-Wechaty provides a more structured and extensible framework.
Python-Wechaty offers broader functionality and cross-platform support, making it suitable for more complex projects. However, ItChat's simplicity and focus on WeChat-specific features make it a good choice for smaller, WeChat-centric applications.
Conversational RPA SDK for Chatbot Makers. Join our Discord: https://discord.gg/7q8NBZbQzt
Pros of Wechaty
- More mature and feature-rich, with a larger community and ecosystem
- Better documentation and examples for various use cases
- Supports multiple programming languages through SDKs
Cons of Wechaty
- Steeper learning curve due to more complex architecture
- Potentially higher resource usage for simple chatbot applications
- May require more setup and configuration
Code Comparison
Python-Wechaty:
from wechaty import Wechaty
class MyBot(Wechaty):
async def on_message(self, msg):
await msg.say('Hello, World!')
bot = MyBot()
bot.start()
Wechaty:
import { Wechaty } from 'wechaty'
const bot = new Wechaty()
bot.on('message', async msg => {
await msg.say('Hello, World!')
})
bot.start()
Summary
Wechaty is a more comprehensive solution with broader language support and a larger ecosystem. It's ideal for complex chatbot applications and those requiring multi-language support. Python-Wechaty, on the other hand, is more straightforward and Python-specific, making it a good choice for Python developers working on simpler chatbot projects. The code comparison shows that both libraries have similar basic usage patterns, with Python-Wechaty using a class-based approach and Wechaty using an event-based approach.
网页版微信API,包含终端版微信及微信机器人
Pros of WeixinBot
- Lightweight and focused specifically on WeChat functionality
- Simpler setup process for basic WeChat automation tasks
- More direct access to WeChat Web API
Cons of WeixinBot
- Less actively maintained, with fewer recent updates
- Limited cross-platform support compared to Python-Wechaty
- Narrower scope of features and integrations
Code Comparison
WeixinBot:
bot = WeixinBot()
bot.login()
bot.send_msg(to_user='friend123', msg='Hello from WeixinBot!')
Python-Wechaty:
from wechaty import Wechaty
async def main():
bot = Wechaty()
await bot.start()
contact = await bot.Contact.find('friend123')
await contact.say('Hello from Python-Wechaty!')
asyncio.run(main())
Summary
WeixinBot offers a more straightforward approach for basic WeChat automation, making it easier to get started for simple tasks. However, Python-Wechaty provides a more comprehensive and actively maintained solution with broader platform support and integration capabilities. Python-Wechaty's code structure reflects its asynchronous nature and more extensive feature set, while WeixinBot's code is more concise for basic operations.
查看被删的微信好友
Pros of wechat-deleted-friends
- Focused functionality: Specifically designed to detect deleted WeChat friends
- Lightweight: Smaller codebase, easier to understand and modify
- No external dependencies: Runs with standard Python libraries
Cons of wechat-deleted-friends
- Limited scope: Only handles friend deletion detection
- Less active development: Fewer recent updates and contributions
- Manual interaction required: User needs to scan QR code for authentication
Code Comparison
wechat-deleted-friends:
def get_contact(self):
url = self.base_uri + '/webwxgetcontact?pass_ticket=%s&skey=%s&r=%s' % (
self.pass_ticket, self.skey, int(time.time()))
r = self.session.post(url, data='{}')
r.encoding = 'utf-8'
data = json.loads(r.text)
return data['MemberList']
python-wechaty:
async def get_contact(self, weixin: str) -> Optional[Contact]:
contact = self.Contact.load(weixin)
try:
await contact.ready()
return contact
except Exception as e:
log.error('Contact load error for %s: %s', weixin, str(e))
return None
The code snippets show different approaches to retrieving contact information. wechat-deleted-friends uses direct HTTP requests, while python-wechaty employs an asynchronous method with error handling and logging.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
python-wechaty
ð Chinese Document python-wechaty-template
What's Python Wechaty
Python Wechaty is an Open Source software application for building chatbots. It is a modern Conversational RPA SDK which Chatbot makers can use to create a bot in a few lines of code.
You can use Wechaty to build a chatbot which automates conversations and interact with people through instant messaging platforms such as WhatsApp, WeChat, WeCom, Gitter and Lark among others.
Features
- Message Processing: You can use the simple code, similar to natural language, to process the message receving & sending.
- Plugin System: You can use the community-contributed plugins to handle your scenario.
- Write onece, run multi IM platform: python wechaty support many IM platforms with one code, all of you need to do is switch the token token type.
- Wechaty UI: you can use the powerful wechaty-ui to create interactive chatbot
- ...
Getting Started
There are few steps to start your bot, and we give a bot-template for you to getting started quickly.
Join Us
Wechaty is used in many ChatBot projects by thousands of developers. If you want to talk with other developers, just scan the following QR Code in WeChat with secret code python wechaty, join our Wechaty Python Developers' Home.
Scan now, because other Wechaty Python developers want to talk with you too! (secret code: python wechaty)
Requirements
- Python 3.7+
Install
pip3 install wechaty
See Also
Static & Instance of Class
Typings
History
v0.6 (Jun 19, 2020)
Python Wechaty Scala Wechaty BETA Released!
Read more from our Multi-language Wechaty Beta Release event from our blog:
v0.4 (Mar 15, 2020) master
Welcome @huangaszaq for joining the project! #42
- Add a friendly exception message for PyPI users. #24
v0.1 (Mar 8, 2020)
Welcome @wj-Mcat for joining the project! #4
- Starting translate TypeScript of Wechaty to Python
- DevOps Setup
- Type Checking: mypy & pytype
- Unit Testing: pytest
- Linting: pylint, pycodestyle, and flake8
- CI/CD: GitHub Actions
- Publish to PyPI automatically after the tests passed.
v0.0.1 (Aug 25, 2018)
Project created, publish a empty module wechaty
on PyPI.
Related Projects
- Wechaty - Conversatioanl AI Chatot SDK for Wechaty Individual Accounts (TypeScript)
- Python Wechaty - Python WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Python)
- Go Wechaty - Go WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Go)
- Java Wechaty - Java WeChaty Conversational AI Chatbot SDK for Wechat Individual Accounts (Java)
- Scala Wechaty - Scala WeChaty Conversational AI Chatbot SDK for WechatyIndividual Accounts (Scala)
Badge
[![Wechaty in Python](https://img.shields.io/badge/Wechaty-Python-blue)](https://github.com/wechaty/python-wechaty)
Stargazers over time
Contributors
Made with contrib.rocks.
Support
Thanks the following supported Software.
Committers
- @huangaszaq - Chunhong HUANG (é»çº¯æ´ª)
Creators
- @wj-Mcat - Jingjing WU (å´äº¬äº¬)
- @huan - (æåæ¡) zixia@zixia.net
Copyright & License
- Code & Docs © 2018 Wechaty Contributors https://github.com/wechaty
- Code released under the Apache-2.0 License
- Docs released under Creative Commons
Top Related Projects
微信机器人 / 可能是最优雅的微信个人号 API ✨✨
A complete and graceful API for Wechat. 微信个人号接口、微信机器人及命令行微信,三十行即可自定义个人号机器人。
Conversational RPA SDK for Chatbot Makers. Join our Discord: https://discord.gg/7q8NBZbQzt
网页版微信API,包含终端版微信及微信机器人
查看被删的微信好友
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot