UTIDYLIB(1) uTidylib UTIDYLIB(1)
NAME
utidylib - uTidylib Documentation
The Tidy wrapper.
I am the main interface to TidyLib. This package supports processing
HTML with Tidy, with all the options that the tidy command line
supports.
For more information on the tidy options, see the reference. These
options can be given as keyword arguments to parse and parseString, by
changing dashes (-) to underscores(_).
For example:
>>> import tidy
>>> from __future__ import print_function
>>> print(tidy.parseString(
... 'Hello Tidy!',
... output_xhtml=1, add_xml_decl=1, indent=1, tidy_mark=0,
... doctype='transitional'
... ))
Hello Tidy!
For options like newline and output_encoding, which must be set to one
of a fixed number of choices, you can provide either the numeric or
string version of the choice; so both
tidy.parseString('foo', newline=2) and
tidy.parseString('foo', newline='CR') do the same thing.
There are no plans to support other features of TidyLib, such as
document-tree traversal, since Python has several quality DOM
implementations. (The author uses Twisted's implementation,
twisted.web.microdom).
tidy.parse(filename: str, **kwargs: OPTION_TYPE) -> Document
Open and process filename as an HTML file.
Returning a processed document object.
Parameters
o kwargs -- named options to pass to TidyLib for
processing the input file.
o filename -- the name of a file to process
Returns
a Document object
tidy.parseString(text: bytes | str, **kwargs: OPTION_TYPE) -> Document
Use text as an HTML file.
Returning a processed document object.
Parameters
o kwargs -- named options to pass to TidyLib for
processing the input file.
o text -- the string to parse
Returns
a Document object
class tidy.Document(options: OPTION_DICT_TYPE)
Document object as returned by parseString() or parse().
get_errors() -> list[ReportItem]
Return list of errors as a list of ReportItem.
gettext() -> str
Unicode text for output returned by tidy.
getvalue() -> bytes
Raw string as returned by tidy.
write(stream: BinaryIO) -> None
Parameters
stream -- Writable file like object.
Writes document to the stream.
class tidy.ReportItem(err: str)
Error report item as returned by tidy.
col: int | None
Column where error was fired (can be None)
err: str
Whole error message as returned by tidy
full_severity: str
Full severity string
line: int | None
Line where error was fired (can be None)
message: str
Error message itself
severity: str
D, W, E or C indicating severity
exception tidy.TidyLibError
Generic Tidy exception.
exception tidy.InvalidOptionError
Exception for invalid option.
exception tidy.OptionArgError
Exception for invalid parameter.
To use uTidylib, you need to have HTML tidy library installed. Check
<> for instructions how to obtain it.
Once you have installed the library, install uTidylib:
pip install uTidylib
You are welcome to contribute on GitHub, we use it for source code
management, issue tracking and patches submission, see <>.
The testsuite can be exececuted using pytest:
pytest tidy
To build the doc, just run:
make -C docs html
This requires that you have Sphinx installed.
The API documentation will be built in the docs/_build/html/ directory.
The MIT License
Copyright (c) 2003 Cory Dodt <>
Copyright (c) 2014-2018 Michal Cihar <>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1.0.0
o Modernized packaging.
o Updated supported Python versions.
o Homebrew compatiblity.
0.10
o Dropped support for Python 3.7.
o Added support for Python 3.12.
o Added type hints.
o Improved documentation.
o Always call CleanAndRepair after parsing.
o Fixed handling char_encoding argument.
0.9
o Dropped support for Python 3.6.
o Added support for Python 3.10 and 3.11.
o Compatibility with html-tidy 5.8.0.
o Added support for specifying library full path using
TIDY_LIBRARY_FULL_PATH.
o Added getTidyVersion to get libtidy version.
0.8
o Code cleanups.
o Fixed typo in 0.7 release notes.
0.7
o Dropped support for Python 2.
0.6
o First official release PyPI.
0.5
o Fixed compatibility with Debian patched libtidy5deb1.
0.4
o Compatibility with html-tidy 5.6.0.
o Added support for Python 3.
0.3
o Initial release under new maintainer.
o Incorporated Debian patches.
o Various compatiblity fixes (eg. with 64-bit machines).
o Various code cleanups.
o New test suite.
o New documentation.
o Support for new HTML 5 tidy library.
This is fork of the original uTidylib with permission with original
author. Originally it incorporated patches from Debian and other
distributions, now it also brings compatibility with recent html-tidy
versions and works with Python 3.
The original source code is still available at .
o Index <>
o Module Index <>
o Search Page <>
Author
uTidylib contributors
Copyright
uTidylib contributors
1.0 January 9, 2026 UTIDYLIB(1)