Skip to main content

pywpsrpc

Build Status PyPI version Python version License: MIT

WPS Office for Linux二次开发C++接口Python绑定.

Read this in other languages: English

WPS Office二次开发接口

WPS二次开发接口允许开发者通过给定的接口来调起WPS并执行指定的任务, 比如你可以打开、编辑然后保存文档,转换文档格式等文档自动化操作,又或者将WPS嵌入到自己的程序、进行功能扩展等。

关于详细的接口文档,可参考

对于pywpsrpc本身的文档,可跳转到wiki查看。

依赖

  • Python 3.6+
  • Qt5 (C++ SDK依赖)
  • WPS Office for Linux 11.1.0.9080+
  • sip 6.0+ (仅编译)
  • qmake (仅编译)
  • g++ (仅编译)
  • 桌面环境(WPS运行需要)

PS,目前WPS整合模式有BUG,非把WPS嵌入到自己进程的场景建议先切换到多组件模式

如何编译

在项目顶层目录下运行终端执行: sip-build

如果需要查看编译相关输出信息,可添加 --verbose 选项

安装

建议通过PyPi安装:

pip install pywpsrpc

如果默认的源太慢,建议自行搜索添加中国pip源

通过源码编译安装:

先打包执行: sip-wheel

打包完成后再通过pip install pywpsrpc-*.whl命令安装

快速上手

# 第一步先import所需模块(rpcxxxapi,xxx为对应项目的名字)
# rpcwpsapi模块为WPS文字项目的开发接口
# rpcwppapi则是WPS演示的
# rpcetapi毫无疑问就是WPS表格的了
# 另外还有common模块,为前三者的公共接口模块,通常不能单独使用

# 调起WPS必需通过createXXXRpcInstance接口,所以导入它是必需的
# 以WPS文字为例
from pywpsrpc.rpcwpsapi import (createWpsRpcInstance, wpsapi)
from pywpsrpc import RpcIter


# 这里仅创建RPC实例
hr, rpc = createWpsRpcInstance()

# 注意:
# WPS开发接口的返回值第一个总是HRESULT(无返回值的除外)
# 通常不为0的都认为是调用失败(0 == common.S_OK)
# 可以使用common模块里的FAILED或者SUCCEEDED去判断

# 通过rpc实例调起WPS进程
hr, app = rpc.getWpsApplication()

# 比如添加一个空白文档
hr, doc = app.Documents.Add()

# 加点文字
selection = app.Selection
selection.InsertAfter("Hello, world")

# 将前面插入的"Hello, world"加粗
selection.Font.Bold = True

# 光标移到末尾
selection.EndKey()

# 再插入空段
selection.InsertParagraph()

# 光标移到新段
selection.MoveDown()

# 再码些文字
selection.TypeText("pywpsrpc~")

# 使用RpcIter遍历所有段
paras = doc.Paragraphs
for para in RpcIter(paras):
    print(para.Range.Text)

# 或者通过索引方式
for i in range(0, paras.Count):
    # 注意:首个元素总是从1开始
    print(paras[i + 1].OutlineLevel)

# 也支持VBA风格的call语法访问集合元素
first_para = paras(1)
print(first_para.Range.Text)

def onDocumentBeforeSave(doc):
    # 如果想取消当前文档保存,第二个返回值设为True
    print("onDocumentBeforeSave called for doc: ", doc.Name)
    # SaveAsUI, Cancel
    return True, False

# 注册文档保存前通知
rpc.registerEvent(app,
                  wpsapi.DIID_ApplicationEvents4,
                  "DocumentBeforeSave",
                  onDocumentBeforeSave)

# 保存文档, onDocumentBeforeSave会被调用到
doc.SaveAs2("test.docx")

# 退出WPS进程
# 使用wpsapi.wdDoNotSaveChanges来忽略文档改动
app.Quit(wpsapi.wdDoNotSaveChanges)

例子

文档互转

嵌入

WPS嵌入第三方进程窗口

在服务器上运行

点我查看

关于授权

pywpsrpc为MIT开源授权协议,项目本身允许商用,但前提是你所使用的WPS Office For Linux版本允许商用(目前个人版本即社区版本不允许),具体需要联系WPS官方咨询。对于不在合理范围使用本项目的,本项目不承担任何法律责任。

Metadata

Release files for pywpsrpc 2.4.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 pywpsrpc 2.4.0
File Size Uploaded Provenance Actions
pywpsrpc-2.4.0.tar.gz 10.2 MB With provenance Details for pywpsrpc-2.4.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pywpsrpc 2.4.0
File Actions
pywpsrpc-2.4.0-cp314-cp314-manylinux_2_5_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.5+ x86-64 Details for pywpsrpc-2.4.0-cp314-cp314-manylinux_2_5_x86_64.whl
pywpsrpc-2.4.0-cp313-cp313-manylinux_2_5_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.5+ x86-64 Details for pywpsrpc-2.4.0-cp313-cp313-manylinux_2_5_x86_64.whl
pywpsrpc-2.4.0-cp312-cp312-manylinux_2_5_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.5+ x86-64 Details for pywpsrpc-2.4.0-cp312-cp312-manylinux_2_5_x86_64.whl
pywpsrpc-2.4.0-cp311-cp311-manylinux_2_5_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.5+ x86-64 Details for pywpsrpc-2.4.0-cp311-cp311-manylinux_2_5_x86_64.whl
pywpsrpc-2.4.0-cp310-cp310-manylinux_2_5_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.5+ x86-64 Details for pywpsrpc-2.4.0-cp310-cp310-manylinux_2_5_x86_64.whl
pywpsrpc-2.4.0-cp39-cp39-manylinux_2_5_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.5+ x86-64 Details for pywpsrpc-2.4.0-cp39-cp39-manylinux_2_5_x86_64.whl
pywpsrpc-2.4.0-cp38-cp38-manylinux_2_5_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.5+ x86-64 Details for pywpsrpc-2.4.0-cp38-cp38-manylinux_2_5_x86_64.whl
pywpsrpc-2.4.0-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details for pywpsrpc-2.4.0-cp37-cp37m-manylinux1_x86_64.whl

