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

日历权限列表同样支持续页: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.1

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.6.1
File Size Uploaded Provenance Actions
wps365-0.6.1.tar.gz 131.5 kB Without provenance Details for wps365-0.6.1.tar.gz

Built distributions (wheels)

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

Total release size: 20.7 MB

Release files / wps365-0.6.1.tar.gz

Download URL wps365-0.6.1.tar.gz
Size 131.5 kB
Tags Source
SHA-256 checksum
How to use checksums
382b14430eaebcb01e354c081221d0f0229dbfbd1d4bcd6e008dfa077dda7497
BLAKE2b-256 checksum
How to use checksums
8549f5ada47e0cb57c33398d1a943c00eb39f1d347d5e5e26bf751d26af3d129
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.1-cp313-cp313-win_amd64.whl

Download URL wps365-0.6.1-cp313-cp313-win_amd64.whl
Size 4.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
050bdfa05288107dcf22d15f5ea865f7d38ee2bc3d40d07b277bb0568d6fdfbb
BLAKE2b-256 checksum
How to use checksums
1d00e018c9f46f61ae21f503c5345beb114eb634afad5a43e10380bc2a76d9a0
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.1-cp312-cp312-win_amd64.whl

Download URL wps365-0.6.1-cp312-cp312-win_amd64.whl
Size 4.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
f5485de98c6668f495c70ece56d0d5d5a12b1b5954e56314607a60f141be044f
BLAKE2b-256 checksum
How to use checksums
adb287a0f2cfdc09702345813d06a6dfc931545fe9ee1e0516a2aafe3f089058
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.1-cp311-cp311-win_amd64.whl

Download URL wps365-0.6.1-cp311-cp311-win_amd64.whl
Size 4.1 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
d7f10d6cd2ca6857a31a4b2bffc13b12859ab5002316882a27f84cabd3de3177
BLAKE2b-256 checksum
How to use checksums
edc20b42111071794138c3f10d1ece654723b9b015512de6cbf3bacb0e6d4d4c
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.1-cp310-cp310-win_amd64.whl

Download URL wps365-0.6.1-cp310-cp310-win_amd64.whl
Size 4.1 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
47c4143ebc5f8ea6356d24295bd38cd606f1084bf9971bffff820a6e4b324a3f
BLAKE2b-256 checksum
How to use checksums
4d918855fdcf7b7c08bdfa0061204c287a806c02a4b6a829998ce53d2aaa2a7e
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.1-cp39-cp39-win_amd64.whl

Download URL wps365-0.6.1-cp39-cp39-win_amd64.whl
Size 4.1 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
4730cf909f2d0516ebcbf72f0b07d1f267b407b44ebdd95d59e3f36e4c1577ec
BLAKE2b-256 checksum
How to use checksums
132deef5559d33205d3ba3e0313a888d6a3aed2da566be22b6f0b27a9a507213
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.1

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