editdistpy 0.4.0


pip install editdistpy

  Latest version

Released: Jul 12, 2026


Meta
Author: mmb L
Requires Python: >=3.10

Classifiers

Development Status
  • 4 - Beta

Intended Audience
  • Developers
  • Science/Research

Natural Language
  • English

Operating System
  • OS Independent

Programming Language
  • Rust
  • Python
  • Python :: 3
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14
  • Python :: Implementation :: CPython

editdistpy
PyPI version Tests

editdistpy is a fast implementation of the Levenshtein edit distance and the Damerau-Levenshtein optimal string alignment (OSA) edit distance algorithms. The original C# project can be found at SoftWx.Match.

Installation

The easiest way to install editdistpy is using pip:

pip install -U editdistpy

Usage

You can specify the max_distance you care about, if the edit distance exceeds this max_distance, -1 will be returned. Specifying a sensible max distance can result in significant speed improvement.

You can also specify max_distance=sys.maxsize if you wish for the actual edit distance to always be computed.

Levenshtein

import sys

from editdistpy import levenshtein

string_1 = "flintstone"
string_2 = "hanson"

max_distance = 2
print(levenshtein.distance(string_1, string_2, max_distance))
# expected output: -1

max_distance = sys.maxsize
print(levenshtein.distance(string_1, string_2, max_distance))
# expected output: 6

Damerau-Levenshtein OSA

import sys

from editdistpy import damerau_osa

string_1 = "flintstone"
string_2 = "hanson"

max_distance = 2
print(damerau_osa.distance(string_1, string_2, max_distance))
# expected output: -1

max_distance = sys.maxsize
print(damerau_osa.distance(string_1, string_2, max_distance))
# expected output: 6

Benchmark

A simple benchmark was done on Python 3.8.12 against editdistance which implements the Levenshtein edit distance algorithm.

The script used by the benchmark can be found here.

For clarity, the following string pairs were used.

Single word (completely different)

"xabxcdxxefxgx"
"1ab2cd34ef5g6"

Single word (similar)

"example"
"samples"

Single word (identical ending)

"kdeisfnexabxcdxlskdixefxgx"
"xabxcdxlskdixefxgx"

Short string

"short sentence with words"
"shrtsen tence wit mispeledwords"

Long string

"Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod rem"
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium"

single_dif string
        test_damerau_osa               0.3055 usec/pass 611.02 msec total 2000000 iterations
        test_levenshtein               0.3030 usec/pass 606.05 msec total 2000000 iterations
        test_editdistance              0.7036 usec/pass 1407.27 msec total 2000000 iterations
        test_damerau_osa early_cutoff  0.3042 usec/pass 608.37 msec total 2000000 iterations
        test_levenshtein early_cutoff  0.2997 usec/pass 599.44 msec total 2000000 iterations
single_sim string
        test_damerau_osa               0.2379 usec/pass 475.80 msec total 2000000 iterations
        test_levenshtein               0.2434 usec/pass 486.90 msec total 2000000 iterations
        test_editdistance              0.4126 usec/pass 825.17 msec total 2000000 iterations
        test_damerau_osa early_cutoff  0.2234 usec/pass 446.78 msec total 2000000 iterations
        test_levenshtein early_cutoff  0.2372 usec/pass 474.36 msec total 2000000 iterations
single_end string
        test_damerau_osa               0.2933 usec/pass 586.63 msec total 2000000 iterations
        test_levenshtein               0.2538 usec/pass 507.57 msec total 2000000 iterations
        test_editdistance              0.9376 usec/pass 1875.16 msec total 2000000 iterations
        test_damerau_osa early_cutoff  0.2774 usec/pass 554.73 msec total 2000000 iterations
        test_levenshtein early_cutoff  0.2497 usec/pass 499.48 msec total 2000000 iterations
short string
        test_damerau_osa               0.3533 usec/pass 706.55 msec total 2000000 iterations
        test_levenshtein               0.3772 usec/pass 754.42 msec total 2000000 iterations
        test_editdistance              1.1646 usec/pass 2329.30 msec total 2000000 iterations
        test_damerau_osa early_cutoff  0.3515 usec/pass 702.97 msec total 2000000 iterations
        test_levenshtein early_cutoff  0.3798 usec/pass 759.67 msec total 2000000 iterations
