Fast Levenshtein and Damerau optimal string alignment algorithms.
Actively maintained. Last release 4 weeks ago, commits in 14 of the last 26 weeks. A safe choice.
pip install editdistpyeditdistpy

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"