{"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":"python","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,"search_vec":"'6.3.1':58 'activ':65 'bad':33 'badly-decod':32 'clean':17,75 'common':41 'correct':40 'current':55 'data':49,74 'data-clean':73 'decod':34 'design':15 'detect':38 'due':26 'encod':29,68 'fact':46 'fix':2,7 'ftfi':1,6 'gone':23 'html':35 'intellig':37 'irregular':63 'issu':43 'librari':14 'maintain':66 'make':47 'mismatch':30 'mojibak':28,69 'often':25 'process':72 'python':13 'readabl':51 'releas':60 'somewhat':62 'text':3,8,20,42,71 'text-process':70 'unicod':19,67 'usabl':53 'version':56 'wrong':24","created_at":"2026-04-09T03:49:57.811038+00:00","updated_at":"2026-04-16T15:11:46.201870+00:00","problems":[{"fix":"You need to install the ftfy package using pip: `pip install ftfy`","cause":"The ftfy library is not installed in your Python environment or is not accessible within the current Python path.","error":"ModuleNotFoundError: No module named 'ftfy'"},{"fix":"Iterate over the list and apply `ftfy.fix_text()` to each string, or concatenate the list of strings into a single string before passing it to the function. Example: `fixed_text_list = [ftfy.fix_text(s) for s in my_list_of_strings]` or `single_string = ' '.join(my_list_of_strings); fixed_string = ftfy.fix_text(single_string)`","cause":"The `ftfy.fix_text()` function expects a single string as input, but it was provided with a list of strings.","error":"AttributeError: 'list' object has no attribute 'find' (within ftfy.fix_text)"},{"fix":"Avoid direct import or calling of `ftfy.bad_codecs`. The necessary codecs are registered automatically upon `import ftfy`. If a linter insists, `ftfy.bad_codecs.ok()` can be called to satisfy it, but it typically has no functional effect beyond registration.","cause":"This error occurs when trying to explicitly import or access `ftfy.bad_codecs` directly. The 'bad codecs' are generally made available to Python's standard codecs API simply by importing `ftfy` (or any part of it), and direct invocation of `ftfy.bad_codecs` is usually not necessary or intended.","error":"AttributeError: module 'ftfy' has no attribute 'bad_codecs'"},{"fix":"Install the missing dependency using pip: `pip install wcwidth` (or `pip install python-wcwidth` depending on your package manager and environment).","cause":"The `ftfy` library has a dependency on the `wcwidth` package, which is missing from your Python environment.","error":"ModuleNotFoundError: No module named 'wcwidth'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"6.3.1","cli_name":"","cli_version":null,"type":"library","homepage":"https://ftfy.readthedocs.io/en/latest/","github":"https://github.com/rspeer/python-ftfy","docs":"https://ftfy.readthedocs.io/en/latest/","changelog":"https://github.com/rspeer/python-ftfy/blob/main/CHANGELOG.md","pypi":"https://pypi.org/project/ftfy/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":"verified"}}