Skip to main content

fast_diff_match_patch: Python package wrapping the C++ implementation of google-diff-match-patch

Project description

fast_diff_match_patch: Python package wrapping the C++ implementation of google-diff-match-patch

This is a Python 3.6+ package that wraps google-diff-match-patch's C++ implementation for performing very fast string comparisons. This package was previously known as diff_match_patch_python.

google-diff-match-patch is a Google library for computing differences between text files (http://code.google.com/p/google-diff-match-patch). There are implementations in various languages. Although there is a Python port, it's slow on very large documents, and I have a need for speed. I wanted to use the C++ implementation, but I'm a Python guy so I'd prefer to use it from Python.

Google's library depends on Qt 4, so some other folks rewrote it using the standard C++ library classes instead, making it more portable. That's at https://github.com/leutloff/diff-match-patch-cpp-stl. This package uses that library.

(This package can hopefully still be built for Python 2.7 also but a pre-built package is not available.)

Example

First:

pip3 install fast_diff_match_patch

Then write (this is 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")

The two textual arguments can be either strings or bytes (Unicode or str on Python 2.x).

Some keyword arguments are also available:

timelimit (default 0) gives the maximum running time in seconds if you want to ensure the result comes quickly. According to the Google docs, the diff will stop working after the time is exceeded and will return a valid diff, but it might not be the best one. checklines is also a Google thing and might speed up diffs that are over lined-based text like code.

checklines (default True) is the same argument in the diff_main subroutine of the main library.

cleanup (default "Semantic") is "Semantic", "Efficiency", or "No" to run the corresponding cleanup subroutine after performing the diff.

Set counts_only (default True) to False to have the returned value be an array of tuples of operations and corresponding strings rather than operations and the lengths of those strings.

If as_patch (default False) is True, the diff is returned in patch format as a string.

On Windows, an exception will be thrown if either of the two text strings has characters outside of the Basic Multilingual Plane because the native platform character type is a two-byte character. The fast_diff_match_patch.CHAR_WIDTH field, which will either be 2 or 4, can be used to determine whether these characters are supported ahead of time.

The Global Interpreter Lock (GIL) is released while performing the diff so that this library can be used in a multi-threaded application.

Changes in version 2.0.0

  • The import has been renamed from diff_match_patch to fast_diff_match_patch to avoid an import naming collision with https://pypi.org/project/diff-match-patch/ and the package name has been updated to match the import name.
  • In previous versions of this package, separate diff_bytes (Py3), diff_unicode and diff_str (Py2) methods were available. They have been merged into a single diff method that checks the type of the arguments passed.)
  • On Windows, an exception will be thrown if a string has characters outside of the Basic Multilingual Plane.

Building from source

To build from these sources, you will need:

  • Python development headers and the setuptools package (Debian packages python3-dev, python3-setuptools)
  • The diff-match-patch library, which you can clone using git submodule update --init.

Then build/install the binary module using:

python setup.py build
python setup.py install

For package maintainers

To build everything:

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

To test without installing:

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

To upload a new release to PyPi:

  • Install twine: python3 -m pip install --upgrade twine
  • manylinux wheels are built automatically on GitHub Actions.
  • Download the artifact and extract the files to a new directory.
  • Upload them: python3 -m twine upload path-to-artifact-files/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fast_diff_match_patch-2.0.1.tar.gz (36.4 kB view hashes)

Uploaded Source

Built Distributions

fast_diff_match_patch-2.0.1-pp310-pypy310_pp73-win_amd64.whl (75.0 kB view hashes)

Uploaded PyPy Windows x86-64

fast_diff_match_patch-2.0.1-pp39-pypy39_pp73-win_amd64.whl (74.9 kB view hashes)

Uploaded PyPy Windows x86-64

fast_diff_match_patch-2.0.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (66.1 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

fast_diff_match_patch-2.0.1-pp38-pypy38_pp73-win_amd64.whl (74.9 kB view hashes)

Uploaded PyPy Windows x86-64

fast_diff_match_patch-2.0.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (66.2 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

fast_diff_match_patch-2.0.1-pp37-pypy37_pp73-win_amd64.whl (74.9 kB view hashes)

Uploaded PyPy Windows x86-64

fast_diff_match_patch-2.0.1-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (85.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

fast_diff_match_patch-2.0.1-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (91.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

fast_diff_match_patch-2.0.1-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (66.0 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

fast_diff_match_patch-2.0.1-cp312-cp312-win_amd64.whl (75.0 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

fast_diff_match_patch-2.0.1-cp312-cp312-win32.whl (67.0 kB view hashes)

Uploaded CPython 3.12 Windows x86

fast_diff_match_patch-2.0.1-cp312-cp312-musllinux_1_1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.0.1-cp312-cp312-musllinux_1_1_i686.whl (1.5 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

fast_diff_match_patch-2.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (802.6 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.0.1-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (786.3 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.0.1-cp311-cp311-win_amd64.whl (75.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

fast_diff_match_patch-2.0.1-cp311-cp311-win32.whl (66.9 kB view hashes)

Uploaded CPython 3.11 Windows x86

fast_diff_match_patch-2.0.1-cp311-cp311-musllinux_1_1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.0.1-cp311-cp311-musllinux_1_1_i686.whl (1.5 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

fast_diff_match_patch-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (802.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.0.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (786.4 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.0.1-cp310-cp310-win_amd64.whl (75.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

fast_diff_match_patch-2.0.1-cp310-cp310-win32.whl (66.9 kB view hashes)

Uploaded CPython 3.10 Windows x86

fast_diff_match_patch-2.0.1-cp310-cp310-musllinux_1_1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.0.1-cp310-cp310-musllinux_1_1_i686.whl (1.5 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

fast_diff_match_patch-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (801.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.0.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (785.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (762.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

fast_diff_match_patch-2.0.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (741.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

fast_diff_match_patch-2.0.1-cp310-cp310-macosx_11_0_arm64.whl (66.1 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

fast_diff_match_patch-2.0.1-cp310-cp310-macosx_10_9_x86_64.whl (72.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

fast_diff_match_patch-2.0.1-cp310-cp310-macosx_10_9_universal2.whl (130.2 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

fast_diff_match_patch-2.0.1-cp39-cp39-win_amd64.whl (75.0 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

fast_diff_match_patch-2.0.1-cp39-cp39-win32.whl (66.9 kB view hashes)

Uploaded CPython 3.9 Windows x86

fast_diff_match_patch-2.0.1-cp39-cp39-musllinux_1_1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.0.1-cp39-cp39-musllinux_1_1_i686.whl (1.5 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

fast_diff_match_patch-2.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (801.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.0.1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (785.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (762.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

fast_diff_match_patch-2.0.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (741.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

fast_diff_match_patch-2.0.1-cp39-cp39-macosx_11_0_arm64.whl (66.1 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

fast_diff_match_patch-2.0.1-cp39-cp39-macosx_10_9_x86_64.whl (72.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

fast_diff_match_patch-2.0.1-cp39-cp39-macosx_10_9_universal2.whl (130.2 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

fast_diff_match_patch-2.0.1-cp38-cp38-win_amd64.whl (75.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

fast_diff_match_patch-2.0.1-cp38-cp38-win32.whl (66.9 kB view hashes)

Uploaded CPython 3.8 Windows x86

fast_diff_match_patch-2.0.1-cp38-cp38-musllinux_1_1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.0.1-cp38-cp38-musllinux_1_1_i686.whl (1.5 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

fast_diff_match_patch-2.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (801.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.0.1-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (785.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (762.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

fast_diff_match_patch-2.0.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (741.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

fast_diff_match_patch-2.0.1-cp38-cp38-macosx_11_0_arm64.whl (66.0 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

fast_diff_match_patch-2.0.1-cp38-cp38-macosx_10_9_x86_64.whl (72.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

fast_diff_match_patch-2.0.1-cp38-cp38-macosx_10_9_universal2.whl (130.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

fast_diff_match_patch-2.0.1-cp37-cp37m-win_amd64.whl (74.9 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

fast_diff_match_patch-2.0.1-cp37-cp37m-win32.whl (66.9 kB view hashes)

Uploaded CPython 3.7m Windows x86

fast_diff_match_patch-2.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.0.1-cp37-cp37m-musllinux_1_1_i686.whl (1.5 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

fast_diff_match_patch-2.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (802.3 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.0.1-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (786.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (763.3 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

fast_diff_match_patch-2.0.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (740.7 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

fast_diff_match_patch-2.0.1-cp37-cp37m-macosx_10_9_x86_64.whl (72.0 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

fast_diff_match_patch-2.0.1-cp36-cp36m-win_amd64.whl (75.0 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

fast_diff_match_patch-2.0.1-cp36-cp36m-win32.whl (66.9 kB view hashes)

Uploaded CPython 3.6m Windows x86

fast_diff_match_patch-2.0.1-cp36-cp36m-musllinux_1_1_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

fast_diff_match_patch-2.0.1-cp36-cp36m-musllinux_1_1_i686.whl (1.5 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ i686

fast_diff_match_patch-2.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (801.4 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

fast_diff_match_patch-2.0.1-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (784.9 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686

fast_diff_match_patch-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (762.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

fast_diff_match_patch-2.0.1-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (739.9 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

fast_diff_match_patch-2.0.1-cp36-cp36m-macosx_10_9_x86_64.whl (72.0 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page