Skip to main content

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

mecat_sdk-0.1.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mecat_sdk-0.1.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file mecat_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: mecat_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for mecat_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 046040efd8c1c51a73490bd47ba5fdb2b448f333c8e7510e339388bd48094177
MD5 a40e00394bc9bc37212ca4e29b4e1aa6
BLAKE2b-256 001a6814bc091169207bd1b90e9d060c363dcb2a6d43be9001bf341c92cf3562

See more details on using hashes here.

File details

Details for the file mecat_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mecat_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for mecat_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be86d9c61a730bb7e3bc0590bea73305643c4ca8ce4317995b4963240730b86a
MD5 e5cd4b0e21058c3bf9f509fd08695be6
BLAKE2b-256 28cea6ec2ce672b3644f3347584bc216ad56f877ebfe374aef4758306238440f

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page