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.2.tar.gz (26.4 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.2-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mecat_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 26.4 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.2.tar.gz
Algorithm Hash digest
SHA256 c805064d8ea1f38356d717f9c0d11929a3332ef8a74000aac0456ea83afccb5b
MD5 ee143c664cbda467006cf16606a42063
BLAKE2b-256 d3b5e61e54b3c66390efa81f5d1bdbb3e8687c9e94371888317d58abe32f325f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mecat_sdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 25.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 79370ee4020d72fdd7550a46d123cb9ee4c35e31b233a9524e906f5bec425dc6
MD5 9c35741cb3d198652f656561ebb9a35c
BLAKE2b-256 72dbbf8b3ad2f6f600398d0406112fcb90725fe44c001e6e98699c23105f10c4

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

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