Drop-in replacement for bleach, the deprecated HTML sanitization library.
- Same API as bleach (
clean,linkify,Cleaner,Linker,CSSSanitizer) - Zero dependencies — uses
html.parserfrom stdlib - Python 3.10+
- Full type annotations
pip install blanchimport blanch
# Sanitize HTML
blanch.clean("<script>alert('xss')</script><b>hello</b>")
# '<script>alert(\'xss\')</script><b>hello</b>'
# Linkify URLs
blanch.linkify("Visit https://example.com")
# 'Visit <a href="https://example.com" rel="nofollow">https://example.com</a>'# Option 1: Replace import
# Before: import bleach
import blanch as bleach
# Option 2: Use compatibility layer
import blanch.compat.bleach as bleachMIT