from slimmer import html_slimmer
try:
    html = htmlmin.minify(html, remove_comments=True, remove_empty_space=True)
except:
    html = html_slimmer(html.strip().replace('\n', ' ').replace('\t', ' ').
        replace('\r', ' '))
Compress(minimize) HTML from python