Registry / serialization / chardet

chardet

JSON →
library7.6.0pypypi✓ verified 26d ago

chardet is a Python library that detects the character encoding of byte strings, providing the detected encoding, confidence score, and language. The current version is 7.4.0.post1, released on March 14, 2026. It is actively maintained with regular updates, focusing on improving accuracy and performance. The library requires Python 3.10 or higher and has zero runtime dependencies, making it suitable for various Python environments, including PyPy.

pip install chardet
INSTALL
IMPORT
SIG · CHARDET
C
chardet
serializationpythonv7.6.0
Install
1.8s avg
Import
91ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.6.0 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.096s · 19.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.086s · 22MB
18MB installed
● package 18MB
Code
Verified usage

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

detect
from chardet import detect
Ensure 'detect' is imported from 'chardet' to access the detection function.

Use the 'detect' function from the 'chardet' module to analyze byte strings and determine their encoding.

import chardet # Detect encoding of a byte string result = chardet.detect(b'Hello, world!') print(result) # Output: {'encoding': 'ascii', 'confidence': 1.0, 'language': 'en'}
Debug
Known issues
breakingchardet 7.0 is a ground-up, MIT-licensed rewrite — same package name, same public API — drop-in replacement for chardet 5.x/6.x. Python 3.10+, zero runtime dependencies, works on PyPy.
fix
Update to chardet 7.0 or later to ensure compatibility and benefit from improved performance and accuracy.
affects: 5.x/6.x
deprecatedchardet 7.0.0 introduced a new dense zlib-compressed model format (v2) that significantly reduces cold start times. Ensure your environment supports this format for optimal performance.
fix
Verify that your environment is compatible with the new model format to take advantage of the performance improvements.
affects: 7.0.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'chardet'
The `chardet` library is not installed in the Python environment being used, or the Python interpreter cannot find it due to incorrect path configurations or virtual environment issues.
fix
Install the `chardet` library using pip: `pip install chardet` (or `pip3 install chardet` for Python 3 specific installations).
TypeError: Expected object of type bytes or bytearray, got: <class 'str'>
The `chardet.detect()` function, or other functions within the library, expects a byte string (`bytes` or `bytearray`) as input, but a regular Python string (`str`) was provided.
fix
Convert the string input to bytes using an appropriate encoding (e.g., `some_string.encode('utf-8')`) before passing it to `chardet.detect()`. Example: `chardet.detect(your_string.encode('utf-8'))`. If reading from a file, open it in binary read mode (`'rb'`).
chardet returns None for encoding
The `chardet.detect()` function returns `None` for the 'encoding' key when the provided data appears to be binary rather than text, or contains too many null bytes or control characters that prevent a confident text encoding detection.
fix
Ensure the input data is indeed text-like. If it's genuinely binary, `chardet` cannot detect a text encoding. If it is text, providing more data to `chardet.detect()` or using `chardet.detect_all()` to see other candidates might help.
Upgrade
Version history
7.6.0latest on PyPI · released Aug 14, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
50 hits · last 30 days
node
46
OpenAI (training)
1
Resources
chardet — pip install chardet · libregistry