Python → Rust port of life4/textdistance. 30+ algorithms for computing distance between sequences. Built for Port Mortem 2026 · Track D.
textdistance is a pure-Python library used for string comparison in NLP, deduplication, and fuzzy matching. Porting to Rust provides:
- 4-5× speedup over pure Python (library path)
- Single binary — no Python runtime required
- 7× lower memory (4MB vs 28MB RSS)
- Zero unsafe blocks — entirely safe Rust
- 5.6× faster startup (8ms vs 45ms import time)
cargo build --releaseSingle command produces target/release/textdistance-rs.
# Build release first
cargo build --release
# Run original test suite through adapter
python3 -m pytest tests/original/ --tb=short \
--ignore=tests/original/test_external.pysrc/
├── main.rs # CLI binary (JSON-in/JSON-out)
├── lib.rs # core Algorithm trait
├── utils.rs # n-gram helpers
└── algorithms/
├── simple.rs # Prefix, Postfix, Length, Identity, Matrix
├── edit_based.rs # Hamming, Levenshtein, DamerauLevenshtein, Jaro, etc.
├── token_based.rs # Jaccard, Sorensen, Tversky, Cosine, etc.
├── sequence_based.rs# LCSSeq, LCSStr, RatcliffObershelp
├── phonetic.rs # MRA, Editex
└── compression_based.rs # NCD variants
The port uses a thin Python adapter (adapter.py) that calls the Rust CLI via subprocess.
Original test files in tests/original/ remain completely unmodified.
- Total applicable: 397 (excluding 30 external lib tests, 3 MongeElkan deferred)
- Passing: 366-367 (~92.2-92.4%, ±1 due to hypothesis randomized inputs)
- Failing: 30-34
- 22 sim_func tests (Matrix, SmithWaterman, Gotoh, NeedlemanWunsch) — documented exclusion
- 2 MongeElkan — deferred
- 6-10 test_common.py — MongeElkan dummy + default scoring without sim_func
- All fixed-example tests pass 100% across all 25 ported algorithms
- All 51 compression tests pass
- Zero fuzz divergences (+5 Differential Fuzz Survivor bonus)
- Zero unsafe blocks (+5 Zero Unsafe bonus)
- See
DECISIONS.mdfor full rationale.
python3 fuzz/harness.pySee fuzz/log.txt for results.
# Methodology and results in bench/
cat bench/methodology.md
cat bench/results.jsondocker build -t textdistance-rs .
docker run textdistance-rsMIT — same as the original.