野火IM Server Python SDK 是野火IM服务器的官方 Python 语言 SDK,提供了完整的 Admin API、Robot API 和 Channel API 接口封装。
- 用户管理(创建、查询、更新、封禁等)
- 群组管理(创建、解散、成员管理等)
- 消息管理(发送、撤回、广播等)
- 好友关系管理(添加、删除、黑名单等)
- 聊天室管理
- 频道管理
- 机器人服务
- 会议管理
- 敏感词管理
- 多种消息类型支持(文本、图片、语音、视频、文件、位置、链接、名片等)
- Admin API 文档 - 服务端管理接口,包括用户、群组、消息、频道等管理功能
- Robot API 文档 - 机器人服务接口,用于开发机器人应用
- Channel API 文档 - 频道服务接口,用于开发公众号/频道应用
- IM 开发文档 - 野火IM完整开发文档
野火IM 官方提供多语言 SDK 实现:
| 语言 | GitHub | Gitee(码云) |
|---|---|---|
| Java SDK | GitHub | Gitee |
| Go SDK | GitHub | Gitee |
| Node.js SDK | GitHub | Gitee |
| Python SDK | GitHub | Gitee |
pip install -r requirements.txtfrom wildfirechat import AdminConfig, UserAdmin, MessageAdmin
from wildfirechat.models import InputOutputUserInfo, Conversation
from wildfirechat.message_content import TextMessageContent
from wildfirechat.proto_constants import Platform
# 初始化配置
AdminConfig.init_admin("http://localhost:18080", "123456")
# 创建用户
user = InputOutputUserInfo()
user.userId = "user1"
user.name = "user1"
user.displayName = "Test User"
user.mobile = "13800000000"
result = UserAdmin.create_user(user)
if result.is_success():
print(f"创建用户成功: {result.result.userId}")
# 获取用户Token
token_result = UserAdmin.get_user_token("user1", "client1", Platform.Platform_Android)
if token_result.is_success():
print(f"Token: {token_result.result.token}")
# 发送消息
conversation = Conversation()
conversation.type = 0 # 私聊
conversation.target = "user2"
conversation.line = 0
text_content = TextMessageContent("Hello, World!")
payload = text_content.encode()
msg_result = MessageAdmin.send_message("user1", conversation, payload)
if msg_result.is_success():
print(f"消息发送成功,消息ID: {msg_result.result.messageUid}")from wildfirechat import RobotService
from wildfirechat.message_content import TextMessageContent
# 初始化机器人服务(使用机器人ID和密钥)
robot = RobotService("http://localhost", "robot1", "123456")
# 发送文本消息
content = TextMessageContent("Hello from robot!")
result = robot.send_message("user1", content)
if result.is_success():
print("机器人消息发送成功")
# 获取用户信息
user_info = robot.get_user_info("user1")
if user_info.is_success():
print(f"用户显示名: {user_info.result.display_name}")from wildfirechat import ChannelService
from wildfirechat.message_content import TextMessageContent
# 初始化频道服务(使用频道ID和密钥)
channel = ChannelService("http://localhost", "channel1", "123456")
# 发送消息给订阅用户
content = TextMessageContent("Channel broadcast message")
result = channel.broadcast_message(content)
if result.is_success():
print("频道广播消息发送成功")
# 获取频道订阅者列表(专业版功能)
subscribers = channel.get_subscribers()
if subscribers.is_success():
print(f"订阅者数量: {len(subscribers.result.subscribers)}")# 使用默认配置
python main.py
# 使用自定义配置
python main.py http://your-server:18080 your-secret http://your-server false false
# 显示帮助
python main.py --helppython_sdk/
├── wildfirechat/ # SDK主模块
│ ├── __init__.py # 模块导出
│ ├── admin_config.py # 配置类
│ ├── api_path.py # API路径定义
│ ├── error_code.py # 错误码定义
│ ├── proto_constants.py # 协议常量
│ ├── http_utils.py # HTTP工具类
│ ├── models.py # 数据模型
│ ├── message_content.py # 消息内容类
│ ├── user_admin.py # 用户管理
│ ├── group_admin.py # 群组管理
│ ├── message_admin.py # 消息管理
│ ├── relation_admin.py # 好友关系管理
│ ├── chatroom_admin.py # 聊天室管理
│ ├── channel_admin.py # 频道管理
│ ├── general_admin.py # 通用管理
│ ├── sensitive_admin.py # 敏感词管理
│ ├── conference_admin.py# 会议管理
│ └── robot_service.py # 机器人服务
├── main.py # 测试主程序
├── requirements.txt # 依赖包
└── README.md # 说明文档
MIT