Registry / serialization / mbstrdecoder

mbstrdecoder

JSON →
library1.1.5pypypi✓ verified 24d ago

mbstrdecoder is a Python library designed for robust decoding of multi-byte character strings, particularly useful when dealing with unknown or potentially malformed encodings. It aims to prevent `UnicodeDecodeError` exceptions by attempting to decode using various strategies, often leveraging the `chardet` library for encoding detection. The current version is 1.1.4, and it generally follows a minor release cadence driven by Python version support and bug fixes.

pip install mbstrdecoder
INSTALL
IMPORT
SIG · MBSTRDECODER
M
mbstrdecoder
serializationpythonv1.1.5
Install
2.5s avg
Import
14ms
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.5 · 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.014s · 34MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.014s · 34MB
33MB installed
● package 33MB
Code
Verified usage

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

MultiByteStrDecoder
from mbstrdecoder import MultiByteStrDecoder
from mbstrdecoder import MbStrDecoder
detect_file_encoding
from mbstrdecoder import detect_file_encoding

Initialize `MbStrDecoder` with a byte string. You can optionally provide an initial `encoding` hint or let it auto-detect. The `unicode_str` attribute holds the decoded string, and `detected_encoding` shows the encoding used.

from mbstrdecoder import MbStrDecoder # Example 1: Decode a byte string with known encoding decoder1 = MbStrDecoder(b"hello\xc2\xa3world", encoding="utf-8") print(f"Decoded (UTF-8 known): {decoder1.unicode_str}, Encoding: {decoder1.detected_encoding}") # Example 2: Decode a byte string with unknown encoding (chardet will detect) decoder2 = MbStrDecoder(b"\xa3123.45") # Assuming some non-UTF8 locale, chardet will try print(f"Decoded (auto-detect): {decoder2.unicode_str}, Encoding: {decoder2.detected_encoding}") # Example 3: Handling undecodable bytes gracefully (if any) decoder3 = MbStrDecoder(b'\xed\xa0\x80some invalid bytes', errors='replace') print(f"Decoded (replace errors): {decoder3.unicode_str}, Encoding: {decoder3.detected_encoding}")
Debug
Known issues
breakingPython 3.7 and 3.8 support was dropped in version 1.1.4. Users on these Python versions must upgrade their Python environment or pin mbstrdecoder to an older version (e.g., <1.1.4).
fix
Upgrade to Python 3.9 or newer, or specify `mbstrdecoder<1.1.4` in your project dependencies.
affects: >=1.1.4
gotchaPrior to version 1.1.4, there were reported issues where `UnicodeDecodeError` exceptions might not be sent (or propagated) correctly during decoding attempts, leading to silent failures or unexpected behavior in error handling logic.
fix
Upgrade to version 1.1.4 or newer to ensure correct `UnicodeDecodeError` exception handling and propagation.
affects: <1.1.4
gotchaThe `chardet` library is a mandatory dependency. While it was optional in very early versions, it became mandatory from v0.8.2 onwards and has specific version requirements (`chardet>=3.0.2,<6.0.0`). Ensure it's installed alongside `mbstrdecoder` to avoid import errors related to encoding detection.
fix
Ensure `chardet` is part of your project's `pip install` commands. `pip install mbstrdecoder` should handle this automatically for recent versions.
affects: All
Upgrade
Version history
1.1.5latest on PyPI · released May 5, 2026
Audit
Dependencies
chardetrequiredUsed for automatic encoding detection, mandatory dependency.
Agent activity
13 hits · last 30 days
node
12
Resources
mbstrdecoder — pip install mbstrdecoder · libregistry