---
title: "Quickstart"
description: "Run representative distance, similarity, alignment and compression measures with strsimpy."
---

> 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.

# Quickstart

The quickest way to see the library in action is one small script. Every class used here is available from the package root.

## Run the examples

Create a file named `example.py`:

```python
from strsimpy import (
    Jaccard,
    JaroWinkler,
    Levenshtein,
    NeedlemanWunsch,
    NormalizedCompressionDistance,
)

print(Levenshtein().distance("kitten", "sitting"))
print(JaroWinkler().similarity("MARTHA", "MARHTA"))
print(Jaccard(2).similarity("night", "nacht"))
print(NeedlemanWunsch().score("GATTACA", "GCATGCU"))
print(NormalizedCompressionDistance().distance("aaaa", "aaab"))
```

Run it with:

```bash
python example.py
```

On strsimpy 0.5.0 the output is exactly:

```text
3
0.9611111111111111
0.14285714285714285
0.0
0.3333333333333333
```

## What each result means

| Measure | Result | Interpretation |
| --- | --- | --- |
| `Levenshtein().distance` | `3` | Three single-character edits transform `"kitten"` into `"sitting"`. The result is an `int` here. |
| `JaroWinkler().similarity` | `0.9611111111111111` | A normalized similarity, where `1.0` means identical. |
| `Jaccard(2).similarity` | `0.14285714285714285` | Similarity between the sets of character bigrams, where `1.0` means identical sets. |
| `NeedlemanWunsch().score` | `0.0` | A raw global alignment score, not a distance. It can be zero or negative. |
| `NormalizedCompressionDistance().distance` | `0.3333333333333333` | A compression-based distance with the RLE compressor. Lower values are more similar. |

> **Equal strings return the float 0.0**
>
> `Levenshtein` and a few other integer-valued distances return a Python `int` for unequal inputs, but the float `0.0` when both strings are identical. This preserves the historical behavior of the pure-Python releases:
>
> ```python
> Levenshtein().distance("kitten", "sitting")  # 3, an int
> Levenshtein().distance("abc", "abc")         # 0.0, a float
> ```
>
> The same pattern applies to `Damerau`, `OptimalStringAlignment`, `LongestCommonSubsequence` and `QGram`.

## Similarity, distance or score?

| Method | Meaning | Typical range | Classes |
| --- | --- | --- | --- |
| `similarity()` | Higher is more similar; `1.0` usually means identical. | Usually `0.0` to `1.0` | `JaroWinkler`, `Jaccard`, `Cosine` |
| `distance()` | Lower is more similar; `0.0` usually means identical. | Depends on the measure | `Levenshtein`, `NormalizedCompressionDistance` |
| `score()` | Raw alignment score under the configured match, mismatch and gap parameters. | Any finite value; Smith-Waterman is non-negative | `NeedlemanWunsch`, `SmithWaterman`, `Gotoh` |

The sequence-alignment classes deliberately expose scores rather than distances. Use `alignment()` on those classes, or on `OptimalStringAlignment`, when you need the edit operations behind a result.

> **Identical inputs are not always distance 0.0**
>
> Normalized compression distance depends on the compressor. With the RLE compressor, `'abc'` versus `'abc'` scores `1.0`, while `'aaa'` versus `'aaa'` scores `0.0`. Do not assume `distance(x, x) == 0` for this measure.

## Where to go next

- Read the [algorithms](https://luozhouyang.github.io/python-string-similarity/algorithms/) section for the definition, range and caveats of each measure.
- Browse the [API reference](https://luozhouyang.github.io/python-string-similarity/reference/api/) for constructors and method signatures.
- Use the [Rust core](https://luozhouyang.github.io/python-string-similarity/getting-started/rust/) directly if you need the algorithms outside Python.

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