textdistance
Compute distance between the two texts.
What it is and what it does
TextDistance is a pure-Python library that implements a large collection of algorithms for measuring how different two or more text sequences are from each other. It provides both distance metrics (how far apart sequences are) and similarity metrics (how alike they are), with support for edit-based algorithms like Levenshtein and Damerau-Levenshtein, token-based methods like Jaccard and Cosine similarity, sequence-based approaches like longest common subsequence, compression-based distance, and phonetic matching. The library has zero runtime dependencies by default and offers optional numpy integration for speed on specific algorithms.
You use it by instantiating an algorithm class or calling a function directly, then invoking methods like `.distance()`, `.similarity()`, or `.normalized_distance()` to compare sequences. It's designed for straightforward use cases where you need to measure text similarity—fuzzy matching, deduplication, spell-checking support, or record linkage—without needing to implement these algorithms yourself.
Use it for:
- Fuzzy string matching to find similar product names or user entries despite typos or variations
- Deduplication of text records by computing similarity scores between candidates
- Spell-checking or autocorrect by ranking candidate corrections by edit distance
- Record linkage in data integration by comparing field values across datasets
- Phonetic matching for names that sound similar but are spelled differently
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Computes distance and similarity between text sequences using 30+ algorithms including Levenshtein, Jaro-Winkler, Hamming, and compression-based methods.
Yes. The package is stable, permissively licensed, has no dependencies, and provides a comprehensive toolkit for a common task. The aging maintenance status (last release 759 days ago) is a minor concern but not a blocker—the library solves a well-defined problem with established algorithms, and the repository remains active and not archived. Install it if you need string distance or similarity computation.
Install
textdistance on PyPI
pip
pip install textdistanceuv
uv add textdistancepoetry
poetry add textdistanceInstalling textdistance
Before you install
Low friction installation with no runtime dependencies. Maintenance status is aging—last release was 2024-07-16, with 759 days since then—but the package remains in production/stable state with an active repository (3538 stars, not archived).
License in practice
MIT license (permissive) means you can use this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install textdistance
from textdistance import Levenshtein
levenshtein = Levenshtein()
distance = levenshtein.distance('kitten', 'sitting')
print(distance) # 3
Verify before relying
- Whether optional numpy integration actually improves performance for the algorithms listed, and which ones benefit most
- Current state of the 'work in progress' compression-based algorithms (BZ2NCD, LZMANCD, ZLIBNCD) and whether they are production-ready
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 759 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,580,088/month — #2,991 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: textdistance-4.6.3-py3-none-any.whl
Keywords: distance, between, text, strings, sequences, iterators
Tags
More Human Machine Interfaces packages
NLTK is a Python library for natural language…
permissive · top 1,000 on PyPI
humanfriendlyFormats and parses numbers, file sizes,…
permissive · top 1,000 on PyPI
coloredlogsAdds colored output to Python's standard…
permissive · top 1,000 on PyPI
word2numberConverts written-out number words (like "twenty…
permissive · top 5,000 on PyPI
webrtcvad-wheelsDetects voiced versus unvoiced segments in…
permissive · top 15,000 on PyPI
webrtcvadProvides a Python interface to Google's WebRTC…
permissive · top 15,000 on PyPI
DistanceComputes distance metrics (Levenshtein,…
copyleft · top 15,000 on PyPI
strsimpyImplements a dozen string similarity and…
permissive · top 15,000 on PyPI
fuzzysearchFinds approximate substring matches in text or…
permissive · top 15,000 on PyPI
editdistanceComputes the edit distance (Levenshtein…
permissive · top 5,000 on PyPI
pylevComputes the Levenshtein distance between two…
permissive · top 5,000 on PyPI
jaro-winklerComputes Jaro and Jaro-Winkler string…
copyleft · top 5,000 on PyPI
pyjarowinklerComputes Jaro and Jaro-Winkler similarity and…
permissive · top 15,000 on PyPI
aptedComputes the tree edit distance between two…
permissive · top 15,000 on PyPI
jarowinklerCalculates Jaro and Jaro-Winkler string…
permissive · top 15,000 on PyPI
zssComputes the edit distance between two tree…
unclear · top 15,000 on PyPI