ftfy (Fixes Text For You)

6.3.1 · active · verified Thu Apr 09

ftfy (Fixes Text For You) is a Python library designed to clean up Unicode text that has gone wrong, often due to mojibake, encoding mismatches, or badly-decoded HTML. It intelligently detects and corrects common text issues after the fact, making your data more readable and usable. The current version is 6.3.1, and releases are somewhat irregular but actively maintained.

Warnings

Install

Imports

Quickstart

Demonstrates fixing a simple mojibake string and using `fix_and_explain` to understand the transformations applied.

import ftfy

# Basic text fixing
text = "The quick brown fox jumped over the lazy dogs.—David"
fixed_text = ftfy.fix_text(text)
print(f"Original: {text}")
print(f"Fixed:    {fixed_text}")
# Expected: The quick brown fox jumped over the lazy dogs.—David

# Fixing with explanation (useful for debugging)
text_with_mojibake = "It was the best of times, it was the worst of times.â\x80\x94Charles Dickens"
fixed, explanation = ftfy.fix_and_explain(text_with_mojibake)
print(f"\nOriginal: {text_with_mojibake}")
print(f"Fixed:    {fixed}")
print(f"Explanation: {explanation}")
# Expected fixed: It was the best of times, it was the worst of times.—Charles Dickens

view raw JSON →