Markup Processing Modules

html

Escape special characters for HTML text and quoted attributes, or decode HTML character references. escape() does not sanitize an entire document, validate URL schemes or protect JavaScript and CSS contexts. Use context-aware escaping when producing markup.

Formal Syntax & Structure

python syntaxpython
import html

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import htmlprint(html.escape("<b>Tea & milk</b>"))print(html.unescape("Tea &amp; milk"))
Python Reference