Registry / data / ftfy

ftfy

JSON →
library6.3.1pypypi✓ verified 52d ago

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.

dataserialization
pip install ftfy
Install & Compatibility
Where this runs
tested against v6.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.930 runs
installs and imports cleanly · install 0.0s · import 0.318s · 25MB
glibc
py 3.103.930 runs
installs and imports cleanly · install 1.7s · import 0.279s · 26MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fix_text
from ftfy import fix_text
fix_and_explain
from ftfy import fix_and_explain
from ftfy.fixes import fix_encoding_and_explain
The `fix_encoding_and_explain` function was removed in 6.0.x; use `fix_and_explain` instead.

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
Debug
Known issues
breakingftfy 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.
fix
Thoroughly test ftfy's behavior on your specific data after upgrading. For detailed insights into changes, use `ftfy.fix_and_explain()`.
affects: >=6.0.0
deprecatedThe 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`.
fix
Update your code to `from ftfy import fix_and_explain` and use the new top-level function.
affects: <6.0.0
breakingftfy 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+).
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`).
affects: >=6.0.0
gotchaftfy 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.
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.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ftfy'
The ftfy library is not installed in your Python environment or is not accessible within the current Python path.
fix
You need to install the ftfy package using pip: `pip install ftfy`
AttributeError: 'list' object has no attribute 'find' (within ftfy.fix_text)
The `ftfy.fix_text()` function expects a single string as input, but it was provided with a list of strings.
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)`
AttributeError: module 'ftfy' has no attribute 'bad_codecs'
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.
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.
ModuleNotFoundError: No module named 'wcwidth'
The `ftfy` library has a dependency on the `wcwidth` package, which is missing from your Python environment.
fix
Install the missing dependency using pip: `pip install wcwidth` (or `pip install python-wcwidth` depending on your package manager and environment).
Upgrade
Version history
6.3.1latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
6
seranking-bot
4
ahrefsbot
2
Meta
1
amazonbot
1
Resources