---
title: "python-string-similarity"
description: "Rust-backed string similarity and distance measures for Python, with a pure Rust core and a stable PyO3 API."
---

> Documentation Index
> Fetch the complete documentation index at: https://luozhouyang.github.io/python-string-similarity/llms.txt
> Use this file to discover all available pages before exploring further.

# python-string-similarity

`python-string-similarity` is a collection of string similarity and distance measures for Python. The algorithms are implemented in Rust and exposed through [PyO3](https://pyo3.rs/), so comparisons are fast while the public Python API remains compatible with the original pure-Python releases.

## Install

```bash
pip install -U strsimpy
```

Supported on Python 3.10-3.13. Prebuilt abi3 wheels cover Linux, macOS and Windows; see [Installation](https://luozhouyang.github.io/python-string-similarity/getting-started/installation/) for platforms and source-build requirements.

## A first comparison

```python
from strsimpy import JaroWinkler, Levenshtein

Levenshtein().distance("kitten", "sitting")      # 3
JaroWinkler().similarity("MARTHA", "MARHTA")     # 0.9611111111111111
```

Every public class can be imported from the package root. The historical per-module imports, such as `from strsimpy.levenshtein import Levenshtein`, keep working too.

## Feature families

| Family | Measures | What it gives you |
| --- | --- | --- |
| Edit distance | `Levenshtein`, `WeightedLevenshtein`, `Damerau`, `OptimalStringAlignment`, `LongestCommonSubsequence`, `MetricLCS` | Character-level edit costs and their normalized variants |
| Normalized similarity | `NormalizedLevenshtein`, `JaroWinkler`, `MLIPNS`, `RatcliffObershelp`, plus the Strcmp95 routine | Scores in the range `0.0` to `1.0` for ranking candidates |
| Shingle and token metrics | `NGram`, `QGram`, `Cosine`, `Jaccard`, `SorensenDice`, `OverlapCoefficient`, `Tversky`, `Tanimoto`, `Bag`, `MongeElkan` | Set, profile and token comparisons for words and documents |
| Sequence alignment | `NeedlemanWunsch`, `SmithWaterman`, `Gotoh` | Raw alignment scores and optional alignment paths |
| Compression | `NormalizedCompressionDistance` | Compression-based distance with a run-length encoder |
| Experimental | `SIFT4` | Human-oriented edit distance with optional tokenizers |

## Why the Rust core?

- **Fast by default.** The hot loops run in compiled Rust, including rolling-row edit distances and shingle profiles.
- **Easy to deploy.** A single abi3 extension module ships in prebuilt wheels for CPython 3.10 and newer.
- **Familiar API.** Class names, constructor options, module paths and method names from the pure-Python package are preserved.
- **Unicode aware.** Algorithms operate on Unicode scalar values, matching Python's `len(str)` and indexing semantics.

> **Semantics can differ from other libraries**
>
> Some measures use deliberate definitions that differ from popular packages. For example, Tanimoto is the standard set-based measure, Tversky uses shingle sets, and the alignment classes return scores rather than distances. Each algorithm page documents these choices, and the [compatibility guide](https://luozhouyang.github.io/python-string-similarity/guides/compatibility/) collects the main divergences.

## Explore the docs

- [**Quickstart**](https://luozhouyang.github.io/python-string-similarity/getting-started/quickstart/) — Run representative distance, similarity, alignment and compression measures in a few lines of Python.
- [**Algorithms**](https://luozhouyang.github.io/python-string-similarity/algorithms/) — Understand how each measure works, what its values mean, and when to choose it.
- [**API reference**](https://luozhouyang.github.io/python-string-similarity/reference/api/) — Look up classes, constructors, methods, return types and caveats.

Source code, issues and release notes live on [GitHub](https://github.com/luozhouyang/python-string-similarity). The project is MIT licensed.

Source: https://luozhouyang.github.io/python-string-similarity/index.mdx
