.\" Man page generated from reStructuredText
.\" by the Docutils 0.22.3 manpage writer.
.
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "UTIDYLIB" "1" "Jan 09, 2026" "1.0" "uTidylib"
.SH NAME
utidylib \- uTidylib Documentation
.sp
The Tidy wrapper.
.sp
I am the main interface to TidyLib. This package supports processing HTML with
Tidy, with all the options that the tidy command line supports.
.sp
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(_).
.sp
For example:
.sp
.EX
>>> import tidy
>>> from __future__ import print_function
>>> print(tidy.parseString(
\&... \(aqHello Tidy!\(aq,
\&... output_xhtml=1, add_xml_decl=1, indent=1, tidy_mark=0,
\&... doctype=\(aqtransitional\(aq
\&... ))
Hello Tidy!
.EE
.sp
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(\(aqfoo\(aq, newline=2) and
tidy.parseString(\(aqfoo\(aq, newline=\(aqCR\(aq) do the same thing.
.sp
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\(aqs implementation, twisted.web.microdom).
.INDENT 0.0
.TP
.B tidy.parse(filename: str, **kwargs: OPTION_TYPE) -> Document
Open and process filename as an HTML file.
.sp
Returning a processed document object.
.INDENT 7.0
.TP
.B Parameters
.INDENT 7.0
.IP \(bu 2
\fBkwargs\fP \-\- named options to pass to TidyLib for processing the
input file.
.IP \(bu 2
\fBfilename\fP \-\- the name of a file to process
.UNINDENT
.TP
.B Returns
a \fBDocument\fP object
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B tidy.parseString(text: bytes | str, **kwargs: OPTION_TYPE) -> Document
Use text as an HTML file.
.sp
Returning a processed document object.
.INDENT 7.0
.TP
.B Parameters
.INDENT 7.0
.IP \(bu 2
\fBkwargs\fP \-\- named options to pass to TidyLib for processing the
input file.
.IP \(bu 2
\fBtext\fP \-\- the string to parse
.UNINDENT
.TP
.B Returns
a \fBDocument\fP object
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B class tidy.Document(options: OPTION_DICT_TYPE)
Document object as returned by \fBparseString()\fP or \fBparse()\fP\&.
.INDENT 7.0
.TP
.B get_errors() -> list[ReportItem]
Return list of errors as a list of \fBReportItem\fP\&.
.UNINDENT
.INDENT 7.0
.TP
.B gettext() -> str
Unicode text for output returned by tidy.
.UNINDENT
.INDENT 7.0
.TP
.B getvalue() -> bytes
Raw string as returned by tidy.
.UNINDENT
.INDENT 7.0
.TP
.B write(stream: BinaryIO) -> None
.INDENT 7.0
.TP
.B Parameters
\fBstream\fP \-\- Writable file like object.
.UNINDENT
.sp
Writes document to the stream.
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B class tidy.ReportItem(err: str)
Error report item as returned by tidy.
.INDENT 7.0
.TP
.B col: int | None
Column where error was fired (can be None)
.UNINDENT
.INDENT 7.0
.TP
.B err: str
Whole error message as returned by tidy
.UNINDENT
.INDENT 7.0
.TP
.B full_severity: str
Full severity string
.UNINDENT
.INDENT 7.0
.TP
.B line: int | None
Line where error was fired (can be None)
.UNINDENT
.INDENT 7.0
.TP
.B message: str
Error message itself
.UNINDENT
.INDENT 7.0
.TP
.B severity: str
D, W, E or C indicating severity
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B exception tidy.TidyLibError
Generic Tidy exception.
.UNINDENT
.INDENT 0.0
.TP
.B exception tidy.InvalidOptionError
Exception for invalid option.
.UNINDENT
.INDENT 0.0
.TP
.B exception tidy.OptionArgError
Exception for invalid parameter.
.UNINDENT
.sp
To use uTidylib, you need to have HTML tidy library installed.
Check <\%> for instructions how to obtain it.
.sp
Once you have installed the library, install uTidylib:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
pip install uTidylib
.EE
.UNINDENT
.UNINDENT
.sp
You are welcome to contribute on GitHub, we use it for source code management,
issue tracking and patches submission, see <\%>.
.sp
The testsuite can be exececuted using pytest:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
pytest tidy
.EE
.UNINDENT
.UNINDENT
.sp
To build the doc, just run:
.INDENT 0.0
.INDENT 3.5
.sp
.EX
make \-C docs html
.EE
.UNINDENT
.UNINDENT
.sp
This requires that you have Sphinx installed.
.sp
The API documentation will be built in the \fBdocs/_build/html/\fP directory.
.sp
The MIT License
.sp
Copyright (c) 2003 Cory Dodt <\%>
.sp
Copyright (c) 2014\-2018 Michal Čihař <\%>
.sp
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
\(dqSoftware\(dq), 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:
.sp
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
.sp
THE SOFTWARE IS PROVIDED \(dqAS IS\(dq, 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.
.SH 1.0.0
.INDENT 0.0
.IP \(bu 2
Modernized packaging.
.IP \(bu 2
Updated supported Python versions.
.IP \(bu 2
Homebrew compatiblity.
.UNINDENT
.SH 0.10
.INDENT 0.0
.IP \(bu 2
Dropped support for Python 3.7.
.IP \(bu 2
Added support for Python 3.12.
.IP \(bu 2
Added type hints.
.IP \(bu 2
Improved documentation.
.IP \(bu 2
Always call CleanAndRepair after parsing.
.IP \(bu 2
Fixed handling char_encoding argument.
.UNINDENT
.SH 0.9
.INDENT 0.0
.IP \(bu 2
Dropped support for Python 3.6.
.IP \(bu 2
Added support for Python 3.10 and 3.11.
.IP \(bu 2
Compatibility with html\-tidy 5.8.0.
.IP \(bu 2
Added support for specifying library full path using TIDY_LIBRARY_FULL_PATH.
.IP \(bu 2
Added getTidyVersion to get libtidy version.
.UNINDENT
.SH 0.8
.INDENT 0.0
.IP \(bu 2
Code cleanups.
.IP \(bu 2
Fixed typo in 0.7 release notes.
.UNINDENT
.SH 0.7
.INDENT 0.0
.IP \(bu 2
Dropped support for Python 2.
.UNINDENT
.SH 0.6
.INDENT 0.0
.IP \(bu 2
First official release PyPI.
.UNINDENT
.SH 0.5
.INDENT 0.0
.IP \(bu 2
Fixed compatibility with Debian patched libtidy5deb1.
.UNINDENT
.SH 0.4
.INDENT 0.0
.IP \(bu 2
Compatibility with html\-tidy 5.6.0.
.IP \(bu 2
Added support for Python 3.
.UNINDENT
.SH 0.3
.INDENT 0.0
.IP \(bu 2
Initial release under new maintainer.
.IP \(bu 2
Incorporated Debian patches.
.IP \(bu 2
Various compatiblity fixes (eg. with 64\-bit machines).
.IP \(bu 2
Various code cleanups.
.IP \(bu 2
New test suite.
.IP \(bu 2
New documentation.
.IP \(bu 2
Support for new HTML 5 tidy library.
.UNINDENT
.sp
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.
.sp
The original source code is still available at \%\&.
.INDENT 0.0
.IP \(bu 2
Index \%<>
.IP \(bu 2
Module Index \%<>
.IP \(bu 2
Search Page \%<>
.UNINDENT
.SH Author
uTidylib contributors
.SH Copyright
uTidylib contributors
.\" End of generated man page.