I've written an HTML minification library that's ready for release.
pip install htmlmin should get you going.
This site is statically generated via pelican and I noticed that the content generated by it was not as compact as it could be. I started looking into existing HTML minification solutions and was left disappointed. I found one, django-htmlmin that left me disappointed - it relies on Beautiful Soup, Django, and other libraries, which in turn have lots of other, non-HTML dependencies such as MySQL. Furthermore, it isn't really that featureful or well designed, as I looked through the code.
htmlmin has no dependencies other than Python's builtin HTMLParser. It has features that allow you to fine tune how the HTML gets minified and allows you to easily mark up your HTML inline to demarcate non-minifieable areas. It follows the HTML 5 specification closely to account for non-closed tags.
There's still a few more features that I want to add. Specifically, I want to add a feature that allows removal of opening and closing tags where allowed by the HTML5 specification. I also want it to recognize
whitespace: pre inside of inline style tags. Those will come in the next version of the software as I design tests for them.