Replaces: webencodings (92M monthly downloads, abandoned since 2017)
Package name: webenc (verified available on PyPI)
Language: Python 3.10+
License: MIT
Zero dependencies
webencodings implements the WHATWG Encoding Standard but has not had a commit in 8+ years or a release in 9 years. The WHATWG spec was last updated December 2025. The package has 6 unreviewed PRs, 7 unanswered issues, and still lists Python 2.6/2.7 in its metadata. It is a transitive dependency of html5lib, tinycss2, bleach, and indirectly pip — affecting ~92M monthly downloads.
No maintained alternative exists.
Implement the WHATWG Encoding Standard (https://encoding.spec.whatwg.org/) for Python:
- Encoding label lookup — case-insensitive label-to-encoding mapping per the spec's encoding index
- BOM sniffing — detect UTF-8/UTF-16BE/UTF-16LE byte order marks
- Codec wrappers —
IncrementalDecoder/IncrementalEncoderwith web-compatible error handling - TextDecoder/TextEncoder API — Pythonic equivalents of the web platform API
- Encoding index — complete label-to-name mapping table from the current WHATWG spec (Dec 2025)
webenc/
├── __init__.py # Public API: lookup(), TextDecoder, TextEncoder
├── labels.py # WHATWG encoding label → name mapping table
├── codecs.py # IncrementalDecoder/Encoder with web error modes
├── bom.py # BOM sniffing utilities
├── py.typed # PEP 561 marker
└── _version.py # Version string
- Pure Python, zero dependencies — no C extensions, no system library requirements
- Spec-compliant — encoding labels and mappings from the current WHATWG spec, not the 2017 snapshot
- Type-annotated — full type annotations, PEP 561 compliant
- Drop-in compatible — provide a
webencodingscompatibility shim for easy migration - Three error modes —
replacement(U+FFFD),fatal(raise),html(numeric character references)
- Core library with full WHATWG encoding label support
- BOM sniffing per spec
- Web-compatible error handling (replacement, fatal, html modes)
- Compatibility API matching
webencodingsfor migration - Comprehensive test suite (label lookup, BOM detection, error modes, round-trip encoding)
- pyproject.toml with modern Python packaging
- README with migration guide from
webencodings
- Implementing actual codec algorithms (defer to Python's
codecsstdlib module) - Supporting Python < 3.10
- GUI or CLI tools