{
 "kind": "tool",
 "slug": "markupsafe",
 "path": "tools/markupsafe/",
 "name": "MarkupSafe",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Auth and security libraries",
   "tools/auth-security/"
  ]
 ],
 "lead": "Show user text on web pages safely.",
 "chips": [
  {
   "label": "Auth and security libraries",
   "path": "tools/auth-security/"
  },
  {
   "label": "PYPI"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "pip install markupsafe"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/pallets/markupsafe"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "BSD-3-Clause",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met",
   "note": "BSD-3-Clause allows use in paid and closed products.",
   "src": "https://github.com/pallets/markupsafe/blob/main/LICENSE.txt"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Oct 3, 2026",
   "note": "Latest GitHub release Oct 2, 2026. ",
   "src": "https://github.com/pallets/markupsafe"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "45 projects",
   "status": "info",
   "sub": "#15 of 141 in its category",
   "note": "Dependency in 45 public GitHub projects set up for AI coding agents that we scanned (0.7%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 11, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What MarkupSafe does",
   "parts": [
    {
     "t": "prose",
     "text": "MarkupSafe is a small free Python library that makes text safe to put into a web page. Characters like < and & in a user's name or comment are turned into harmless codes, so a hidden script shows up as plain text instead of running. Jinja2 and Flask use it under the hood; it does not clean up HTML that you want to keep."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Show names and comments from users",
       "text": "A visitor signs up with a name that contains a script tag; your page shows the name as typed, and the script never runs.",
       "idea": false
      },
      {
       "title": "Build HTML snippets in Python code",
       "text": "Your app builds a small piece of HTML, like a comment card or an email line, in Python; the template is trusted and every value put into it is escaped.",
       "idea": false
      },
      {
       "title": "Objects that draw themselves as HTML",
       "text": "A User or Image class in your app gives its own HTML for templates, while the parts that come from users are still escaped.",
       "idea": false
      },
      {
       "title": "Plain-text previews of HTML",
       "text": "For a search snippet or a notification, your app turns stored safe HTML into plain words without the tags.",
       "idea": false
      },
      {
       "title": "Safe text in your own small template helpers",
       "text": "If your project prints HTML from Python without a template engine, for example in an admin script or a report generator, one escape call per value keeps it safe.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "MarkupSafe popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "67",
       "of": "/ 100",
       "l": "Gid Score, #566 overall"
      },
      {
       "n": "198M",
       "l": "downloads a week, pypi"
      },
      {
       "n": "702",
       "l": "GitHub stars"
      },
      {
       "n": "45",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How MarkupSafe is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "MarkupSafe is a dependency in 45 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (2.8% of the 1,623 Python ones), #15 of 141 in auth and security libraries.",
      "Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,197; those are left out of every share on this page.",
      "Projects that use it most often also use Requests (86.7%), Click (84.4%), urllib3 (82.2%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "27 projects, 0.9%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "22 projects, 0.7%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "19 projects, 0.8%",
       "v": "Cursor",
       "path": "agents/cursor/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 86.7% of its projects",
       "v": "Requests",
       "path": "tools/requests-py/"
      },
      {
       "l": "In 84.4% of its projects",
       "v": "Click",
       "path": "tools/click-py/"
      },
      {
       "l": "In 82.2% of its projects",
       "v": "urllib3",
       "path": "tools/urllib3/"
      },
      {
       "l": "In 80.0% of its projects",
       "v": "charset-normalizer",
       "path": "tools/charset-normalizer/"
      },
      {
       "l": "In 80.0% of its projects",
       "v": "Jinja2",
       "path": "tools/jinja2/"
      },
      {
       "l": "In 77.8% of its projects",
       "v": "Pydantic",
       "path": "tools/pydantic/"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "usage",
   "h2": "More about MarkupSafe",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "GitHub Sponsors: https://github.com/pallets",
        "Own page: https://palletsprojects.com/donate",
        "Tidelift: https://tidelift.com/funding/github/pypi/Flask",
        "thanks.dev: https://thanks.dev/u/gh/pallets",
        "31 GitHub sponsors"
       ]
      },
      {
       "title": "More in Auth and security libraries",
       "path": "tools/auth-security/",
       "items": [
        {
         "text": "bcryptjs",
         "path": "tools/bcryptjs/"
        },
        {
         "text": "NextAuth.js",
         "path": "tools/next-auth/"
        },
        {
         "text": "jsonwebtoken",
         "path": "tools/jsonwebtoken/"
        },
        {
         "text": "cryptography",
         "path": "tools/cryptography/"
        },
        {
         "text": "PyJWT",
         "path": "tools/pyjwt/"
        },
        {
         "text": "jose",
         "path": "tools/jose/"
        },
        {
         "text": "Better Auth",
         "path": "tools/better-auth/"
        },
        {
         "text": "DOMPurify",
         "path": "tools/dompurify/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "MarkupSafe",
       "me": true,
       "facts": [
        "BSD-3-Clause",
        "Gid 67",
        "198M/wk"
       ]
      },
      {
       "name": "nh3",
       "why": "Pick nh3 when users may post some HTML, like bold text and links, and you want to keep the allowed tags and remove the rest.",
       "path": "tools/nh3/",
       "facts": []
      },
      {
       "name": "Jinja2",
       "why": "Pick Jinja2 when you are building whole pages; it escapes values for you in HTML templates, using MarkupSafe inside.",
       "path": "tools/jinja2/",
       "facts": []
      },
      {
       "name": "Bleach",
       "why": "Pick Bleach for an allow-list HTML cleaner in older Python projects that already use it.",
       "path": "tools/bleach/",
       "facts": []
      }
     ],
     "more": "Compare MarkupSafe with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "In this Python code that builds HTML by hand, use MarkupSafe 3.0.4 (pin markupsafe==3.0.4) to wrap only our own fixed template strings in Markup and pass every user value through Markup.format or escape; never wrap user input in Markup."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Install it into your project's Python environment (Jinja2 and Flask already bring it along).",
       "code": "pip install -U MarkupSafe",
       "src": "https://markupsafe.palletsprojects.com/en/stable/"
      },
      {
       "text": "Escape any value before it goes into HTML; the result is marked safe so it is not escaped twice.",
       "code": ">>> from markupsafe import escape\n>>> hello = escape(\"<em>Hello</em>\")\n>>> hello\nMarkup('&lt;em&gt;Hello&lt;/em&gt;')\n",
       "src": "https://markupsafe.palletsprojects.com/en/stable/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "Markup(user_input) or Markup(f\"<b>{name}</b>\")",
       "fix": "Markup(\"<b>{}</b>\").format(name), or escape(name)",
       "why": "The Markup constructor marks text safe without escaping, so the user's tags would run."
      },
      {
       "dont": "escape(str(value)) on a value that is already Markup",
       "fix": "escape(soft_str(value)) or keep the Markup object as it is",
       "why": "str() drops the safe mark and the text is escaped again; our run turned & into &amp;amp;."
      },
      {
       "dont": "Putting card.striptags() straight back into HTML",
       "fix": "Escape the result again before it goes into a page; striptags returns plain text with HTML codes turned back into characters",
       "why": "In our run striptags gave back '<img src=x onerror=alert(1)>' as raw characters, because it unescapes first."
      },
      {
       "dont": "from markupsafe import soft_unicode",
       "fix": "from markupsafe import soft_str",
       "why": "soft_unicode was removed in 2.1.0; old Jinja2 versions fail on import because of it."
      },
      {
       "dont": "markupsafe.__version__ to check the version",
       "fix": "importlib.metadata.version(\"markupsafe\")",
       "why": "The attribute is deprecated since 3.0.0 and raises a DeprecationWarning since 3.0.3."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Why do I see &amp;amp; on my page?",
       "a": "The text was escaped twice. Converting Markup back with str() drops its safe mark; keep the Markup object or use soft_str.",
       "evidence": {
        "url": "https://markupsafe.palletsprojects.com/en/stable/escaping/",
        "quote": "This preserves a Markup string rather than converting it back to a basic string, so it will still be marked as safe and won't be escaped again."
       }
      },
      {
       "q": "Why does my page show the word None?",
       "a": "escape(None) gives the text \"None\"; use escape_silent for values that may be missing.",
       "evidence": {
        "url": "https://markupsafe.palletsprojects.com/en/stable/escaping/",
        "quote": "Like escape() but treats None as the empty string."
       }
      },
      {
       "q": "My old code imports soft_unicode and fails. What changed?",
       "a": "soft_unicode was removed in version 2.1.0; use soft_str instead.",
       "evidence": {
        "url": "https://markupsafe.palletsprojects.com/en/stable/changes/",
        "quote": "which was previously deprecated. Use soft_str instead."
       }
      },
      {
       "q": "Can I use it in a paid product?",
       "a": "Yes. The BSD-3-Clause license allows it; keep the notice and do not use the project's name to promote your product.",
       "evidence": {
        "url": "https://github.com/pallets/markupsafe/blob/main/LICENSE.txt",
        "quote": "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met"
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "pypi markupsafe"
  ],
  [
   "Category",
   "Auth and security libraries"
  ],
  [
   "License",
   "BSD-3-Clause"
  ],
  [
   "Gid Score",
   "66.7"
  ],
  [
   "Rank in category",
   "#15 of 141"
  ],
  [
   "GitHub",
   "pallets/markupsafe"
  ],
  [
   "Last change",
   "Oct 3, 2026"
  ]
 ],
 "good": [
  "Wrapping text in Markup tells the library the text is already safe, so it is not escaped. Never do that with text from users.",
  "It escapes all text; it does not keep some tags and remove others. To allow bold or links in user posts, use an HTML cleaner such as nh3.",
  "Since version 3.0, a few text methods such as strip and partition no longer escape what you pass to them."
 ],
 "checked_line": "Read by AgentGid from 10 official pages, card checked Nov 11, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/pallets.png"
}