long string
        test_damerau_osa               1.3348 usec/pass 2669.56 msec total 2000000 iterations
        test_levenshtein               1.1531 usec/pass 2306.22 msec total 2000000 iterations
        test_editdistance              2.8700 usec/pass 5740.06 msec total 2000000 iterations
        test_damerau_osa early_cutoff  1.3383 usec/pass 2676.50 msec total 2000000 iterations
        test_levenshtein early_cutoff  0.8080 usec/pass 1616.03 msec total 2000000 iterations

While max_distance=10 significantly improves the computation time, it may not be a sensible value in some cases.

editdistpy is also seen to perform better with shorter length strings and can be the more suitable library if your use case mainly deals with comparing short strings.

Changelog

See the changelog for a history of notable changes to edistdistpy.

Wheel compatibility matrix

Platform CPython 3.10 CPython 3.11 CPython 3.12 CPython 3.13 CPython 3.14
macosx_10_12_x86_64
macosx_11_0_arm64
manylinux2014_aarch64
manylinux2014_x86_64
manylinux_2_17_aarch64
manylinux_2_17_x86_64
musllinux_1_1_aarch64
musllinux_1_1_x86_64
win32
win_amd64

Files in release

editdistpy-0.4.0-cp310-cp310-macosx_10_12_x86_64.whl (212.9KiB)
editdistpy-0.4.0-cp310-cp310-macosx_11_0_arm64.whl (211.3KiB)
editdistpy-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (238.8KiB)
editdistpy-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (243.0KiB)
editdistpy-0.4.0-cp310-cp310-musllinux_1_1_aarch64.whl (410.6KiB)
editdistpy-0.4.0-cp310-cp310-musllinux_1_1_x86_64.whl (440.9KiB)
editdistpy-0.4.0-cp310-cp310-win32.whl (107.6KiB)
editdistpy-0.4.0-cp310-cp310-win_amd64.whl (110.9KiB)
editdistpy-0.4.0-cp311-cp311-macosx_10_12_x86_64.whl (212.9KiB)
editdistpy-0.4.0-cp311-cp311-macosx_11_0_arm64.whl (211.2KiB)
editdistpy-0.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (239.3KiB)
editdistpy-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (242.7KiB)
editdistpy-0.4.0-cp311-cp311-musllinux_1_1_aarch64.whl (411.2KiB)
editdistpy-0.4.0-cp311-cp311-musllinux_1_1_x86_64.whl (440.5KiB)
editdistpy-0.4.0-cp311-cp311-win32.whl (107.5KiB)
editdistpy-0.4.0-cp311-cp311-win_amd64.whl (110.8KiB)
editdistpy-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl (212.0KiB)
editdistpy-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (209.7KiB)
editdistpy-0.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (237.7KiB)
editdistpy-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (240.7KiB)
editdistpy-0.4.0-cp312-cp312-musllinux_1_1_aarch64.whl (409.3KiB)
editdistpy-0.4.0-cp312-cp312-musllinux_1_1_x86_64.whl (438.4KiB)
editdistpy-0.4.0-cp312-cp312-win32.whl (106.4KiB)
editdistpy-0.4.0-cp312-cp312-win_amd64.whl (109.3KiB)
editdistpy-0.4.0-cp313-cp313-macosx_10_12_x86_64.whl (212.0KiB)
editdistpy-0.4.0-cp313-cp313-macosx_11_0_arm64.whl (209.7KiB)
editdistpy-0.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (237.8KiB)
editdistpy-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (240.7KiB)
editdistpy-0.4.0-cp313-cp313-musllinux_1_1_aarch64.whl (409.6KiB)
editdistpy-0.4.0-cp313-cp313-musllinux_1_1_x86_64.whl (438.8KiB)
editdistpy-0.4.0-cp313-cp313-win32.whl (106.4KiB)
editdistpy-0.4.0-cp313-cp313-win_amd64.whl (109.4KiB)
editdistpy-0.4.0-cp314-cp314-macosx_10_12_x86_64.whl (212.2KiB)
editdistpy-0.4.0-cp314-cp314-macosx_11_0_arm64.whl (209.7KiB)
editdistpy-0.4.0-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (237.5KiB)
editdistpy-0.4.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (240.7KiB)
editdistpy-0.4.0-cp314-cp314-musllinux_1_1_aarch64.whl (409.2KiB)
editdistpy-0.4.0-cp314-cp314-musllinux_1_1_x86_64.whl (438.8KiB)
editdistpy-0.4.0-cp314-cp314-win32.whl (106.5KiB)
editdistpy-0.4.0-cp314-cp314-win_amd64.whl (109.3KiB)
editdistpy-0.4.0.tar.gz (39.4KiB)
No dependencies