{"id":386,"library":"chardet","title":"chardet: Universal Character Encoding Detector","description":"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.","status":"active","version":"7.4.0.post1","language":"python","source_language":"en","source_url":"https://github.com/chardet/chardet","tags":["character encoding","Python","library","chardet","encoding detection"],"install":[{"cmd":"pip install chardet","lang":"bash","label":"Install chardet"}],"dependencies":[],"imports":[{"note":"Ensure 'detect' is imported from 'chardet' to access the detection function.","symbol":"detect","correct":"from chardet import detect"}],"quickstart":{"code":"import chardet\n\n# Detect encoding of a byte string\nresult = chardet.detect(b'Hello, world!')\nprint(result)\n# Output: {'encoding': 'ascii', 'confidence': 1.0, 'language': 'en'}","lang":"python","description":"Use the 'detect' function from the 'chardet' module to analyze byte strings and determine their encoding."},"warnings":[{"fix":"Update to chardet 7.0 or later to ensure compatibility and benefit from improved performance and accuracy.","message":"chardet 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.","severity":"breaking","affected_versions":"5.x/6.x"},{"fix":"Verify that your environment is compatible with the new model format to take advantage of the performance improvements.","message":"chardet 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.","severity":"deprecated","affected_versions":"7.0.0"}],"env_vars":null,"last_verified":"2026-05-12T13:27:29.829Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the `chardet` library using pip: `pip install chardet` (or `pip3 install chardet` for Python 3 specific installations).","cause":"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.","error":"ModuleNotFoundError: No module named 'chardet'"},{"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'`).","cause":"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.","error":"TypeError: Expected object of type bytes or bytearray, got: <class 'str'>"},{"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.","cause":"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.","error":"chardet returns None for encoding"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":3,"disk_size":"18.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":2.9,"disk_size":"20M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.13,"mem_mb":3.3,"disk_size":"20.8M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":3.3,"disk_size":"22M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":3.3,"disk_size":"12.7M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":3.2,"disk_size":"14M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":3.1,"disk_size":"12.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.09,"mem_mb":2.9,"disk_size":"14M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":3.5,"disk_size":"19.0M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":3.5,"disk_size":"20M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}