types-chardet is a PEP 561 type stub package that provides static type information for the `chardet` library. It allows type checkers like Mypy, Pyright, or PyCharm to perform static analysis and detect type-related errors in code that uses `chardet` for character encoding detection, without affecting the runtime behavior of the application. This package is maintained as part of the broader Typeshed project. The current version is 5.0.4.6, and it follows the release cadence of the Typeshed project, which releases updates for third-party stubs regularly.
pip install types-chardetVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic usage of the `chardet` library. When `types-chardet` is installed, a static type checker will be able to verify the types of arguments and return values, such as ensuring that `chardet.detect()` is called with `bytes` data.
Uninstall `types-chardet` using `pip uninstall types-chardet` if your `chardet` version is 5.1.0 or newer. Rely on the inline types provided by `chardet` itself.
Ensure `chardet` is listed as a runtime dependency and installed alongside `types-chardet`.
For optimal compatibility, consider pinning `types-chardet` with the same major.minor version range as `chardet` (e.g., `chardet>=5.0,<5.1` and `types-chardet>=5.0,<5.1`) or relying on the latest available stubs, understanding that stubs might occasionally lag behind or precede runtime changes.
If upgrading to `chardet` 7.x, ensure your project's Python version is 3.10 or newer. Review `chardet`'s release notes for any subtle behavioral changes, although the API for basic detection (`chardet.detect()`) remains consistent.