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.

Source Distribution

MarkupSafe-2.0.1.tar.gz (18.6 kB view hashes)

Uploaded Source

Built Distributions

MarkupSafe-2.0.1-cp310-cp310-win_amd64.whl (15.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

MarkupSafe-2.0.1-cp310-cp310-win32.whl (14.3 kB view hashes)

Uploaded CPython 3.10 Windows x86

MarkupSafe-2.0.1-cp310-cp310-musllinux_1_1_x86_64.whl (30.6 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

MarkupSafe-2.0.1-cp310-cp310-musllinux_1_1_i686.whl (30.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

MarkupSafe-2.0.1-cp310-cp310-musllinux_1_1_aarch64.whl (31.2 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ ARM64

MarkupSafe-2.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (26.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

MarkupSafe-2.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

MarkupSafe-2.0.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (30.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

MarkupSafe-2.0.1-cp310-cp310-macosx_10_9_x86_64.whl (14.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

MarkupSafe-2.0.1-cp310-cp310-macosx_10_9_universal2.whl (18.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

MarkupSafe-2.0.1-cp39-cp39-win_amd64.whl (14.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

MarkupSafe-2.0.1-cp39-cp39-win32.whl (14.3 kB view hashes)

Uploaded CPython 3.9 Windows x86

MarkupSafe-2.0.1-cp39-cp39-musllinux_1_1_x86_64.whl (30.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

MarkupSafe-2.0.1-cp39-cp39-musllinux_1_1_i686.whl (29.9 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

MarkupSafe-2.0.1-cp39-cp39-musllinux_1_1_aarch64.whl (31.0 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ ARM64

MarkupSafe-2.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (26.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

MarkupSafe-2.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

MarkupSafe-2.0.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (30.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

MarkupSafe-2.0.1-cp39-cp39-manylinux2014_aarch64.whl (31.9 kB view hashes)

Uploaded CPython 3.9

MarkupSafe-2.0.1-cp39-cp39-manylinux2010_x86_64.whl (30.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

MarkupSafe-2.0.1-cp39-cp39-manylinux2010_i686.whl (30.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

MarkupSafe-2.0.1-cp39-cp39-manylinux1_x86_64.whl (30.6 kB view hashes)

Uploaded CPython 3.9

MarkupSafe-2.0.1-cp39-cp39-manylinux1_i686.whl (30.2 kB view hashes)

Uploaded CPython 3.9

MarkupSafe-2.0.1-cp39-cp39-macosx_10_9_x86_64.whl (14.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

MarkupSafe-2.0.1-cp39-cp39-macosx_10_9_universal2.whl (18.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

MarkupSafe-2.0.1-cp38-cp38-win_amd64.whl (14.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

MarkupSafe-2.0.1-cp38-cp38-win32.whl (14.3 kB view hashes)

Uploaded CPython 3.8 Windows x86

MarkupSafe-2.0.1-cp38-cp38-musllinux_1_1_x86_64.whl (30.4 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

MarkupSafe-2.0.1-cp38-cp38-musllinux_1_1_i686.whl (30.0 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

MarkupSafe-2.0.1-cp38-cp38-musllinux_1_1_aarch64.whl (31.0 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ ARM64

MarkupSafe-2.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (27.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

MarkupSafe-2.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

MarkupSafe-2.0.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (30.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

MarkupSafe-2.0.1-cp38-cp38-manylinux2014_aarch64.whl (31.9 kB view hashes)

Uploaded CPython 3.8

MarkupSafe-2.0.1-cp38-cp38-manylinux2010_x86_64.whl (30.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

MarkupSafe-2.0.1-cp38-cp38-manylinux2010_i686.whl (30.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

MarkupSafe-2.0.1-cp38-cp38-manylinux1_x86_64.whl (30.6 kB view hashes)

Uploaded CPython 3.8

MarkupSafe-2.0.1-cp38-cp38-manylinux1_i686.whl (30.2 kB view hashes)

Uploaded CPython 3.8

MarkupSafe-2.0.1-cp38-cp38-macosx_10_9_x86_64.whl (14.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

MarkupSafe-2.0.1-cp38-cp38-macosx_10_9_universal2.whl (18.3 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

MarkupSafe-2.0.1-cp37-cp37m-win_amd64.whl (14.9 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

MarkupSafe-2.0.1-cp37-cp37m-win32.whl (14.3 kB view hashes)

Uploaded CPython 3.7m Windows x86

MarkupSafe-2.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl (30.8 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

MarkupSafe-2.0.1-cp37-cp37m-musllinux_1_1_i686.whl (30.5 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

MarkupSafe-2.0.1-cp37-cp37m-musllinux_1_1_aarch64.whl (31.4 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ ARM64

MarkupSafe-2.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (26.5 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

MarkupSafe-2.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (31.2 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

MarkupSafe-2.0.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (30.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

MarkupSafe-2.0.1-cp37-cp37m-manylinux2014_aarch64.whl (32.3 kB view hashes)

Uploaded CPython 3.7m

MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_x86_64.whl (31.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_i686.whl (30.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

MarkupSafe-2.0.1-cp37-cp37m-manylinux1_x86_64.whl (31.1 kB view hashes)

Uploaded CPython 3.7m

MarkupSafe-2.0.1-cp37-cp37m-manylinux1_i686.whl (30.7 kB view hashes)

Uploaded CPython 3.7m

MarkupSafe-2.0.1-cp37-cp37m-macosx_10_9_x86_64.whl (13.9 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

MarkupSafe-2.0.1-cp36-cp36m-win_amd64.whl (14.9 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

MarkupSafe-2.0.1-cp36-cp36m-win32.whl (14.3 kB view hashes)

Uploaded CPython 3.6m Windows x86

MarkupSafe-2.0.1-cp36-cp36m-musllinux_1_1_x86_64.whl (29.9 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

MarkupSafe-2.0.1-cp36-cp36m-musllinux_1_1_i686.whl (29.6 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ i686

MarkupSafe-2.0.1-cp36-cp36m-musllinux_1_1_aarch64.whl (30.5 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ ARM64

MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (26.5 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

MarkupSafe-2.0.1-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_12_i686.manylinux2010_i686.whl (29.9 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686 manylinux: glibc 2.5+ i686

MarkupSafe-2.0.1-cp36-cp36m-manylinux2014_aarch64.whl (31.4 kB view hashes)

Uploaded CPython 3.6m

MarkupSafe-2.0.1-cp36-cp36m-manylinux2010_x86_64.whl (30.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

MarkupSafe-2.0.1-cp36-cp36m-manylinux2010_i686.whl (29.9 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

MarkupSafe-2.0.1-cp36-cp36m-manylinux1_x86_64.whl (30.2 kB view hashes)

Uploaded CPython 3.6m

MarkupSafe-2.0.1-cp36-cp36m-manylinux1_i686.whl (29.9 kB view hashes)

Uploaded CPython 3.6m

MarkupSafe-2.0.1-cp36-cp36m-macosx_10_9_x86_64.whl (13.9 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page