Skip to main content

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,
    )

AirPage v2 raw 块操作

高层 doc_append_markdown / doc_replace_markdown / doc_update_block 继续提供常用组合路径;需要官方完整请求和响应时使用四个 raw 入口:

converted = client.doc_convert_blocks("OTL_FILE_ID", "<p>正文</p>", format="html")
created = client.doc_create_blocks("OTL_FILE_ID", {
    "block_id": "doc",
    "doc_children": {"children": converted["blocks"]},
    # 省略 index 时由服务端默认 0;高层 Markdown 写入仍默认 1(标题后)。
})
updated = client.doc_batch_update_blocks("OTL_FILE_ID", operations=[{
    "block_id": "title",
    "update_elements": {"paragraph_elements": {"elements": [
        {"text": {"attributes": {"content": "新标题"}}},
    ]}},
}])
# 删除前必须独立确认目标文档和范围;创建/更新授权不代表删除授权。
deleted = client.doc_batch_delete_blocks("OTL_FILE_ID", operations=[{
    "block_id": "doc", "start_index": 1, "end_index": 2,
}])

四个入口沿用项目 API 约定,返回服务端 data 对象并保留其中的扩展字段(不含 code 等外层 envelope),并在发网前校验基本 schema 边界(content/format、create body、1~100 项 operations)及响应必填字段。v2 doc.children 与 create/batch_delete 索引不包含独立 title,正文首块索引为 0;不要直接套用包含 title 的 v1 展示位置。它们只是已有 operation 的公开封装,不增加 205/835 的直接 operation 计数;离线 loopback 通过不等于真实线上写删已验证。

日历权限列表同样支持续页: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 平铺全部 237 个方法(认证 / 云盘 / 文件 / 智能文档 / 待办 / 组织 / 知识库 / 日历 / 邮箱 / 消息 / 会议 / 审批 / 表格三件套 / 搜索 / 收藏 / 回收站 / 评论 / 标签),完整签名见随包分发的 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.7.0

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

Source distribution (sdist)

Source distribution for wps365 0.7.0
File Size Uploaded Provenance Actions
wps365-0.7.0.tar.gz 142.1 kB Without provenance Details for wps365-0.7.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for wps365 0.7.0
File Actions
wps365-0.7.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for wps365-0.7.0-cp313-cp313-win_amd64.whl
wps365-0.7.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for wps365-0.7.0-cp312-cp312-win_amd64.whl
wps365-0.7.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for wps365-0.7.0-cp311-cp311-win_amd64.whl
wps365-0.7.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for wps365-0.7.0-cp310-cp310-win_amd64.whl
wps365-0.7.0-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details for wps365-0.7.0-cp39-cp39-win_amd64.whl

Total release size: 21.0 MB

Release files / wps365-0.7.0.tar.gz

Download URL wps365-0.7.0.tar.gz
Size 142.1 kB
Tags Source
SHA-256 checksum
How to use checksums
61dc4566b24a42a965257801f58aec288a09bcb78323d7ae66408f63ea82925b
BLAKE2b-256 checksum
How to use checksums
4a42866df8fbd1239d03bbaf02dc2e8098bc9c0c17147104ca12accb811bc7a0
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.7.0-cp313-cp313-win_amd64.whl

Download URL wps365-0.7.0-cp313-cp313-win_amd64.whl
Size 4.2 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
292e0f733a9ecbfe9261e933426d578f99180c4220df05ffe5a94726b67e2b02
BLAKE2b-256 checksum
How to use checksums
876d3f3bc22916d818528c9de94311d686295bc3960b79782db2d14fe1e53158
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.7.0-cp312-cp312-win_amd64.whl

Download URL wps365-0.7.0-cp312-cp312-win_amd64.whl
Size 4.2 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
bf536828c25b83297a4f474b4b958f20c93ce0753efefd8bfe661cd4679ec1b5
BLAKE2b-256 checksum
How to use checksums
2049b779e90b45981874f575ec3c518d08c3914b32dc137e1dc7e76ea772e963
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.7.0-cp311-cp311-win_amd64.whl

Download URL wps365-0.7.0-cp311-cp311-win_amd64.whl
Size 4.2 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
285b40e0c84f6970d8b32f0216675e06a74a19fd6408ea26113395c9a50b54c6
BLAKE2b-256 checksum
How to use checksums
6c67fb0af3a1f39213f30402e743197c90f52a6cb90e20200615f2fdc908e02b
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.7.0-cp310-cp310-win_amd64.whl

Download URL wps365-0.7.0-cp310-cp310-win_amd64.whl
Size 4.2 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
be64f9db44f7b87f10a65ae923ec6ce63a53d41305c67da6cfc1089285da435d
BLAKE2b-256 checksum
How to use checksums
e2d9bba1d4cb71474d9ee395f92f3ea51b81bc1eab5b07c5df5d2c3aa0bc8a43
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.7.0-cp39-cp39-win_amd64.whl

Download URL wps365-0.7.0-cp39-cp39-win_amd64.whl
Size 4.2 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
bf998e45f60596cc10804ad764b0df32448b70393beaff9afbf98427442ef107
BLAKE2b-256 checksum
How to use checksums
3e00c69e6203871e374daf3781c7b57a17037582a95727a17900cf97b09d6cc8
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.7.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.

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