Registry / type-stubs / types-chardet

types-chardet

JSON →
library5.0.4.6pypypi✓ verified 24d ago

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-chardet
INSTALL
IMPORT
SIG · TYPES-CHARDET
T
types-chardet
type-stubspythonv5.0.4.6
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.0.4.6 · 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.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

detect
from chardet_stubs import detect
from chardet_stubs import detect

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.

import chardet def analyze_encoding(data: bytes) -> dict: """Detects the encoding of a byte string.""" result = chardet.detect(data) print(f"Detected encoding: {result['encoding']} with confidence {result['confidence']}") return result # Example usage with bytes data sample_data = "München ist die Hauptstadt Bayerns.".encode("windows-1252") analysis = analyze_encoding(sample_data) # Without types-chardet, a type checker might not flag if you passed # a 'str' instead of 'bytes' to chardet.detect. With it, it would. # try_wrong_data = analyze_encoding("This is a string") # Mypy/Pyright would flag this as an error
Debug
Known issues
breakingThe `chardet` library, starting from version 5.1.0, includes its own inline type annotations. If you are using `chardet>=5.1.0`, you should uninstall `types-chardet` to avoid potential conflicts with the package's native type information.
fix
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.
affects: chardet >= 5.1.0
gotcha`types-chardet` provides only type stubs; it does not install the actual `chardet` runtime library. For your code to run, `chardet` must be installed separately (e.g., `pip install chardet`).
fix
Ensure `chardet` is listed as a runtime dependency and installed alongside `types-chardet`.
affects: All versions
gotchaThe versioning of `types-chardet` follows Typeshed's policy, where the first three parts align with the `chardet` version it stubs (e.g., `5.0.4` for `chardet` 5.0.x), followed by a Typeshed-specific identifier. Direct version pinning between `chardet` and `types-chardet` can be complex and might sometimes lead to conflicts or missed type improvements.
fix
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.
affects: All versions
gotcha`chardet` underwent a significant rewrite in version 7.x, introducing substantial performance improvements, new features (like MIME type detection), and dropping support for older Python versions (now requiring Python 3.10+). While the public API remained largely compatible, be aware of the underlying changes and Python version requirements if migrating to `chardet` 7.x.
fix
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.
affects: chardet < 7.0.0
Upgrade
Version history
5.0.4.6latest on PyPI · released May 10, 2023
Audit
Dependencies
chardetrequiredThis package provides type stubs for the 'chardet' library. The 'chardet' library itself must be installed to provide the runtime functionality. The latest 'chardet' versions (7.x) require Python 3.10+.
Agent activity
33 hits · last 30 days
node
30
Amazon
1
OpenAI (training)
1
Resources
types-chardet — pip install types-chardet · libregistry