UTIDYLIB(1)

πŸ“¦ version 1.1.0, in arch rolling

πŸ’– UTIDYLIB πŸ’–

okay so first things first: this is the utidylib(1) page from the uTidylib manual β€” the Tidy wrapper. buckle up bestie, it's giving "small library, big personality" πŸ’…

🌸 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. no cap, ALL of them 🫢

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 (_). yes literally just swap the dash for an underscore and you're so back πŸŽ€

For example:

>>> import tidy
>>> from __future__ import print_function
>>> print(tidy.parseString(
...     '<Html>Hello Tidy!',
...     output_xhtml=1, add_xml_decl=1, indent=1, tidy_mark=0,
...     doctype='transitional'
... ))
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
  </head>
  <body>
    Hello Tidy!
  </body>
</html>

iconic. look at that markup, it ate πŸ”₯

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('<HTML>foo</html>', newline=2) and tidy.parseString('<HTML>foo</html>', newline='CR') do the same thing. same vibe, different spelling, both valid πŸ’œ

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). so like, respectfully, that's not happening β€” go use a DOM, bestie 🌈


πŸ¦‹ THE API πŸ¦‹

lowkey the whole point of the page. here's the roster πŸ‘‘

⭐ tidy.parse

tidy.parse(filename: str, **kwargs: OPTION_TYPE) -> Document

Open and process filename as an HTML file. πŸ“

Returning a processed document object.

Parameters

  • kwargs β€” named options to pass to TidyLib for processing the input file.
  • filename β€” the name of a file to process

Returns

a Document object πŸ’«

⭐ tidy.parseString

tidy.parseString(text: bytes | str, **kwargs: OPTION_TYPE) -> Document

Use text as an HTML file. no file on disk required, we're doing this in memory 🧚

Returning a processed document object.

Parameters

  • kwargs β€” named options to pass to TidyLib for processing the input file.
  • text β€” the string to parse

Returns

a Document object πŸ’«

πŸ‘‘ class tidy.Document

class tidy.Document(options: OPTION_DICT_TYPE)

Document object as returned by parseString() or parse(). it's the little guy you get back 🎁

πŸ’… get_errors() -> list[ReportItem]

Return list of errors as a list of ReportItem. (yes, plural, a whole list, brace yourself)

πŸ’… 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

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

🚨 the exceptions (the villains)

  • exception tidy.TidyLibError β€” Generic Tidy exception.
  • exception tidy.InvalidOptionError β€” Exception for invalid option.
  • exception tidy.OptionArgError β€” Exception for invalid parameter.

πŸ› οΈ INSTALL & CONTRIBUTE πŸ› οΈ

To use uTidylib, you need to have HTML tidy library installed. Check http://www.html-tidy.org/ for instructions how to obtain it. prerequisites bestie, can't skip them πŸ™ˆ

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 https://github.com/nijel/utidylib. come hang out, we'd love to have you 🫢

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.


πŸ“œ LICENSE πŸ“œ

The MIT License

Copyright (c) 2003 Cory Dodt corydodt@twistedmatrix.com

Copyright (c) 2014-2026 Michal ČihaΕ™ michal@weblate.org

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.
yeah that's the whole thing, don't skip the fine print bestie, it's literally the license 😭

πŸ“¦ CHANGELOG πŸ“¦

the glow-up history, in order, we respect the timeline πŸ’€

πŸŽ€ 1.1.0

  • Added FreeBSD support for finding the Tidy library.
  • Added support for Python 3.15.

πŸŽ€ 1.0.0

  • Modernized packaging.
  • Updated supported Python versions.
  • Homebrew compatiblity.

πŸŽ€ 0.10

  • Dropped support for Python 3.7.
  • Added support for Python 3.12.
  • Added type hints.
  • Improved documentation.
  • Always call CleanAndRepair after parsing.
  • Fixed handling char_encoding argument.

πŸŽ€ 0.9

  • Dropped support for Python 3.6.
  • Added support for Python 3.10 and 3.11.
  • Compatibility with html-tidy 5.8.0.
  • Added support for specifying library full path using TIDY_LIBRARY_FULL_PATH.
  • Added getTidyVersion to get libtidy version.

πŸŽ€ 0.8

  • Code cleanups.
  • Fixed typo in 0.7 release notes.

πŸŽ€ 0.7

  • Dropped support for Python 2.

πŸŽ€ 0.6

  • First official release PyPI.

πŸŽ€ 0.5

  • Fixed compatibility with Debian patched libtidy5deb1.

πŸŽ€ 0.4

  • Compatibility with html-tidy 5.6.0.
  • Added support for Python 3.

πŸŽ€ 0.3

  • Initial release under new maintainer.
  • Incorporated Debian patches.
  • Various compatiblity fixes (eg. with 64-bit machines).
  • Various code cleanups.
  • New test suite.
  • New documentation.
  • Support for new HTML 5 tidy library.

🌱 ORIGIN STORY 🌱

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. main character energy, honestly πŸ‘‘

The original source code is still available at https://github.com/xdissent/utidylib/.

  • Index <>
  • Module Index <>
  • Search Page <>

Author

uTidylib contributors

Copyright

uTidylib contributors


ok that's the whole page πŸ’– go forth and tidy your HTML, you're gonna slay πŸ¦‹

later bestie!! this was uTidylib version 1.1 β€” 1.1.0, dated Oct 11, 2026, page UTIDYLIB(1), brought to you by the uTidylib contributors. mwah πŸ’‹

πŸ“¦ where this page comes from