Skip to main content

An easy whitelist-based HTML-sanitizing tool.

Project description

https://travis-ci.org/jsocol/bleach.png?branch=master https://badge.fury.io/py/Bleach.svg

Bleach is an HTML sanitizing library that escapes or strips markup and attributes based on a white list. Bleach can also linkify text safely, applying filters that Django’s urlize filter cannot, and optionally setting rel attributes, even on links already in the text.

Bleach is intended for sanitizing text from untrusted sources. If you find yourself jumping through hoops to allow your site administrators to do lots of things, you’re probably outside the use cases. Either trust those users, or don’t.

Because it relies on html5lib, Bleach is as good as modern browsers at dealing with weird, quirky HTML fragments. And any of Bleach’s methods will fix unbalanced or mis-nested tags.

The version on GitHub is the most up-to-date and contains the latest bug fixes. You can find full documentation on ReadTheDocs.

Reporting Bugs

For regular bugs, please report them in our issue tracker.

If you believe that you’ve found a security vulnerability, please file a secure bug report in our bug tracker or send an email to security AT mozilla DOT org.

For more information on security-related bug disclosure and the PGP key to use for sending encrypted mail or to verify responses received from that address, please read our wiki page at https://www.mozilla.org/en-US/security/#For_Developers.

Basic Use

The simplest way to use Bleach is:

>>> import bleach

>>> bleach.clean('an <script>evil()</script> example')
u'an &lt;script&gt;evil()&lt;/script&gt; example'

>>> bleach.linkify('an http://example.com url')
u'an <a href="http://example.com" rel="nofollow">http://example.com</a> url

NB: Bleach always returns a unicode object, whether you give it a bytestring or a unicode object, but Bleach does not attempt to detect incoming character encodings, and will assume UTF-8. If you are using a different character encoding, you should convert from a bytestring to unicode before passing the text to Bleach.

Installation

Bleach is available on PyPI, so you can install it with pip:

$ pip install bleach

Or with easy_install:

$ easy_install bleach

Or by cloning the repo from GitHub:

$ git clone git://github.com/jsocol/bleach.git

Then install it by running:

$ python setup.py install

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

bleach-1.4.2.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bleach-1.4.2-py2.py3-none-any.whl (22.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file bleach-1.4.2.tar.gz.

File metadata

  • Download URL: bleach-1.4.2.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bleach-1.4.2.tar.gz
Algorithm Hash digest
SHA256 56018a17d1488eb1a1e18e7cdddcaea24d3c7b3704172e356f6916c577f4fd9e
MD5 6a8f4d8afed000e2aea14c3aa02a1ea9
BLAKE2b-256 35dfa7918b1d41040aa281bb199432c233954366ca87b638a0f6740ece9f2ba8

See more details on using hashes here.

File details

Details for the file bleach-1.4.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for bleach-1.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 58a2c153c0b5450695c34ce2eddc23fb3ee476b31a878e6a5c24c75fd1ed4d89
MD5 e3e2eb8d5afd4deea0e2b142fab88ae7
BLAKE2b-256 9840b2fc4d7a22ca89e58c6bcda0bccfff5b61bfcc19a11f9d037df004316088

See more details on using hashes here.

Supported by

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