{"id":1485,"library":"ftfy","title":"ftfy (Fixes Text For You)","description":"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.","status":"active","version":"6.3.1","language":"en","source_language":"en","source_url":"https://github.com/rspeer/python-ftfy","tags":["unicode","encoding","mojibake","text-processing","data-cleaning"],"install":[{"cmd":"pip install ftfy","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"fix_text","correct":"from ftfy import fix_text"},{"note":"The `fix_encoding_and_explain` function was removed in 6.0.x; use `fix_and_explain` instead.","wrong":"from ftfy.fixes import fix_encoding_and_explain","symbol":"fix_and_explain","correct":"from ftfy import fix_and_explain"}],"quickstart":{"code":"import ftfy\n\n# Basic text fixing\ntext = \"The quick brown fox jumped over the lazy dogs.â€”David\"\nfixed_text = ftfy.fix_text(text)\nprint(f\"Original: {text}\")\nprint(f\"Fixed:    {fixed_text}\")\n# Expected: The quick brown fox jumped over the lazy dogs.—David\n\n# Fixing with explanation (useful for debugging)\ntext_with_mojibake = \"It was the best of times, it was the worst of times.â\\x80\\x94Charles Dickens\"\nfixed, explanation = ftfy.fix_and_explain(text_with_mojibake)\nprint(f\"\\nOriginal: {text_with_mojibake}\")\nprint(f\"Fixed:    {fixed}\")\nprint(f\"Explanation: {explanation}\")\n# Expected fixed: It was the best of times, it was the worst of times.—Charles Dickens","lang":"python","description":"Demonstrates fixing a simple mojibake string and using `fix_and_explain` to understand the transformations applied."},"warnings":[{"fix":"Thoroughly test ftfy's behavior on your specific data after upgrading. For detailed insights into changes, use `ftfy.fix_and_explain()`.","message":"ftfy 6.0.x introduced a completely rewritten heuristic for detecting and fixing mojibake. While generally an improvement, it might behave differently for certain edge cases compared to 5.x. Users migrating from 5.x should review output carefully.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Update your code to `from ftfy import fix_and_explain` and use the new top-level function.","message":"The function `ftfy.fixes.fix_encoding_and_explain` was deprecated and subsequently removed in ftfy 6.0.x. Its functionality, along with broader fixing capabilities, is now integrated into the top-level `ftfy.fix_and_explain`.","severity":"deprecated","affected_versions":"<6.0.0"},{"fix":"Ensure your Python environment is 3.9 or higher. If you need to use an older Python version, you must pin ftfy to a 5.x version (e.g., `ftfy<6`).","message":"ftfy 6.x requires Python 3.9 or newer. Older versions (e.g., 5.x) supported older Python versions (e.g., Python 2.7, 3.4+).","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Only use ftfy when you suspect genuine text corruption. Understand its scope as a mojibake and encoding repair tool rather than a general-purpose text cleaner.","message":"ftfy is designed to *fix* corrupted text, not to perform general text normalization, re-encode correctly decoded text, or handle natural language processing tasks. Applying it to already clean or correctly encoded text may not yield desired results or could introduce unintended changes, although it tries to be conservative.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}