跳转到主要内容

将C++实现的google-diff-match-patch打包为Python,用于快速字节和字符串比较。

项目描述

fast_diff_match_patch: 包装google-diff-match-patch C++实现的Python包

这是一个Python 3.6+包,它包装了google-diff-match-patch的C++实现,用于执行非常快速的字符串比较。这个包之前被称为diff_match_patch_python。

google-diff-match-patch是Google的一个库,用于计算文本文件之间的差异(http://code.google.com/p/google-diff-match-patch)。有各种语言的实现。虽然有一个Python端口,但它在非常大的文档上速度较慢,而我需要速度。我想使用C++实现,但我是个Python人,所以我更喜欢从Python中使用它。

Google的库依赖于Qt 4,因此有其他人用标准的C++库类重写了它,使其更便携。在https://github.com/leutloff/diff-match-patch-cpp-stl。这个包使用了那个库。

示例

首先

pip3 install fast_diff_match_patch

然后写入(这是Python 3)

from fast_diff_match_patch import diff

changes = diff("Hello world.", "Goodbye moon.")

for op, length in changes:
    if op == "-": print ("next", length, "characters are deleted")
    if op == "=": print ("next", length, "characters are in common")
    if op == "+": print ("next", length, "characters are inserted")

两个文本参数可以是字符串或字节。

也有一些关键字参数可用

timelimit(默认值为0)给出了最大运行时间(秒),如果您想确保结果快速返回。根据Google文档,如果在时间超出后,diff将停止工作并返回一个有效的diff,但它可能不是最好的一个。checklines也是Google的东西,可能会加快基于行文本(如代码)的diff速度。

checklines(默认为 True)与主库的 diff_main 子例程中的参数相同。

cleanup(默认为 "Semantic")可以是 "Semantic""Efficiency""No",表示在执行 diff 后运行相应的清理子例程。

counts_only(默认为 True)设置为 False,以便返回的操作与相应字符串的元组数组,而不是操作及其字符串长度的数组。

如果 as_patch(默认为 False)为 True,则 diff 以字符串形式的补丁格式返回。

在执行 diff 时释放全局解释器锁(GIL),以便此库可用于多线程应用程序。

变更日志

版本 2.0.1

  • 现在对字节字符串的 diff 是空字符安全的。
  • 修复了 as_patch 参数。

版本 2.0.0

  • 已将导入重命名为 diff_match_patchfast_diff_match_patch 以避免与 https://pypi.ac.cn/project/diff-match-patch/ 的导入命名冲突,并将包名更新以匹配导入名。
  • 在此包的先前版本中,提供了单独的 diff_bytes(Py3)、diff_unicodediff_str(Py2)方法。它们已被合并为单个 diff 方法,该方法检查传入参数的类型。
  • cleanup_semantic 已重命名为 cleanup,它接受三种选项之一(见上文)
  • 在 Windows 上,如果字符串包含基本多语言平面之外的字符,将抛出异常。

从源代码构建

要从这些源代码构建,您需要

  • Python 开发头文件和 setuptools 包(Debian 包 python3-devpython3-setuptools
  • diff-match-patch 库,您可以使用 git submodule update --init 来克隆。

然后使用以下命令构建/安装二进制模块

python setup.py build
python setup.py install

对于包维护者

构建一切(用于测试)

git submodule update && rm -rf build && python3 setup.py build

不安装进行测试

PYTHONPATH=build/lib.linux-x86_64-*/ python3 -m unittest

发布包(wheel 和源分发)使用此存储库中的 GitHub Actions 构建。要将它们作为新的发布版本上传到 PyPi,请下载工件并将其文件提取到新目录中,然后

python3 -m pip install --upgrade twine
python3 -m twine upload -u __token__ path-to-artifact-files/*

项目详情


下载文件

下载适用于您平台的项目文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分发

fast_diff_match_patch-2.1.0.tar.gz (36.0 kB 查看散列值

上传时间:

构建的分发

fast_diff_match_patch-2.1.0-pp310-pypy310_pp73-win_amd64.whl (76.4 kB 查看散列值

上传时间: PyPy Windows x86-64

fast_diff_match_patch-2.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (95.2 kB 查看散列值

上传时间: PyPy manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (99.4 kB 查看哈希值)

上传时间 PyPy manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-pp310-pypy310_pp73-macosx_10_9_x86_64.whl (84.7 kB 查看哈希值)

上传时间 PyPy macOS 10.9+ x86-64

fast_diff_match_patch-2.1.0-pp39-pypy39_pp73-win_amd64.whl (76.4 kB 查看哈希值)

上传时间 PyPy Windows x86-64

fast_diff_match_patch-2.1.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (95.2 kB 查看哈希值)

上传时间 PyPy manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (99.4 kB 查看哈希值)

上传时间 PyPy manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (84.7 kB 查看哈希值)

上传时间 PyPy macOS 10.9+ x86-64

fast_diff_match_patch-2.1.0-pp38-pypy38_pp73-win_amd64.whl (76.4 kB 查看哈希值)

上传时间 PyPy Windows x86-64

fast_diff_match_patch-2.1.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (95.2 kB 查看哈希值)

上传时间 PyPy manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (99.6 kB 查看哈希值)

上传时间 PyPy manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (84.5 kB 查看哈希值)

上传于 PyPy macOS 10.9+ x86-64

fast_diff_match_patch-2.1.0-pp37-pypy37_pp73-win_amd64.whl (76.4 kB 查看哈希值)

上传于 PyPy Windows x86-64

fast_diff_match_patch-2.1.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (97.1 kB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (101.2 kB 查看哈希值)

上传于 PyPy manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (84.5 kB 查看哈希值)

上传于 PyPy macOS 10.9+ x86-64

fast_diff_match_patch-2.1.0-cp312-cp312-win_amd64.whl (76.5 kB 查看哈希值)

上传于 CPython 3.12 Windows x86-64

fast_diff_match_patch-2.1.0-cp312-cp312-win32.whl (67.8 kB 查看哈希值)

上传于 CPython 3.12 Windows x86

fast_diff_match_patch-2.1.0-cp312-cp312-musllinux_1_1_x86_64.whl (1.5 MB 查看哈希值)

上传于 CPython 3.12 musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.1.0-cp312-cp312-musllinux_1_1_i686.whl (1.5 MB 查看哈希值)

上传于 CPython 3.12 musllinux: musl 1.1+ i686

fast_diff_match_patch-2.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (855.5 kB 查看哈希值)

上传于 CPython 3.12 manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (834.5 kB 查看哈希值)

上传于 CPython 3.12 manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-cp312-cp312-macosx_11_0_arm64.whl (83.3 kB 查看哈希值)

上传于 CPython 3.12 macOS 11.0+ ARM64

fast_diff_match_patch-2.1.0-cp312-cp312-macosx_10_9_x86_64.whl (97.6 kB 查看哈希值)

上传于 CPython 3.12 macOS 10.9+ x86-64

fast_diff_match_patch-2.1.0-cp312-cp312-macosx_10_9_universal2.whl (171.1 kB 查看哈希值)

上传于 CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

fast_diff_match_patch-2.1.0-cp311-cp311-win_amd64.whl (76.4 kB 查看哈希值)

上传于 CPython 3.11 Windows x86-64

fast_diff_match_patch-2.1.0-cp311-cp311-win32.whl (67.7 kB 查看哈希值)

上传于 CPython 3.11 Windows x86

fast_diff_match_patch-2.1.0-cp311-cp311-musllinux_1_1_x86_64.whl (1.5 MB 查看哈希值)

上传于 CPython 3.11 musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.1.0-cp311-cp311-musllinux_1_1_i686.whl (1.5 MB 查看哈希值)

上传于 CPython 3.11 musllinux: musl 1.1+ i686

fast_diff_match_patch-2.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (855.0 kB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (833.6 kB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-cp311-cp311-macosx_11_0_arm64.whl (83.2 kB 查看哈希值)

上传于 CPython 3.11 macOS 11.0+ ARM64

fast_diff_match_patch-2.1.0-cp311-cp311-macosx_10_9_x86_64.whl (97.4 kB 查看哈希值)

上传时间: CPython 3.11 macOS 10.9+ x86-64

fast_diff_match_patch-2.1.0-cp311-cp311-macosx_10_9_universal2.whl (170.8 kB 查看哈希值)

上传时间: CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

fast_diff_match_patch-2.1.0-cp310-cp310-win_amd64.whl (76.4 kB 查看哈希值)

上传时间: CPython 3.10 Windows x86-64

fast_diff_match_patch-2.1.0-cp310-cp310-win32.whl (67.7 kB 查看哈希值)

上传时间: CPython 3.10 Windows x86

fast_diff_match_patch-2.1.0-cp310-cp310-musllinux_1_1_x86_64.whl (1.5 MB 查看哈希值)

上传时间: CPython 3.10 musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.1.0-cp310-cp310-musllinux_1_1_i686.whl (1.5 MB 查看哈希值)

上传时间: CPython 3.10 musllinux: musl 1.1+ i686

fast_diff_match_patch-2.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (854.0 kB 查看哈希值)

上传时间: CPython 3.10 manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (832.5 kB 查看哈希值)

上传时间: CPython 3.10 manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-cp310-cp310-macosx_11_0_arm64.whl (83.2 kB 查看哈希值)

上传时间: CPython 3.10 macOS 11.0+ ARM64

fast_diff_match_patch-2.1.0-cp310-cp310-macosx_10_9_x86_64.whl (97.5 kB 查看哈希值)

上传时间: CPython 3.10 macOS 10.9+ x86-64

fast_diff_match_patch-2.1.0-cp310-cp310-macosx_10_9_universal2.whl (170.8 kB 查看哈希值)

上传时间 CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

fast_diff_match_patch-2.1.0-cp39-cp39-win_amd64.whl (76.4 kB 查看哈希值)

上传时间 CPython 3.9 Windows x86-64

fast_diff_match_patch-2.1.0-cp39-cp39-win32.whl (67.7 kB 查看哈希值)

上传时间 CPython 3.9 Windows x86

fast_diff_match_patch-2.1.0-cp39-cp39-musllinux_1_1_x86_64.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.9 musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.1.0-cp39-cp39-musllinux_1_1_i686.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.9 musllinux: musl 1.1+ i686

fast_diff_match_patch-2.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (853.6 kB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (832.2 kB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-cp39-cp39-macosx_11_0_arm64.whl (83.2 kB 查看哈希值)

上传时间 CPython 3.9 macOS 11.0+ ARM64

fast_diff_match_patch-2.1.0-cp39-cp39-macosx_10_9_x86_64.whl (97.4 kB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ x86-64

fast_diff_match_patch-2.1.0-cp39-cp39-macosx_10_9_universal2.whl (170.8 kB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

fast_diff_match_patch-2.1.0-cp38-cp38-win_amd64.whl (76.4 kB 查看哈希值)

上传时间 CPython 3.8 Windows x86-64

fast_diff_match_patch-2.1.0-cp38-cp38-win32.whl (67.7 kB 查看哈希值)

上传时间 CPython 3.8 Windows x86

fast_diff_match_patch-2.1.0-cp38-cp38-musllinux_1_1_x86_64.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.8 musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.1.0-cp38-cp38-musllinux_1_1_i686.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.8 musllinux: musl 1.1+ i686

fast_diff_match_patch-2.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (853.6 kB 查看哈希值)

上传时间 CPython 3.8 manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (832.2 kB 查看哈希值)

上传时间 CPython 3.8 manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-cp38-cp38-macosx_11_0_arm64.whl (83.2 kB 查看哈希值)

上传时间 CPython 3.8 macOS 11.0+ ARM64

fast_diff_match_patch-2.1.0-cp38-cp38-macosx_10_9_x86_64.whl (97.4 kB 查看哈希值)

上传时间 CPython 3.8 macOS 10.9+ x86-64

fast_diff_match_patch-2.1.0-cp38-cp38-macosx_10_9_universal2.whl (170.8 kB 查看哈希值)

上传时间 CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

fast_diff_match_patch-2.1.0-cp37-cp37m-win_amd64.whl (76.4 kB 查看哈希值)

上传时间 CPython 3.7m Windows x86-64

fast_diff_match_patch-2.1.0-cp37-cp37m-win32.whl (67.7 kB 查看哈希值)

上传时间 CPython 3.7m Windows x86

fast_diff_match_patch-2.1.0-cp37-cp37m-musllinux_1_1_x86_64.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.7m musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.1.0-cp37-cp37m-musllinux_1_1_i686.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.7m musllinux: musl 1.1+ i686

fast_diff_match_patch-2.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (854.4 kB 查看哈希值)

上传时间 CPython 3.7m manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (833.9 kB 查看哈希值)

上传时间 CPython 3.7m manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-cp37-cp37m-macosx_10_9_x86_64.whl (97.4 kB 查看哈希值)

上传时间 CPython 3.7m macOS 10.9+ x86-64

fast_diff_match_patch-2.1.0-cp36-cp36m-win_amd64.whl (76.4 kB 查看哈希值)

上传时间 CPython 3.6m Windows x86-64

fast_diff_match_patch-2.1.0-cp36-cp36m-win32.whl (67.7 kB 查看哈希值)

上传时间 CPython 3.6m Windows x86

fast_diff_match_patch-2.1.0-cp36-cp36m-musllinux_1_1_x86_64.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.6m musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.1.0-cp36-cp36m-musllinux_1_1_i686.whl (1.5 MB 查看哈希值)

上传时间 CPython 3.6m musllinux: musl 1.1+ i686

fast_diff_match_patch-2.1.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (853.1 kB 查看哈希值)

上传时间: CPython 3.6m manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.1.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (832.5 kB 查看哈希值)

上传时间: CPython 3.6m manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.1.0-cp36-cp36m-macosx_10_9_x86_64.whl (97.4 kB 查看哈希值)

上传时间: CPython 3.6m macOS 10.9+ x86-64

支持者