Skip to main content

QQ Bot Python SDK

Python 3.10+ 原生绑定,通过 PyO3 复用 Rust SDK 的鉴权、限频和消息 API。JSON API 与 Node.js 共用 Rust 分发层。

从 PyPI 安装

pip install qqbot-sdk-python

首次发布完成后即可安装,导入名为 qqbot_sdk_python。预编译 wheel 支持 CPython 3.10+,覆盖 Linux x86_64/ARM64、macOS Intel/Apple Silicon 和 Windows x64。

从源码安装

在仓库根目录运行,需要 Rust 工具链和 Python。

cd packages/python
python3 -m venv .venv
. .venv/bin/activate
python -m pip install 'maturin>=1.9.4,<2'
maturin develop --locked
python -m unittest discover -s tests -v

在同一目录运行 maturin build --release --locked 构建当前平台的 wheel。

使用

import asyncio
import os

from qqbot_sdk_python import Bot

async def main():
    bot = Bot(os.environ["QQBOT_APP_ID"], os.environ["QQBOT_APP_SECRET"])
    print(await bot.api.bot.me())
    user = bot.user(os.environ["QQBOT_USER_OPENID"])
    message = await user.send("你好")
    print(message["id"])

asyncio.run(main())

被动回复时可传入 await user.send("你好", msg_id=收到的消息ID)。发送权限和额度取决于 QQ 开放平台的配置。

bot.user(id)、bot.group(id)、bot.channel(id) 和 bot.direct(id) 都提供 send 与 recall。发送时也可以传入使用 QQ 原生字段名的字典。权限检查与 Rust SDK 一致。

bot.api 与 Rust 和 Node.js 共用 11 个分组,包含 bot、messages、users、groups、guilds、channels、materials、interactions、menu、panels 和 utility。Python 使用和 Rust 相同的下划线方法名,参数顺序与 Node.js 一致。分页可选参数可省略,例如 await bot.api.bot.guilds(limit=20)。

二进制上传使用 bot.api.materials.upload(...)、bot.api.messages.upload_media(...) 和 bot.api.messages.send_media(...),文件内容以 bytes 传入。两个消息富媒体方法也接受 URL 字符串。

分组和方法由共享核心生成。修改核心 API 后,在仓库根目录运行 python3 packages/npm/scripts/generate-api.py 更新 Rust 分发、TypeScript 声明和 Python 方法。

网关模式下使用 await bot.run(callback) 接收事件,调用 bot.stop() 结束。每个实例可启动一次。普通同步回调在 asyncio 循环中执行。Webhook 模式下,bot.handle_webhook(timestamp, signature, raw_body) 验证原始字节,返回 response 和可选的 event。HTTP 处理器应把 response 写回 QQ。

请求失败会抛出 BotError。平台业务错误是其子类 ApiError,提供 status、code、message、trace_id 和 data。无效参数会抛出 ValueError。

Bot(..., api_base_url=...) 可接入测试服务器。鉴权请求会把 App ID 和 App Secret 发送到该地址。

发布到 PyPI

合并 Release Please 的统一版本 PR 后,统一发布工作流 会从发行标签构建五个平台的 wheel。每个 wheel 安装后运行 Python 测试,全部通过才发布。

首次发布前,在 PyPI 的 Publishing 页面 添加 pending Trusted Publisher。使用以下配置。

字段 值
PyPI 项目名 qqbot-sdk-python
GitHub owner Lovely-02
Repository qqbot-sdk-rs
Workflow name release.yml
Environment name pypi

在 GitHub 仓库的 Settings → Environments 中创建 pypi 环境,并将允许部署的分支设为 main。工作流通过 GitHub OIDC 获取上传权限,无需配置 PyPI API Token。

重试时,在 Actions → 统一发布 → Run workflow 选择 main,填入已有的 qqbot-sdk-rs-vX.Y.Z 标签,选择 target=python。选择 all 会同时重试三个包仓库,选择 both 会重试 crates.io 和 GitHub Packages。

Metadata

Release files for qqbot-sdk-python 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for qqbot-sdk-python 0.4.2
File Actions
qqbot_sdk_python-0.4.2-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for qqbot_sdk_python-0.4.2-cp310-abi3-win_amd64.whl
qqbot_sdk_python-0.4.2-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details for qqbot_sdk_python-0.4.2-cp310-abi3-manylinux_2_28_x86_64.whl
qqbot_sdk_python-0.4.2-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details for qqbot_sdk_python-0.4.2-cp310-abi3-manylinux_2_28_aarch64.whl
qqbot_sdk_python-0.4.2-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for qqbot_sdk_python-0.4.2-cp310-abi3-macosx_11_0_arm64.whl
qqbot_sdk_python-0.4.2-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for qqbot_sdk_python-0.4.2-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 16.1 MB

Release files / qqbot_sdk_python-0.4.2-cp310-abi3-win_amd64.whl

Download URL qqbot_sdk_python-0.4.2-cp310-abi3-win_amd64.whl
Size 3.0 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
750ba7415e1c957fb74cf7afa0a829d32f71fe993cfa3e12339dede22115780e
BLAKE2b-256 checksum
How to use checksums
6a639449373f45e8d3ba1399c59f2ae2e5a998626d8b05902d9b5319f325c0d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / qqbot_sdk_python-0.4.2-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL qqbot_sdk_python-0.4.2-cp310-abi3-manylinux_2_28_x86_64.whl
Size 3.4 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
2c14ef570256e7228cced546cd4147f2aecdf8309a3dea6e9572da532f362533
BLAKE2b-256 checksum
How to use checksums
cde4b71746058628f4ec5ce9127b1fb076eea67b3cd3f3b245ceaa59c27d0fc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / qqbot_sdk_python-0.4.2-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL qqbot_sdk_python-0.4.2-cp310-abi3-manylinux_2_28_aarch64.whl
Size 3.4 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
ac4f9991519af85c797323dffc60f6c10a57a8411a6ba2e3e06fd1d367d08559
BLAKE2b-256 checksum
How to use checksums
d02b0defbde5b56b9393fd46e1344034f2482cd1dc0f72c2d701d7307f809d77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / qqbot_sdk_python-0.4.2-cp310-abi3-macosx_11_0_arm64.whl

Download URL qqbot_sdk_python-0.4.2-cp310-abi3-macosx_11_0_arm64.whl
Size 3.1 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b09be1cce395d500fb98a012b16beb5567846c035b59e99447bd7b86c7bbe9f0
BLAKE2b-256 checksum
How to use checksums
1f19342f1fa5d131a031687b37e87393b965ebd4ad509c51515e67f801922454
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / qqbot_sdk_python-0.4.2-cp310-abi3-macosx_10_12_x86_64.whl

Download URL qqbot_sdk_python-0.4.2-cp310-abi3-macosx_10_12_x86_64.whl
Size 3.2 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
cfa59a99a54890e78ee159dd02d88e862040e65589439fa44d9ce10b4a524d46
BLAKE2b-256 checksum
How to use checksums
0dddf4b9c7946ba4fa25ef6cbf9eedbc81b6187062a4cf651d4d0e6e59612289
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for qqbot-sdk-python 0.4.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for qqbot_sdk_python-0.4.2-cp310-abi3-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.2 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page