Skip to main content

Default template for PDM package

Project description

editdistance

Fast implementation of the edit distance (Levenshtein distance).

This library simply implements Levenshtein distance with C++ and Cython.

The algorithm used in this library is proposed by Heikki Hyyrö, "Explaining and extending the bit-parallel approximate string matching algorithm of Myers", (2001)

Binary wheels

Thanks to pypa/cibuildwheel There are binary wheels on Linux, Mac OS, and Windows.

Install

You can install via pip:

pip install editdistance

Usage

It's quite simple:

import editdistance
editdistance.eval('banana', 'bahama')
# 2L

Simple Benchmark

With IPython, I tried several libraries:

On Python 2.7.5:

a = 'fsffvfdsbbdfvvdavavavavavava'
b = 'fvdaabavvvvvadvdvavavadfsfsdafvvav'
import pylev
timeit pylev.levenshtein(a, b)
# 100 loops, best of 3: 7.48 ms per loop

from pyxdameraulevenshtein import damerau_levenshtein_distance
timeit damerau_levenshtein_distance(a, b)
# 100000 loops, best of 3: 11.4 µs per loop

timeit editdistance.eval(a, b)  # my library
# 100000 loops, best of 3: 3.5 µs per loop

import Levenshtein

timeit Levenshtein.distance(a, b)
# 100000 loops, best of 3: 3.21 µs per loop

Distance with Any Object

Above libraries only support strings. But Sometimes other type of objects such as list of strings(words). I support any iterable, only requires hashable object of it:

Levenshtein.distance(['spam', 'egg'], ['spam', 'ham'])
# ---------------------------------------------------------------------------
# TypeError                                 Traceback (most recent call last)
# <ipython-input-22-3e0b30d145ac> in <module>()
# ----> 1 Levenshtein.distance(['spam', 'egg'], ['spam', 'ham'])
#
# TypeError: distance expected two Strings or two Unicodes

editdistance.eval(['spam', 'egg'], ['spam', 'ham'])
# 1L

So if object's hash is same, it's same. You can provide __hash__ method to your object instances.

Enjoy!

License

It is released under the MIT license.

Copyright (c) 2013 Hiroyuki Tanaka

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

editdistance-0.8.0.tar.gz (49.9 kB view hashes)

Uploaded Source

Built Distributions

editdistance-0.8.0-pp310-pypy310_pp73-win_amd64.whl (77.4 kB view hashes)

Uploaded PyPy Windows x86-64

