chardet: Universal Character Encoding Detector

7.4.0.post1 · active · verified Sat Mar 28

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.

Warnings

Install

Imports

Quickstart

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'}

view raw JSON →