Typing Stubs for MarkupSafe

1.1.10 · active · verified Thu Apr 09

This is a PEP 561 type stub package providing external type annotations for the MarkupSafe library. It enables static type-checking tools like MyPy, PyCharm, or Pyright to analyze code that uses MarkupSafe. The current version is 1.1.10. These stub packages are automatically released by the Typeshed project, ensuring they follow typing specification standards.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install `types-markupsafe` and use a type checker like MyPy to verify the types in code that uses `MarkupSafe`. Note that `types-markupsafe` is only needed for `MarkupSafe` versions prior to 2.0, as newer versions include their own type annotations.

# 1. Install MarkupSafe (if not already present)
pip install MarkupSafe==1.1.1

# 2. Install types-markupsafe (for MarkupSafe versions < 2.0)
pip install types-markupsafe

# 3. Create a Python file (e.g., app.py) to use MarkupSafe
#    Note: This quickstart is for MarkupSafe < 2.0
from markupsafe import escape, Markup

def process_user_input(user_input: str) -> Markup:
    escaped_input = escape(user_input)
    return Markup(f"<p>You entered: {escaped_input}</p>")

html_output = process_user_input("<script>alert('xss')</script>")
print(html_output)

# 4. Run a type checker (e.g., MyPy)
# pip install mypy
# mypy app.py

view raw JSON →