A Python extension module that wraps Google's diff_match_patch C++ implementation for very fast string comparisons. Version 1.0.2 fixes a build issue on Macs.
Project description
A Python extension module that wraps google-diff-match-patch’s C++ implementation for performing very fast string comparisons.
google-diff-match-patch is a Google library for computing differences between text files (<http://code.google.com/p/google-diff-match-patch>). Thare 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 project is a Python extension module for the C++ STL port so Python code can call into the native library easily. It works in both Python 2 and Python 3.
Example
First:
pip3 install diff_match_patch_python
Then write (this is Python 3):
from diff_match_patch import diff changes = diff("Hello world.", "Goodbye moon.", timelimit=0, checklines=False) 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 module also provides a method called diff_bytes for performing a diff on a bytes array.
In Python 2, the methods are named diff_unicode (unicode strings) and diff_str (str strings).
The timelimit argument is 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.
The diff methods also take a counts_only argument which is True by default. Set it 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.
Building from source
To build from these sources, you will need:
Python development headers (Debian package python-dev)
The diff-match-patch library, which you can clone using git submodule update --init.
Then build the binary module using:
python setup.py install
Or you may find pre-built binaries stored in the git repository in the build directory. Your mileage may vary with these depending on whether your system is compatible.
For package maintainers
To build everything:
git submodule update && rm -rf build && python setup.py build && python3 setup.py build
And to test without installing:
PYTHONPATH=build/lib.linux-x86_64-2.7/ python test.py PYTHONPATH=build/lib.linux-x86_64-3.4/ python3 test.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fast_diff_match-1.0.2.macosx-10.15-x86_64.tar.gz
.
File metadata
- Download URL: fast_diff_match-1.0.2.macosx-10.15-x86_64.tar.gz
- Upload date:
- Size: 49.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17c92c0448b4d81446ed94e870b6285eec1461c4968bb6a6e31501e385cd2c9f |
|
MD5 | 33c0ca83a3f2a0eab9d050d48069ae1d |
|
BLAKE2b-256 | eb44764b2a51d40fb7d49bff49ade1be33519be20bac3e14723a9fef17f94e99 |
Provenance
File details
Details for the file fast_diff_match-1.0.2-cp37-cp37m-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: fast_diff_match-1.0.2-cp37-cp37m-macosx_10_15_x86_64.whl
- Upload date:
- Size: 51.5 kB
- Tags: CPython 3.7m, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e9b1f0c617b676cf5ad74d0b159588081c8ee911f6d48e8354392ea856b4d32 |
|
MD5 | dbf42edf5c79c3b69b0787c2651fc9c9 |
|
BLAKE2b-256 | c5b429b20ecf7dfcb824e3188c30c1162ab37f938c27ac97ecb20868ff04cc02 |