Skip to main content

Safely add untrusted strings to HTML/XML markup.

Project description

MarkupSafe implements a text object that escapes characters so it is safe to use in HTML and XML. Characters that have special meanings are replaced so that they display as the actual characters. This mitigates injection attacks, meaning untrusted user input can safely be displayed on a page.

Installing

Install and update using pip:

pip install -U MarkupSafe

Examples

>>> from markupsafe import Markup, escape

>>> # escape replaces special characters and wraps in Markup
>>> escape("<script>alert(document.cookie);</script>")
Markup('&lt;script&gt;alert(document.cookie);&lt;/script&gt;')

>>> # wrap in Markup to mark text "safe" and prevent escaping
>>> Markup("<strong>Hello</strong>")
Markup('<strong>hello</strong>')

>>> escape(Markup("<strong>Hello</strong>"))
Markup('<strong>hello</strong>')

>>> # Markup is a str subclass
>>> # methods and operators escape their arguments
>>> template = Markup("Hello <em>{name}</em>")
>>> template.format(name='"World"')
Markup('Hello <em>&#34;World&#34;</em>')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for MarkupSafe, version 2.0.1
Filename, size File type Python version Upload date Hashes
Filename, size MarkupSafe-2.0.1-cp36-cp36m-macosx_10_9_x86_64.whl (13.9 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp36-cp36m-manylinux1_i686.whl (29.9 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp36-cp36m-manylinux1_x86_64.whl (30.2 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp36-cp36m-manylinux2010_i686.whl (29.9 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp36-cp36m-manylinux2010_x86_64.whl (30.2 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp36-cp36m-manylinux2014_aarch64.whl (31.4 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp36-cp36m-win32.whl (14.3 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp36-cp36m-win_amd64.whl (14.9 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp37-cp37m-macosx_10_9_x86_64.whl (13.9 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp37-cp37m-manylinux1_i686.whl (30.7 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp37-cp37m-manylinux1_x86_64.whl (31.1 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_i686.whl (30.8 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_x86_64.whl (31.1 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp37-cp37m-manylinux2014_aarch64.whl (32.3 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp37-cp37m-win32.whl (14.3 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp37-cp37m-win_amd64.whl (14.9 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp38-cp38-macosx_10_9_x86_64.whl (14.0 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp38-cp38-manylinux1_i686.whl (30.2 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp38-cp38-manylinux1_x86_64.whl (30.6 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp38-cp38-manylinux2010_i686.whl (30.2 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp38-cp38-manylinux2010_x86_64.whl (30.6 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp38-cp38-manylinux2014_aarch64.whl (31.9 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp38-cp38-win32.whl (14.3 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp38-cp38-win_amd64.whl (14.9 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp39-cp39-macosx_10_9_universal2.whl (18.3 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp39-cp39-macosx_10_9_x86_64.whl (14.0 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp39-cp39-manylinux1_i686.whl (30.2 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp39-cp39-manylinux1_x86_64.whl (30.6 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp39-cp39-manylinux2010_i686.whl (30.2 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp39-cp39-manylinux2010_x86_64.whl (30.6 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp39-cp39-manylinux2014_aarch64.whl (31.9 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp39-cp39-win32.whl (14.3 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size MarkupSafe-2.0.1-cp39-cp39-win_amd64.whl (14.9 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size MarkupSafe-2.0.1.tar.gz (18.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page