What I want is to get readable text, the best I can.
In other language (unofficial port - by the community)
All IANA character set names for which the Python core library provides codecs are supported.
You can also register your own set of codecs, and yes, it would work as-is.
This project offers you an alternative to Universal Charset Encoding Detector, also known as Chardet.
updated as of November 2026 using CPython 3.12, Charset-Normalizer 3.5.3, and Chardet 7.7 inside a (libc Debian) container. The host CPU is a 13th gen Intel mobile CPU. We'll no longer update regularly those since the sub-ms changes aren't meaningful to anyone anymore.
Stats are generated using 477 files using default parameters. More details on used files, see GHA workflows.
And yes, these results might change at any time. The dataset can be updated to include more files.
The actual delays heavily depends on your CPU capabilities. The factors should remain the same.
Chardet reports higher accuracy on its own benchmark. Chardet used our 477-file
corpus when developing its early 7.x model weights. Charset-normalizer scores
candidate decodings using noise heuristics and language letter frequencies.
✨ Installation
Using pip:
pip install charset-normalizer -U
🚀 Basic Usage
CLI
This package comes with a CLI.
usage: normalizer [-h] [-v] [-a] [-n] [-m] [-r] [-f] [-t THRESHOLD]
file [file ...]
The Real First Universal Charset Detector. Discover originating encoding used
on text file. Normalize text to unicode.
positional arguments:
files File(s) to be analysed
optional arguments:
-h, --help show this help message and exit
-v, --verbose Display complementary information about file if any.
Stdout will contain logs about the detection process.
-a, --with-alternative
Output complementary possibilities if any. Top-level
JSON WILL be a list.
-n, --normalize Permit to normalize input file. If not set, program
does not write anything.
-m, --minimal Only output the charset detected to STDOUT. Disabling
JSON output.
-r, --replace Replace file when trying to normalize it instead of
creating a new one.
-f, --force Replace file without asking if you are sure, use this
flag with caution.
-t THRESHOLD, --threshold THRESHOLD
Define a custom maximum amount of chaos allowed in
decoded content. 0. <= chaos <= 1.
--version Show version information and exit.
When I started using Chardet, I noticed that it was not suited to my expectations, and I wanted to propose a
reliable alternative using a completely different method. Also! I never back down on a good challenge!
In a way, I'm brute forcing text decoding. How cool is that ? 😎
Don't confuse package ftfy with charset-normalizer or chardet. ftfy goal is to repair Unicode string whereas charset-normalizer to convert raw file in unknown encoding to Unicode.
🍰 How
Discard all charset encoding table that could not fit the binary content.
Measure noise, or the mess once opened (by chunks) with a corresponding charset encoding.
Extract matches with the lowest mess detected.
Additionally, we measure coherence / probe for a language.
Wait a minute, what is noise/mess and coherence according to YOU ?
Noise : I opened hundred of text files, written by humans, with the wrong encoding table. I observed, then
I established some ground rules about what is obvious when it seems like a mess (aka. defining noise in rendered text).
I know that my interpretation of what is noise is probably incomplete, feel free to contribute in order to
improve or rewrite it.
Coherence : For each language there is on earth, we have computed ranked letter appearance occurrences (the best we can). So I thought
that intel is worth something here. So I use those records against decoded text to check if I can detect intelligent design.
⚡ Known limitations
Language detection is unreliable when text contains two or more languages sharing identical letters. (eg. HTML (english tags) + Turkish content (Sharing Latin characters))
Every charset detector heavily depends on sufficient content. In common cases, do not bother run detection on very tiny content.
⚠️ About Python EOLs
If you are running:
Python >=2.7,<3.5: Unsupported
Python 3.5: charset-normalizer < 2.1
Python 3.6: charset-normalizer < 3.1
Upgrade your Python interpreter as soon as possible.
👤 Contributing
Contributions, issues and feature requests are very much welcome.
Feel free to check issues page if you want to contribute.
Professional support for charset-normalizer is available as part of the Tidelift
Subscription. Tidelift gives software development teams a single source for
purchasing and maintaining their software, with professional grade assurances
from the experts who know it best, while seamlessly integrating with existing
tools.
Changelog
All notable changes to charset-normalizer will be documented in this file. This project adheres to Semantic Versioning.
The format is based on Keep a Changelog.
Faster noise scoring in both the pure-Python and Cython implementations by reusing
Unicode character properties. The Cython extensions also speed up language ranking
and checks for suspicious transitions between Unicode blocks.
Reduced detection overhead by skipping redundant UTF-8 sample alignment checks and
repeated logging checks when tracing is disabled.
Raised the setuptools upper bound to <84.3, allowing source builds with setuptools
84.1 and 84.2. (#828)
Fixed
Fixed detection of registered multibyte codecs when a sample boundary splits a character.
The detector now strictly decodes the full input with the custom codec before sampling
the resulting text.
Kept single-byte candidates in consideration when a Chinese, Japanese or Korean
decoding has measurable noise and no matching language.
Recognized ASCII information separators (0x1C through 0x1F) as whitespace when
scoring text, including record-separated JSON. (#821)
Removed the leading GB18030 signature from lazily decoded matches on large inputs. (#820)
Fixed UTF-7 text with a signature being misidentified as ASCII when a sample
started in the middle of a long encoded sequence. (#839)
Fixed language detection returning names such as English— when only an alternative
language profile met the coherence threshold. (#823)
CharsetMatch.output() now updates a UTF-8 declaration when transcoding to another
encoding and preserves the last successful output if a later conversion fails. (#819, #814)
The legacy detect() function now reports ISO-8859-1 for Latin-1 by default. (#813)
Both python -m charset_normalizer and python -m charset_normalizer.cli now
propagate the CLI exit status. (#817)
CLI JSON output with --with-alternative now always uses a top-level array,
including for a single result or a file with no match. (#822)
normalizer --normalize now appends the detected encoding to extensionless
filenames when creating a copy (for example, README becomes README.cp1252). (#838)
Excluded Python 3.16's utf_7_imap mailbox codec from detection to prevent
errors when probing unrelated encodings. (#825)
Raised the Cython upper bound to <3.4 for native builds. The bound remains <3.3 for
abi3 builds to preserve compatibility with the Python 3.7 Limited API.
Fixed
Valid UTF-8 Chinese JSON incorrectly detected as PTCP154 due to excessive noise penalties
for uncommon CJK characters. (#796)
Supported encodings without aliases failing name resolution or being ignored in charset
declarations. (#800)
Comparing a CharsetMatch to a non-alias encoding strings (#773)
Return 0.0 CharsetMatch.multi_byte_usage for empty payloads instead of crashing (#774)
A file with both a charset declaration and BOM/SIG did not verify first the BOM/SIG charset.
iso2022* cases misdetected due to a flaw in our multibyte chunking logic.
Changed
Replaced the optional mypyc build with Cython extensions while retaining the
pure Python fallback. The previous engine (mypyc) started to hit rough limit around
the optimization of our noise/coherence detector while Cython allows us to
steer the engine toward the right generated optimized sources.
This change SHOULD not impact bundler (e.g. Pyinstaller) as the module are
immediately discoverable (i.e. not hidden import like mypyc did).
Moreover, a long wished distribution is the abi3 wheels, this will allow us
to no longer rush each year when a new Python interpreter is released.
We still distribute the interpreter specific wheels for faster performance.
Applied micro-optimization on several utils.
CharsetMatches no longer sort on each match insertion.
Misc
Removed an old performance optimization attempt in apy.py (success_fast_tracked+payload_result_cache).
mypy(c) is no longer a required dependency at build time if CHARSET_NORMALIZER_USE_MYPYC isn't set to 1. (#595) (#583)
automatically lower confidence on small bytes samples that are not Unicode in detect output legacy function. (#391)
Added
Custom build backend to overcome inability to mark mypy as an optional dependency in the build phase.
Support for Python 3.14
Fixed
sdist archive contained useless directories.
automatically fallback on valid UTF-16 or UTF-32 even if the md says it's noisy. (#633)
Misc
SBOM are automatically published to the relevant GitHub release to comply with regulatory changes.
Each published wheel comes with its SBOM. We choose CycloneDX as the format.
Prebuilt optimized wheel are no longer distributed by default for CPython 3.7 due to a change in cibuildwheel.
Output the Unicode table version when running the CLI with --version (PR #194)
Changed
Reuse decoded buffer for single byte character sets from @nijel (PR #175)
Fixing some performance bottlenecks from @deedy5 (PR #183)
Fixed
Workaround potential bug in cpython with Zero Width No-Break Space located in Arabic Presentation Forms-B, Unicode 1.1 not acknowledged as space (PR #175)
CLI default threshold aligned with the API threshold from @oleksandr-kuzmenko (PR #181)
Removed
Support for Python 3.5 (PR #192)
Deprecated
Use of backport unicodedata from unicodedata2 as Python is quickly catching up, scheduled for removal in 3.0 (PR #194)
Fix error while using the package with a python pre-release interpreter (PR #33)
Changed
Dependencies refactoring, constraints revised.
Added
Add python 3.9 and 3.10 to the supported interpreters
MIT License
Copyright (c) 2025 TAHRI Ahmed R.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Footnotes
Usage of specific code or data per encoding. Not a generalist approach. ↩
Chardet does not feed the complete body but rather a limited part of it, because the algorithm doesn't scale properly with larger samples. Internal hard limits can't be bypassed even with max_bytes set to full size. Each internal steps have an arbitrary cap that can't be configured. ↩
Alternatives
Use instead of charset-normalizer: tools that do the same job, closest first.