editdistance-0.8.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (84.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

editdistance-0.8.0-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (84.6 kB view hashes)

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

editdistance-0.8.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (89.0 kB view hashes)

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

editdistance-0.8.0-pp310-pypy310_pp73-macosx_10_9_x86_64.whl (76.4 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

editdistance-0.8.0-pp39-pypy39_pp73-win_amd64.whl (77.4 kB view hashes)

Uploaded PyPy Windows x86-64

editdistance-0.8.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (84.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

editdistance-0.8.0-pp39-pypy39_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (84.6 kB view hashes)

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

editdistance-0.8.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (89.0 kB view hashes)

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

editdistance-0.8.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (76.4 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

editdistance-0.8.0-pp38-pypy38_pp73-win_amd64.whl (76.9 kB view hashes)

Uploaded PyPy Windows x86-64

editdistance-0.8.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (83.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

editdistance-0.8.0-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (83.8 kB view hashes)

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

editdistance-0.8.0-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (88.0 kB view hashes)

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

editdistance-0.8.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (75.7 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

editdistance-0.8.0-cp312-cp312-win_amd64.whl (79.8 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

editdistance-0.8.0-cp312-cp312-win32.whl (81.0 kB view hashes)

Uploaded CPython 3.12 Windows x86

editdistance-0.8.0-cp312-cp312-musllinux_1_1_x86_64.whl (929.1 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

editdistance-0.8.0-cp312-cp312-musllinux_1_1_i686.whl (975.6 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

editdistance-0.8.0-cp312-cp312-musllinux_1_1_aarch64.whl (917.3 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ ARM64

editdistance-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (418.9 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

editdistance-0.8.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (415.2 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

editdistance-0.8.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (412.5 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

editdistance-0.8.0-cp312-cp312-macosx_11_0_arm64.whl (79.2 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

editdistance-0.8.0-cp312-cp312-macosx_10_9_x86_64.whl (81.0 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

editdistance-0.8.0-cp312-cp312-macosx_10_9_universal2.whl (106.7 kB view hashes)

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

editdistance-0.8.0-cp311-cp311-win_amd64.whl (79.7 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

editdistance-0.8.0-cp311-cp311-win32.whl (80.8 kB view hashes)

Uploaded CPython 3.11 Windows x86

editdistance-0.8.0-cp311-cp311-musllinux_1_1_x86_64.whl (922.1 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

editdistance-0.8.0-cp311-cp311-musllinux_1_1_i686.whl (969.4 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

editdistance-0.8.0-cp311-cp311-musllinux_1_1_aarch64.whl (909.2 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ ARM64

editdistance-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (412.9 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

editdistance-0.8.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (409.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

editdistance-0.8.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (407.4 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

editdistance-0.8.0-cp311-cp311-macosx_11_0_arm64.whl (79.1 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

editdistance-0.8.0-cp311-cp311-macosx_10_9_x86_64.whl (80.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

editdistance-0.8.0-cp311-cp311-macosx_10_9_universal2.whl (106.0 kB view hashes)

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

editdistance-0.8.0-cp310-cp310-win_amd64.whl (79.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

editdistance-0.8.0-cp310-cp310-win32.whl (80.8 kB view hashes)

Uploaded CPython 3.10 Windows x86

editdistance-0.8.0-cp310-cp310-musllinux_1_1_x86_64.whl (911.0 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

editdistance-0.8.0-cp310-cp310-musllinux_1_1_i686.whl (959.6 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

editdistance-0.8.0-cp310-cp310-musllinux_1_1_aarch64.whl (898.9 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

editdistance-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (401.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

editdistance-0.8.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (396.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

editdistance-0.8.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (397.5 kB view hashes)

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

editdistance-0.8.0-cp310-cp310-macosx_11_0_arm64.whl (79.1 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

editdistance-0.8.0-cp310-cp310-macosx_10_9_x86_64.whl (80.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

editdistance-0.8.0-cp310-cp310-macosx_10_9_universal2.whl (106.1 kB view hashes)

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

editdistance-0.8.0-cp39-cp39-win_amd64.whl (79.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

editdistance-0.8.0-cp39-cp39-win32.whl (80.8 kB view hashes)

Uploaded CPython 3.9 Windows x86

editdistance-0.8.0-cp39-cp39-musllinux_1_1_x86_64.whl (910.7 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

editdistance-0.8.0-cp39-cp39-musllinux_1_1_i686.whl (959.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

editdistance-0.8.0-cp39-cp39-musllinux_1_1_aarch64.whl (898.6 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

editdistance-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (401.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

editdistance-0.8.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (396.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

editdistance-0.8.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (397.3 kB view hashes)

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

editdistance-0.8.0-cp39-cp39-macosx_11_0_arm64.whl (79.1 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

editdistance-0.8.0-cp39-cp39-macosx_10_9_x86_64.whl (80.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

editdistance-0.8.0-cp39-cp39-macosx_10_9_universal2.whl (106.1 kB view hashes)

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

editdistance-0.8.0-cp38-cp38-win_amd64.whl (79.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

editdistance-0.8.0-cp38-cp38-win32.whl (80.8 kB view hashes)

Uploaded CPython 3.8 Windows x86

editdistance-0.8.0-cp38-cp38-musllinux_1_1_x86_64.whl (911.5 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

editdistance-0.8.0-cp38-cp38-musllinux_1_1_i686.whl (960.4 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

editdistance-0.8.0-cp38-cp38-musllinux_1_1_aarch64.whl (899.3 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

editdistance-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (402.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

editdistance-0.8.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (397.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

editdistance-0.8.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (397.8 kB view hashes)

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

editdistance-0.8.0-cp38-cp38-macosx_11_0_arm64.whl (79.1 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

editdistance-0.8.0-cp38-cp38-macosx_10_9_x86_64.whl (80.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

editdistance-0.8.0-cp38-cp38-macosx_10_9_universal2.whl (106.1 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, 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