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(u'&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 text subclass (str on Python 3, unicode on Python 2)
>>> # methods and operators escape their arguments
>>> template = Markup("Hello <em>%s</em>")
>>> template % '"World"'
Markup('Hello <em>&#34;World&#34;</em>')

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
MarkupSafe-1.1.0-cp27-cp27m-macosx_10_6_intel.whl (17.7 kB) Copy SHA256 hash SHA256 Wheel cp27
MarkupSafe-1.1.0-cp27-cp27m-manylinux1_i686.whl (24.3 kB) Copy SHA256 hash SHA256 Wheel cp27
MarkupSafe-1.1.0-cp27-cp27m-manylinux1_x86_64.whl (24.5 kB) Copy SHA256 hash SHA256 Wheel cp27
MarkupSafe-1.1.0-cp27-cp27mu-manylinux1_i686.whl (24.3 kB) Copy SHA256 hash SHA256 Wheel cp27
MarkupSafe-1.1.0-cp27-cp27mu-manylinux1_x86_64.whl (24.5 kB) Copy SHA256 hash SHA256 Wheel cp27
MarkupSafe-1.1.0-cp27-cp27m-win32.whl (14.4 kB) Copy SHA256 hash SHA256 Wheel cp27
MarkupSafe-1.1.0-cp27-cp27m-win_amd64.whl (14.2 kB) Copy SHA256 hash SHA256 Wheel cp27
MarkupSafe-1.1.0-cp34-cp34m-macosx_10_6_intel.whl (19.1 kB) Copy SHA256 hash SHA256 Wheel cp34
MarkupSafe-1.1.0-cp34-cp34m-manylinux1_i686.whl (27.1 kB) Copy SHA256 hash SHA256 Wheel cp34
MarkupSafe-1.1.0-cp34-cp34m-manylinux1_x86_64.whl (27.4 kB) Copy SHA256 hash SHA256 Wheel cp34
MarkupSafe-1.1.0-cp34-cp34m-win32.whl (14.8 kB) Copy SHA256 hash SHA256 Wheel cp34
MarkupSafe-1.1.0-cp34-cp34m-win_amd64.whl (14.7 kB) Copy SHA256 hash SHA256 Wheel cp34
MarkupSafe-1.1.0-cp35-cp35m-macosx_10_6_intel.whl (19.1 kB) Copy SHA256 hash SHA256 Wheel cp35
MarkupSafe-1.1.0-cp35-cp35m-manylinux1_i686.whl (27.3 kB) Copy SHA256 hash SHA256 Wheel cp35
MarkupSafe-1.1.0-cp35-cp35m-manylinux1_x86_64.whl (27.7 kB) Copy SHA256 hash SHA256 Wheel cp35
MarkupSafe-1.1.0-cp35-cp35m-win32.whl (16.1 kB) Copy SHA256 hash SHA256 Wheel cp35
MarkupSafe-1.1.0-cp35-cp35m-win_amd64.whl (16.8 kB) Copy SHA256 hash SHA256 Wheel cp35
MarkupSafe-1.1.0-cp36-cp36m-macosx_10_6_intel.whl (19.1 kB) Copy SHA256 hash SHA256 Wheel cp36
MarkupSafe-1.1.0-cp36-cp36m-manylinux1_i686.whl (27.3 kB) Copy SHA256 hash SHA256 Wheel cp36
MarkupSafe-1.1.0-cp36-cp36m-manylinux1_x86_64.whl (27.7 kB) Copy SHA256 hash SHA256 Wheel cp36
MarkupSafe-1.1.0-cp36-cp36m-win32.whl (16.1 kB) Copy SHA256 hash SHA256 Wheel cp36
MarkupSafe-1.1.0-cp36-cp36m-win_amd64.whl (16.8 kB) Copy SHA256 hash SHA256 Wheel cp36
MarkupSafe-1.1.0-cp37-cp37m-macosx_10_6_intel.whl (19.1 kB) Copy SHA256 hash SHA256 Wheel cp37
MarkupSafe-1.1.0-cp37-cp37m-manylinux1_i686.whl (27.3 kB) Copy SHA256 hash SHA256 Wheel cp37
MarkupSafe-1.1.0-cp37-cp37m-manylinux1_x86_64.whl (27.7 kB) Copy SHA256 hash SHA256 Wheel cp37
MarkupSafe-1.1.0-cp37-cp37m-win32.whl (16.1 kB) Copy SHA256 hash SHA256 Wheel cp37
MarkupSafe-1.1.0-cp37-cp37m-win_amd64.whl (16.8 kB) Copy SHA256 hash SHA256 Wheel cp37
MarkupSafe-1.1.0.tar.gz (18.9 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page