Install & Compatibility
Where this runs
tested against v1.1.10 · 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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Markup
✓ from markupsafe_stubs import Markup
✗ from markupsafe_stubs import Markup
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
Debug
Known issues
breakingThe `MarkupSafe` library itself includes type annotations since version 2.0. If you are using `MarkupSafe` 2.0 or newer, you MUST uninstall `types-MarkupSafe` to avoid conflicts and ensure correct type checking, as `types-MarkupSafe` is intended for `MarkupSafe` versions older than 2.0.fixUninstall `types-markupsafe` using `pip uninstall types-markupsafe`. Keep `markupsafe` installed.
affects: MarkupSafe >= 2.0
gotchaEnsure the version of `types-markupsafe` you install is compatible with your installed `markupsafe` version. The `types-markupsafe` version number (excluding the last part) aims to match the `markupsafe` version it provides stubs for. `types-markupsafe 1.1.x` is for `markupsafe 1.1.x`.fixPin `types-markupsafe` to a version compatible with your `markupsafe` installation. For `markupsafe < 2.0`, typically `types-markupsafe` matches the minor version.
affects: All versions
gotcha`types-markupsafe` is a stub-only package and provides no runtime functionality. It should not be imported directly in your application code, nor does it expose any objects or functions at runtime. Its sole purpose is to be consumed by static type checkers.fixDo not attempt to import from or use `types-markupsafe` in your Python code. Continue to import `Markup` and `escape` from `markupsafe`.
affects: All versions
Upgrade
Version history
1.1.10latest on PyPI · released Nov 27, 2021
Audit
Dependencies
MarkupSafeoptionalProvides type stubs for the MarkupSafe library; MarkupSafe itself must be installed to be type-checked.