{"id":2340,"library":"types-markupsafe","title":"Typing Stubs for MarkupSafe","description":"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.","status":"active","version":"1.1.10","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed/tree/main/stubs/MarkupSafe","tags":["typing","stubs","type-checking","markupsafe"],"install":[{"cmd":"pip install types-markupsafe","lang":"bash","label":"Install types-markupsafe"}],"dependencies":[{"reason":"Provides type stubs for the MarkupSafe library; MarkupSafe itself must be installed to be type-checked.","package":"MarkupSafe","optional":true}],"imports":[{"note":"types-markupsafe provides type hints for the actual markupsafe library. There are no runtime objects to import directly from types-markupsafe.","symbol":"Markup","correct":"from markupsafe import Markup"},{"note":"types-markupsafe provides type hints for the actual markupsafe library. There are no runtime objects to import directly from types-markupsafe.","symbol":"escape","correct":"from markupsafe import escape"}],"quickstart":{"code":"# 1. Install MarkupSafe (if not already present)\npip install MarkupSafe==1.1.1\n\n# 2. Install types-markupsafe (for MarkupSafe versions < 2.0)\npip install types-markupsafe\n\n# 3. Create a Python file (e.g., app.py) to use MarkupSafe\n#    Note: This quickstart is for MarkupSafe < 2.0\nfrom markupsafe import escape, Markup\n\ndef process_user_input(user_input: str) -> Markup:\n    escaped_input = escape(user_input)\n    return Markup(f\"<p>You entered: {escaped_input}</p>\")\n\nhtml_output = process_user_input(\"<script>alert('xss')</script>\")\nprint(html_output)\n\n# 4. Run a type checker (e.g., MyPy)\n# pip install mypy\n# mypy app.py","lang":"python","description":"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."},"warnings":[{"fix":"Uninstall `types-markupsafe` using `pip uninstall types-markupsafe`. Keep `markupsafe` installed.","message":"The `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.","severity":"breaking","affected_versions":"MarkupSafe >= 2.0"},{"fix":"Pin `types-markupsafe` to a version compatible with your `markupsafe` installation. For `markupsafe < 2.0`, typically `types-markupsafe` matches the minor version.","message":"Ensure 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`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Do not attempt to import from or use `types-markupsafe` in your Python code. Continue to import `Markup` and `escape` from `markupsafe`.","message":"`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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}