There is cgi.escape but that appears to be implemented in pure python.  It seems like most frameworks like Django also just run some regular expressions.  This is something we do a lot, so it would be good to have it be as fast as possible.
Maybe C implementations wouldn't be much faster than a series of regexes for this?
See lxml, which is based on libxml2. While it's primarily a XML library, HTML support is available.
Is there a good python module that does HTML encoding/escaping in C?