I love tidy. I need tidy. What I really really want is a simple wrapper around tidy that will let me use it through Python.

It's not that the current set of wrappers are bad, it's just that they didn't meet my target requirements. What are my target requirements?

  1. Easy to build, well not necessarily easy, but not a lot of dependecies, nothing beyond Python, TidyLib, and maybe SWIG.
  2. Easy to install (either a good 'make install', or just a couple files to copy into my project.)
  3. Easy to call, this is what I want my end Python to look like:

    import pytidy

    xhtml = pytidy.fix("just same <b>malformed HTML<br/> stuff")

That's it, just a single fucntion that takes in poor markup and then returns well-formed XHTML as output.

Introducing pyTidy

Download pyTidy, a simple Python wrapper of TidyLib that has just the minimal interface described above.

Build Instructions:

  1. Install SWIG
  2. Install Tidy
  3. Edit the variables at the top of the Makefile to reflect your current environment.
    Set to the 'Examples' directory of your SWIG installation.
    Change to point to the include directory for your TidyLib install.
    Change to the full path of libtidy.a (libtidy.lib on Windows).
  4. Type 'make' to build. This will build two files:

    pytidy.so (or _pytidy.dll on Windows) and pytidy.py

    Copy both of these files into your project, or the right location in your Python libraries.

Release Notes

Version 0.1 - Initial Release. Currently untested on Windows.


Yes, I would like to automate this whole process using distutils, but that will have to wait for a later release.

How about this: http://www.lemburg.com/files/python/mxTidy.html ? It "works for me"(tm).

Posted by John Beimler on 2003-11-22

  I had avoided mxTidy as it looked like it was a fork of the original command line only Tidy.

Posted by Joe on 2003-11-26

Is it possible to pass options to Tidy? How?

Posted by Yay on 2003-12-05

  No, as of right now it is a single function that is hard coded to convert HTML into XHTML. If you'd like to extend the current binding to allow for options please feel free to do so. I'll also accept patches for a future release.

Posted by Joe on 2003-12-05

There is also


Which uses ctypes, so it's dead easy to use on windows.

Posted by icepick on 2004-04-16

Alternatively, just open a pipe to a tidy process.  This is a lot simpler.

Posted by doug ransom on 2004-07-01

i need help converting any html to well formed xml in a server side .NET script.

can u help me? or direct me to a place where i can find what i am looking for?

thanks in advance,


Posted by daniel bar on 2004-12-22