Bringing sanity to world of messed-up data
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Alireza Savand 01fbdccffb Update 5 years ago
sanitize Change version numbering 5 years ago
tests Add test_adding_nofollow 5 years ago
.gitignore Add a beautiful .gitignore 5 years ago
.travis.yml Fix a typo on coverage run script 5 years ago
AUTHORS.rst Add ``AUTHORS.rst`` file. 5 years ago
ChangeLog.rst Bump version number and make the package ready to fly! 5 years ago
LICENSE Rename COPYING to LICENSE 5 years ago Add ```` file. 5 years ago Update 5 years ago
requirements.txt Add egenix-mx-base 5 years ago
setup.cfg Add ``setup.cfg` for wheel support. 5 years ago Do not install tests 5 years ago


Build Status Coverage Status Downloads Version Format License

sanitize is a Python module for making sure various things (e.g. HTML) are safe to use. It was originally written by Mark Pilgrim and is distributed under the BSD license.


>>> from sanitize import HTML
>>> HTML('<b>hello')
>>> HTML('<img>')
'<img />'
>>> HTML(("<b><b><b>hello")
... )
>>> HTML('<img src="foo"/')
>>> HTML('<input type="checkbox" checked>')
'<input type="checkbox" checked="checked" />'
>>> # dangerous tags (a small sample)
>>> HTML('safe<applet code="foo.class" codebase=""></applet> <b>description</b>')
'safe <b>description</b>'
>>> HTML('safe<frameset rows="*"><frame src=""></frameset> <b>description</b>')
'safe <b>description</b>'
>>> # bad protocols (a small sample)
>>> HTML('<a href="java' + chr(1) + 'script:foo">bar</a>')
'<a href="#foo">bar</a>'
>>> HTML('<a href="vbscript:foo">bar</a>')
'<a href="#foo">bar</a>'

To see more usage examples see tests/


python-sanitize is available on pypi

So easily install it by pip:

pip install sanitize

Or by easy_install:

$ easy_install sanitize

Another way is by cloning python-sanitize’s git repository

$ git clone git://

Then install it by running

$ python install


To run unit tests:

$ python test


Sanitize is distributed under BSD license.