Bleach 1.0rc2

Bleach is very nearly ready for a 1.0!

After I announced Bleach 1.0rc1, a couple of important issues were found. Those have now been fixed. (Thanks, guys!) One of these was backported to 0.5, and I uploaded 0.5.1 to PyPI yesterday.

If you use Bleach, please try out the new version. You can get it from Github and install with pip.

Upgrade Path

Bleach 1.0 drops the Bleach class. 0.5.x is intended as a stepping stone that will let you start using the new API.

# Bleach <= 0.5
  1. from bleach import Bleach
  2. b = Bleach()
  3. b.clean()
  5. # Bleach >= 0.5
  6. import bleach
  7. bleach.clean()

Hopefully this change will be minor unless you were using URL filters on linkify(). In that case, the change is:

# Bleach <= 0.5
  1. from bleach import Bleach
  2. class MyBleach(Bleach):
  3.     def filter_url(self, url):
  4.         return’
  5. b = MyBleach()
  6. b.linkify(‘a link to’)
  8. # Bleach >= 0.5
  9. import bleach
  10. def filter_url(url):
  11.     return’
  12. bleach.linkify(‘a link to’, filterurl=filterurl)

This is a bigger change, but I hope it won’t be too bad for users, and I think it makes the whole API much more consistent. Lots of kwargs, yes, but more consistent and logical.


Bleach 1.0 doesn’t have much in the way of new features, instead focusing on clean up, improving test coverage and security, and being ready to call it a 1.0. It does have the following changes over 0.5:

  • A skip_pre option for linkify() to ignore URLs in <pre> sections.
  • Drops support for nofollow_relative. I still think that’s a good option but it needs work.

So please, check out Bleach. I’d love feedback on the new direction. Feel free to comment or open issues.