Total release size: 112.9 MB

Release files / pywpsrpc-2.4.0.tar.gz

Download URL pywpsrpc-2.4.0.tar.gz
Size 10.2 MB
Tags Source
SHA-256 checksum
How to use checksums
f2af3b0c4d72f37592be16b3ced41b5bae366cb0fc4e23165d7ffb3457d80b7c
BLAKE2b-256 checksum
How to use checksums
b3be261ad7f6ca52c1b1f439b916e0e215add7ec9990b3a5349f91b374361c0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 20, 2026.

Transparency log

Release files / pywpsrpc-2.4.0-cp314-cp314-manylinux_2_5_x86_64.whl

Download URL pywpsrpc-2.4.0-cp314-cp314-manylinux_2_5_x86_64.whl
Size 7.9 MB
Tags CPython 3.14 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
0bfe103d7c8523d4b568f97990563ffaecb3f2b19d95470c2d926838e1296975
BLAKE2b-256 checksum
How to use checksums
3911e78db17521f6257fa164a892e269fc43cf4f2be1bc6d625c4d299e404070
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 20, 2026.

Transparency log

Release files / pywpsrpc-2.4.0-cp313-cp313-manylinux_2_5_x86_64.whl

Download URL pywpsrpc-2.4.0-cp313-cp313-manylinux_2_5_x86_64.whl
Size 7.9 MB
Tags CPython 3.13 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
49bfbfcbbef59b7ec6c0c2aa36f96588a3d13a09c4d37c5acfdd50cc7758ed66
BLAKE2b-256 checksum
How to use checksums
96bf3bb09265bfbb96a72a90627177be3a405e85fdc5edb0f407807035971b9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 20, 2026.

Transparency log

Release files / pywpsrpc-2.4.0-cp312-cp312-manylinux_2_5_x86_64.whl

Download URL pywpsrpc-2.4.0-cp312-cp312-manylinux_2_5_x86_64.whl
Size 7.9 MB
Tags CPython 3.12 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
4bb25edb4e33a1175701c71bbf0e8bf3a00f09e7cfbc85f0b7ccd9ebe24402e0
BLAKE2b-256 checksum
How to use checksums
d574612f60013e9e5b3625968cc219949107c67b51b09e7cd2ed53d0f0e5e1d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 20, 2026.

Transparency log

Release files / pywpsrpc-2.4.0-cp311-cp311-manylinux_2_5_x86_64.whl

Download URL pywpsrpc-2.4.0-cp311-cp311-manylinux_2_5_x86_64.whl
Size 7.9 MB
Tags CPython 3.11 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
88c1a09c1a6a3274735b389982c50486b9b610ccb8dc6cb262c78bbb7e13d94a
BLAKE2b-256 checksum
How to use checksums
b1399448d386d4e919156d9b79bafeb27b564094c7d8906d43301be0c01678c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 20, 2026.

Transparency log

Release files / pywpsrpc-2.4.0-cp310-cp310-manylinux_2_5_x86_64.whl

Download URL pywpsrpc-2.4.0-cp310-cp310-manylinux_2_5_x86_64.whl
Size 7.9 MB
Tags CPython 3.10 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
7f6d84fee2f65c73ab015d314431dd9d34c33c3c62c57471586a138ebf339618
BLAKE2b-256 checksum
How to use checksums
e9507f9053948c7a67d660b4030281b053bae9df370cb669d69c1b4fe6bb57c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 20, 2026.

Transparency log

Release files / pywpsrpc-2.4.0-cp39-cp39-manylinux_2_5_x86_64.whl

Download URL pywpsrpc-2.4.0-cp39-cp39-manylinux_2_5_x86_64.whl
Size 47.5 MB
Tags CPython 3.9 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
0fe4e996ae6632dc819c3113cace0804beeee2db92a393cc19b0317bd456d7aa
BLAKE2b-256 checksum
How to use checksums
bb6f24951216401ce3f3f9c1b502affa082251b386f75aff8617c452401d328c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 20, 2026.

Transparency log

Release files / pywpsrpc-2.4.0-cp38-cp38-manylinux_2_5_x86_64.whl

Download URL pywpsrpc-2.4.0-cp38-cp38-manylinux_2_5_x86_64.whl
Size 7.9 MB
Tags CPython 3.8 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
a2e78c05f8a4882358ea85795c62fd54163732537f9718aa55781be2e725e2d2
BLAKE2b-256 checksum
How to use checksums
bc9ca6239631acc03bd1b120cd9c71acd2c175ce2bdbf9e6a8747a45143ee8a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 20, 2026.

Transparency log

Release files / pywpsrpc-2.4.0-cp37-cp37m-manylinux1_x86_64.whl

Download URL pywpsrpc-2.4.0-cp37-cp37m-manylinux1_x86_64.whl
Size 7.9 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
5be044643c12a1a44be12ff9eba5895685195df9fe298b18ba06a2e74ddc780f
BLAKE2b-256 checksum
How to use checksums
4cc1dc501ea28c1ec76e33612c14e5c296e111e7f44078b0f7f688cea5d29e0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 20, 2026.

Transparency log

Security for pywpsrpc 2.4.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.

Full provenance

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

Select from 9 files

Attestation for pywpsrpc-2.4.0.tar.gz

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 Jun 20, 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.

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