wps365 — WPS365 全域业务 API Python 绑定
WPS365 云文档工具(wps365-rs)的 Python 绑定:基于 PyO3 将核心库编译为 CPython 扩展模块,提供云盘文件与智能文档修改/导出、待办、组织架构、知识库、日历日程、邮箱、消息、会议、审批、传统/智能/多维表格等全域能力的同步 Python API。
CLI 与桌面 GUI 用法见仓库根 README,本页仅覆盖 Python 绑定。
安装
pip install wps365 # 或 uv pip install wps365
已发布至 PyPI:CDYLIB 扩展,无 Python 侧运行时依赖。
源码构建(开发用)
# 仓库根目录:uv 管理的 venv + maturin
uv venv .venv --python 3.13
uv pip install --python .venv maturin
# 构建并安装到 venv(editable,改 Rust 代码后重复执行即可)
cd crates/wps365-python
VIRTUAL_ENV=<仓库根>/.venv ../../.venv/Scripts/maturin develop
# 或只出分发物
uv build --wheel
快速上手
from wps365 import Client, Wps365Error
client = Client() # 凭据解析:构造参数 > 环境变量 > 配置文件
# client = Client(sid="V02S...") # 也可直接传入 wps_sid
for item in client.search("季度报告"):
print(item["name"], item["link_url"])
result = client.upload(r"D:\报告.xlsx", folder="项目文档", share=True)
info = client.download(result["file_id"], dest="./下载")
text = client.read(result["file_id"])["markdown"] # 在线文档抽取正文
filtered = client.read(
result["file_id"], include_elements="para,table"
) # 元素筛选:para/table/component/textbox/all,默认 all
first = client.versions(result["file_id"], page_size=50)
if token := first.get("next_page_token"):
second = client.versions(
result["file_id"],
page_size=50,
page_token=token,
with_comment=True,
with_ext_attrs=True,
)
日历权限列表同样支持续页:client.calendar_permission_list(calendar_id, page_size=50, page_token=token);token 取上一页的 next_page_token,缺省为 None。
团队文档库列表支持官方续页与角色筛选:client.list_doclibs(page_size=50, page_token=token, user_role="owner,admin")。page_token / user_role 缺省均为 None;角色可选 owner、admin、normal,多个角色用英文逗号分隔,原始响应中的 next_page_token 可用于下一页。
工作待办使用与官方一致的 Cookie 通道及 users/current → todo/tasks/batch_get 流程:client.todo_list_work(page_size=20, page_token=token, status="todo", appid="app_x", order="desc", sort="create_time")。page_token 取上一页响应的 next_offset;默认每页数量已从旧版 50 对齐为官方 20,显式传 page_size=50 可保留原数量。
日历参会人增删按官方结构发送 {"type":"user","user_id":...},会议室增删的 room_ids 为字符串数组;公开方法签名不变。calendar_event_create 的 RFC3339 便捷封装使用官方 start_time/end_time.datetime,不再误写 date_time。
IM 的 im_chat_create / im_member_list 已对齐官方 Internal 扩展的 Cookie 通道;im_member_add / im_member_remove 同样使用 Cookie,成员对象为 {"id":...,"type":"user"}。公开方法签名不变。
user_get(user_id, with_dept=True) 按官方规范发送 with_dept=true,不再把布尔值误写为字段名字符串;公开方法签名不变。
user_batch_read / dept_batch_read 已对齐官方 Cookie POST 数组 body。user_batch_read(user_ids, status="active", with_dept=True) 可附加状态筛选与部门信息;旧调用只传 ID 列表时行为与官方默认请求一致。
wiki_search 已对齐官方 Bearer POST 请求,space_ids 转为字符串数组。可选 page_token 取上一页 next_page_token,with_total=True 返回命中总数;旧调用只传 keyword/page_size/space_ids 的签名保持兼容。
aidocs_recall 已对齐官方 drives:[{"drive_id":...}] 请求,缺省 topk=5,并支持可选 scene="full_folder_recall";旧的位置参数顺序不变。
aidocs_search 新增 session_id/group_names/prompt_system/prompt_template。使用任一官方新选项时需同时提供 session_id、drive_ids、group_names;不传这些选项的旧调用继续使用实测兼容字段,便于平滑迁移。
Client 平铺全部 230 个方法(认证 / 云盘 / 文件 / 智能文档 / 待办 / 组织 / 知识库 / 日历 / 邮箱 / 消息 / 会议 / 审批 / 表格三件套 / 搜索 / 收藏 / 回收站 / 评论 / 标签),完整签名见随包分发的 wps365.pyi(IDE 自动补全开箱可用)。所有方法为同步阻塞调用,执行期间释放 GIL;返回值为 openapi 原始响应序列化而来的 dict / list / str。
凭据
优先级(首个非空者生效):构造参数 sid > 环境变量 WPS_SID > wps_sid > COOKIE(解析其中 wps_sid 字段)> 配置文件 auth_state.wps_sid。
环境变量与 COOKIE 中的凭据只在运行时内存中使用,不会复制进 config.ron;旧配置中已有的 auth_state.wps_sid 仍保持兼容。
显式 sid 会在 HTTP 客户端建立前绑定身份,Bearer token 按 wps_sid 隔离缓存;个人盘 ID 与认证状态使用独立的内存配置,不继承或写回共享配置。构造后需要切换身份时,请新建 Client(sid=...);ensure_auth(sid) 只校验凭据是否可解析,不会替换现有 HTTP 通道的身份。
获取 wps_sid:浏览器登录 kdocs.cn → F12 → Application → Cookies → 复制 wps_sid 值。
错误处理
全部错误以 Wps365Error(Exception 子类)抛出,消息格式为「[机器错误码] 描述」,错误码与 CLI 一致(AUTH_EXPIRED_NO_SID / INVALID_PARAM / API_ERROR / IO_ERROR 等),可按前缀分支处理。通用 JSON 请求会把所有非 2xx 响应视为错误,即使响应缺少业务 code 或包含 code:0;2xx 的既有无 code 内部响应保持兼容。
静态检查
- mypy / Pyright(Pylance):开箱即用,读取随包分发的
wps365.pyi。 - Pylint:默认不导入 C 扩展,会对
wps365.Client等成员误报no-member(E1101),需在使用方项目放行:
# 使用方项目的 pyproject.toml(或同目录 .pylintrc)
[tool.pylint.main]
extension-pkg-allow-list = ["wps365"]
测试
cd crates/wps365-python
../../.venv/Scripts/python.exe -m pytest tests/ -v # 离线冒烟
WPS365_PYTHON_LIVE=1 ../../.venv/Scripts/python.exe -m pytest tests/ -v # 含真实 API 用例
License
MIT
Metadata
Release files for wps365 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wps365-0.6.0.tar.gz | 128.9 kB | Without provenance | Details for wps365-0.6.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| wps365-0.6.0-cp313-cp313-win_amd64.whl | CPython 3.13 | CPython 3.13 | Windows x86-64 | Details for wps365-0.6.0-cp313-cp313-win_amd64.whl |
| wps365-0.6.0-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details for wps365-0.6.0-cp312-cp312-win_amd64.whl |
| wps365-0.6.0-cp311-cp311-win_amd64.whl | CPython 3.11 | CPython 3.11 | Windows x86-64 | Details for wps365-0.6.0-cp311-cp311-win_amd64.whl |
| wps365-0.6.0-cp310-cp310-win_amd64.whl | CPython 3.10 | CPython 3.10 | Windows x86-64 | Details for wps365-0.6.0-cp310-cp310-win_amd64.whl |
| wps365-0.6.0-cp39-cp39-win_amd64.whl | CPython 3.9 | CPython 3.9 | Windows x86-64 | Details for wps365-0.6.0-cp39-cp39-win_amd64.whl |
Total release size: 20.7 MB
Release files / wps365-0.6.0.tar.gz
| Download URL | wps365-0.6.0.tar.gz |
|---|---|
| Size | 128.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a55f04ad0fdf30b916ad1e449a01a503271544e9a5b70885e01f4d3c2563fe9f
|
|
BLAKE2b-256 checksum How to use checksums |
f7f2e0a91765d5f52e4b6196d33dca6b77f0029df32b5a293913703b026da141
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / wps365-0.6.0-cp313-cp313-win_amd64.whl
| Download URL | wps365-0.6.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e7a607a4466de76e5116c4ae5b8998dfe5bc772ec5b15b87a905549701e203d7
|
|
BLAKE2b-256 checksum How to use checksums |
37293d4c06e015e3e153412cfe9388e9c262960f77234b6df65df24ecd6ffe96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / wps365-0.6.0-cp312-cp312-win_amd64.whl
| Download URL | wps365-0.6.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6534b9fce557b0ebff0aadfe9dfe1a789ed0fa370f0a651459ba1ceabf2201a0
|
|
BLAKE2b-256 checksum How to use checksums |
a9346a6f4ed659b79bde8780a794a8919225285d20f97aba033917909babf9bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / wps365-0.6.0-cp311-cp311-win_amd64.whl
| Download URL | wps365-0.6.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
cd682ce168b30950b0c979d34f19c56e5ee4e09a79ffba72eecc510af0f5a28d
|
|
BLAKE2b-256 checksum How to use checksums |
c1833e3842286b6c11274976a6e7a4f87b4f32bbb6e89cadb1a69d4f7b10cb80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / wps365-0.6.0-cp310-cp310-win_amd64.whl
| Download URL | wps365-0.6.0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a851e56c6f3fe393185e298b9cdf8c8359e9e85070cedf291312e0ffbff7798a
|
|
BLAKE2b-256 checksum How to use checksums |
a8def535e169899c71182df96e82e08950729219aa00d6d864eeb57685195ae9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / wps365-0.6.0-cp39-cp39-win_amd64.whl
| Download URL | wps365-0.6.0-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2a491ad79cb3f7d0bd198b0f7f1a1386f7b840ea9827f5bcb35e886f423c1df5
|
|
BLAKE2b-256 checksum How to use checksums |
3166300db11def05c4d5aa92c042a0d7245eb616aa5914191b48d476e01dba71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for wps365 0.6.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.