TextDistance: A Comprehensive Python Library for Sequence Distance Calculation

This repository profile is provided by osrepos.com, an open source repository discovery platform.

TextDistance: A Comprehensive Python Library for Sequence Distance Calculation

Summary

TextDistance is a powerful Python library designed to compute the distance and similarity between sequences using over 30 different algorithms. It offers a pure Python implementation with a common, easy-to-use interface, and can optionally leverage external libraries for maximum performance. This tool is ideal for tasks requiring robust string comparison, such as fuzzy matching and data cleaning.

Repository Information

Analyzed by OSRepos on October 31, 2025

Use at your own risk

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.

Introduction

TextDistance is a comprehensive and versatile Python library designed for computing the distance and similarity between sequences. It stands out by offering implementations of over 30 different algorithms, all accessible through a common and intuitive interface. Whether you need to compare strings, lists, or any other sequence, TextDistance provides a robust solution.

Key features include:

  • Extensive Algorithm Collection: Over 30 algorithms covering edit-based, token-based, sequence-based, compression-based, phonetic, and simple comparisons.
  • Pure Python Implementation: Ensures compatibility and ease of use across various environments.
  • Common Interface: All algorithms share a consistent API for calculating distance, similarity, normalized distance, and normalized similarity.
  • Optional External Libraries: For maximum speed, TextDistance can leverage highly optimized external C-based libraries like jellyfish and Levenshtein if installed.
  • Multi-sequence Comparison: Supports comparing more than two sequences simultaneously.

Installation

Installing TextDistance is straightforward. You can choose between a pure Python version or include optional extra libraries for enhanced performance.

Stable Version (Pure Python):

pip install textdistance

Stable Version (With Extra Libraries for Maximum Speed):

pip install "textdistance[extras]"

Development Version:

You can install the development version directly from GitHub:

pip install -e git+https://github.com/life4/textdistance.git#egg=textdistance

Alternatively, clone the repository and install with benchmark extras:

git clone https://github.com/life4/textdistance.git
pip install -e ".[benchmark]"

Examples

TextDistance provides a simple and consistent interface across all its algorithms. Here's an example using the Hamming distance:

import textdistance

# Calculate Hamming distance
print(textdistance.hamming('test', 'text'))
# Output: 1

# Using the explicit distance method
print(textdistance.hamming.distance('test', 'text'))
# Output: 1

# Calculate similarity
print(textdistance.hamming.similarity('test', 'text'))
# Output: 3

# Calculate normalized distance (0 to 1, 0 means equal)
print(textdistance.hamming.normalized_distance('test', 'text'))
# Output: 0.25

# Calculate normalized similarity (0 to 1, 1 means equal)
print(textdistance.hamming.normalized_similarity('test', 'text'))
# Output: 0.75

# Using q-grams for comparison (e.g., qval=2 for bigrams)
print(textdistance.Hamming(qval=2).distance('test', 'text'))
# Output: 2

This consistent API makes it easy to experiment with different algorithms and find the best fit for your specific use case.

Why Use TextDistance?

TextDistance offers compelling reasons for developers and data scientists:

  • Unmatched Versatility: With over 30 algorithms, it covers almost every scenario for sequence comparison, from simple character differences to complex phonetic matching. This breadth makes it a go-to tool for diverse applications.
  • Optimized Performance: While providing a pure Python fallback, TextDistance intelligently integrates with faster, C-optimized external libraries when available. Benchmarks clearly demonstrate significant speed improvements, making it suitable for performance-critical applications.
  • Simplified Development: The unified API across all algorithms drastically reduces the learning curve and development time. You can switch between algorithms with minimal code changes.
  • Robustness for Data Tasks: It's an invaluable asset for data cleaning, deduplication, fuzzy matching, natural language processing, and bioinformatics, where accurate and efficient sequence comparison is crucial.
  • Active Development and Community: The project is actively maintained, welcoming contributions and ensuring its continued evolution.

Links

Related repositories

Similar repositories that may be relevant next.

OpenSandbox: A Secure and Extensible Sandbox Runtime for AI Agents

OpenSandbox: A Secure and Extensible Sandbox Runtime for AI Agents

August 12, 2026

OpenSandbox is a powerful, general-purpose sandbox platform designed for AI applications. It provides secure, fast, and extensible runtime environments, supporting multi-language SDKs and Docker/Kubernetes deployments. This project is ideal for developing and evaluating AI agents in isolated, controlled settings.

aiai-agentai-infra
FastMCP: The Pythonic Framework for Model Context Protocol Applications

FastMCP: The Pythonic Framework for Model Context Protocol Applications

August 11, 2026

FastMCP is a robust, Pythonic framework developed by PrefectHQ, designed to simplify the creation of Model Context Protocol (MCP) servers and clients. It provides a comprehensive application framework for connecting Large Language Models (LLMs) to tools and data, handling complexities like schema generation, validation, and protocol lifecycle. As the standard framework for MCP, FastMCP empowers developers to build powerful LLM-integrated applications efficiently.

fastmcpmcpmodel-context-protocol
nanobot: An Ultra-Lightweight, Self-Hosted Personal AI Agent Framework

nanobot: An Ultra-Lightweight, Self-Hosted Personal AI Agent Framework

August 9, 2026

nanobot is an ultra-lightweight, open-source, self-hosted personal AI agent framework built in Python. It offers a WebUI, tools, memory, multi-agent workflows, and automation capabilities, making it a versatile solution for personal AI tasks. Users can deploy it across various platforms, including chat apps, for seamless integration.

ai-agentagent-frameworkpython
ReMe: An Advanced Memory Management Kit for AI Agents

ReMe: An Advanced Memory Management Kit for AI Agents

August 7, 2026

ReMe is an innovative, local-first memory layer designed for AI agents, transforming conversations and resources into file-based long-term memory. It continuously indexes, links, and consolidates this information, enabling advanced recall and supporting the development of self-evolving agents. This kit helps agents remember and refine their experiences effectively.

agentai-agentsmemory

Source repository

Open the original repository on GitHub.

8 counted GitHub visits

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️