Levenshtein

A fast Python C extension for Levenshtein edit distance, string similarity, and edit operations.

Library
PyPI
v0.27.4
398stars
GNU GPLv2

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
70/100Good
Development Activity68
Maintenance72
Community56
Maturity56
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture82
Code Quality84
Innovation72
Learning Curve85

Levenshtein is a Python C extension module that provides fast computation of Levenshtein (edit) distance and related string metrics. Beyond raw edit distance, it returns the underlying edit operations, computes normalized string similarity, and can derive approximate median strings and set/sequence similarity, making it a compact toolkit for fuzzy string work.

Maintained by the rapidfuzz project, the current versions are implemented on top of the high-performance rapidfuzz-cpp backend, giving native-speed results while keeping a simple Python API. It is a common building block for spell checking, deduplication, record linkage, and any workflow that needs to measure how similar two strings are.

What You Get

  • distance() for Levenshtein (edit) distance between two strings
  • ratio() and related functions for normalized string similarity
  • Edit-operation APIs (editops, opcodes) describing how to transform one string into another
  • Approximate median-string and general string-averaging helpers
  • Sequence and set similarity functions, all backed by a compiled extension

Common Use Cases

  • Fuzzy matching and deduplication of names, addresses, or records
  • Spell checking and autocorrect ranking by edit distance
  • Computing similarity scores for search, clustering, or record linkage
  • Deriving a representative median string from a set of noisy inputs

Under The Hood

Architecture - The Python-facing package lives in src/Levenshtein/, with __init__.py/__init__.pyi defining the public API and type stubs, a Cython layer (levenshtein_cpp.pyx) bridging to the C++ core in Levenshtein-c/_levenshtein.cpp, and a legacy StringMatcher.py compatibility shim. The vendored extern/ tree and CMakeLists.txt wire in the rapidfuzz-cpp backend that performs the actual distance and similarity computation.

Tech Stack - The distribution is a compiled extension: C++ core plus Cython glue, built via CMake (scikit-build style) as configured in pyproject.toml and CMakeLists.txt, targeting Python 3.10+. It depends on rapidfuzz’s C++ library for its algorithms and ships py.typed plus .pyi stubs for static typing.

Code Quality - The project is actively maintained under the rapidfuzz organization with a tests/ suite, CI via GitHub Actions, published documentation, a HISTORY changelog, and a SECURITY policy. Delegating algorithms to the shared rapidfuzz-cpp backend keeps the surface small and consistent.

API Design - The API is flat and predictable: standalone functions like distance, ratio, editops, and median take strings and return numbers or operation lists, with no objects to instantiate. This makes it easy to adopt as a drop-in for the classic python-Levenshtein package while gaining modern performance.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search