Package: fast-diff-match-patch
fast_diff_match_patch: Python package wrapping the C++ implementation of google-diff-match-patchThis 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 athttps://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.)ExampleFirst:pip3 install fast_diff_match_patchThen 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.checklinesis also a
Google thing and might speed up diffs that are over lined-based text
like code.checklines(defaultTrue) 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.Setcounts_only(defaultTrue) toFalseto have the returned value be an array of
tuples of operations and corresponding strings rather than operations
and the lengths of those strings.Ifas_patch(defaultFalse) isTrue, 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. Thefast_diff_match_patch.CHAR_WIDTHfield, 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.0The import has been renamed fromdiff_match_patchtofast_diff_match_patchto avoid an import naming collision withhttps://pypi.org/project/diff-match-patch/and the package name has been updated to match the import name.In previous versions of this package, separatediff_bytes(Py3),diff_unicodeanddiff_str(Py2)
methods were available. They have been merged into a singlediffmethod 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 sourceTo build from these sources, you will need:Python development headers and the setuptools package
(Debian packagespython3-dev,python3-setuptools)The diff-match-patch library, which you can clone usinggit submodule update --init.Then build/install the binary module using:python setup.py build
python setup.py installFor package maintainersTo build everything:git submodule update && rm -rf build && python3 setup.py buildTo test without installing:PYTHONPATH=build/lib.linux-x86_64-3.9/ python3 -m unittestTo upload a new release to PyPi:Install twine:python3 -m pip install --upgrade twinemanylinux 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/*