mecat-sdk
MeChat 开放世界即时通讯服务 Python SDK。同步阻塞风格,基于 requests + python-socketio,
覆盖全部 REST 端点与 Socket.IO 实时事件。
- Python ≥ 3.9
- 双通道:REST(一次性业务)+ WebSocket(实时推送)
- 事件回调用
@client.on("event")装饰器注册
安装
pip install mecat-sdk
# 本地开发
pip install -e .
快速上手
from mecat import MecatClient
with MecatClient("http://localhost:3000") as c:
# 注册并上线
c.register_account("alice", "pass1234", nickname="Alice")
c.connect_socket()
# 也可以在注册前直接游客进入
# c.quick_join(nickname="游客一号")
# 订阅事件
@c.on("new_message")
def on_msg(data):
print(f"{data['author']}: {data['content']}")
c.send_message("大家好")
REST 接口
| 方法 | 端点 | 描述 |
|---|---|---|
health() |
GET /api/health | 健康检查 |
register_account(u,p,...) |
POST /api/register | 注册 |
login(u,p) |
POST /api/login | 登录 |
get_users() |
GET /api/users | 在线用户(5 分钟活跃窗口) |
get_user(id) |
GET /api/user/:id | 用户详情 |
get_messages(limit,x,y,radius) |
GET /api/messages | 世界消息(服务端只回最新一页) |
clear_messages() |
POST /api/clear-messages | 公开无鉴权,慎用 |
Socket 事件
输入(客户端→服务端)
| 方法 | 说明 |
|---|---|
connect_socket(...) / quick_join(...) |
register(含游客、重连) |
move(x,y) |
位置移动 |
send_message(content,x,y,friend_only) |
世界消息 |
send_private_message(target,content) |
私信(需互为好友) |
update_profile(...) |
更新资料 |
send_friend_request / accept / reject / remove_friend |
好友申请链 |
get_friends / get_pending_requests |
列表查询 |
block_user / unblock_user |
拉黑 / 解除 |
get_dm_history / clear_dm_history |
私信历史 |
管理员事件(16 个,需要 isAdmin / isSuperAdmin)
admin_delete_message admin_mute_user admin_unmute_user admin_broadcast
admin_kick_user admin_kick_guests admin_ban_user admin_unban_user
admin_get_user_info admin_clear_messages admin_cleanup admin_update_user
admin_set_admin admin_unset_admin admin_get_lists admin_get_all_users
输出(服务端→客户端)
通过 @client.on("event_name") 订阅。常用:registered new_message
private_message friend_request friend_accepted user_joined user_left
user_moved kicked banned admin_result …
算法
mecat.algorithms 提供与服务端一致的实现:
hash_password generate_id generate_session_token get_random_name get_random_color。
测试
python -m pytest tests/ -v
tests/test_integration.py 会自动拉起本机 X:\Project\Local\mecat 服务端做联调;
可通过环境变量 MECAT_SERVER_DIR 指向其他路径。若未安装 Node.js,联调测试会自动 skip。
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 mecat_sdk-0.1.1.tar.gz.
File metadata
- Download URL: mecat_sdk-0.1.1.tar.gz
- Upload date:
- Size: 25.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd2d6c978075163694226692fd2221cd1ebf8de1a07ccf824f57d4ccf5e48036
|
|
| MD5 |
796e23492ac2604ee389b76cc50c6314
|
|
| BLAKE2b-256 |
a0f03f33162d50c67e223c9bd51991482a2c3649d5a7099d9a54e6d516feaf38
|
File details
Details for the file mecat_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mecat_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6723a1592bcf7ce963385ad4a8236af4f33726a4beed831740eebdd5c123a056
|
|
| MD5 |
e2977d35663fd344d7cf172db05786d0
|
|
| BLAKE2b-256 |
b873454367269ca22869e7d9f9fb840425f22a0aa974bff42c920f86e8362d95
|