justhtml 3.11.2


pip install justhtml

  Latest version

Released: Aug 27, 2026

Project Links

Meta
Author: Emil Stenström
Requires Python: >=3.10

Classifiers

License
  • OSI Approved :: MIT License

Operating System
  • OS Independent

Programming Language
  • Python :: 3

JustHTML

HTML from the real web is messy. It is often malformed, user supplied, scraped from unknown pages, or headed for a browser where small parsing differences can become security bugs.

JustHTML gives Python projects one small dependency for the common HTML jobs:

  • parse HTML like a browser, including broken markup
  • sanitize untrusted HTML by default
  • query with CSS selectors
  • transform, serialize, extract text, or convert to Markdown
  • run anywhere Python runs, with no C extension and no system package to install
pip install justhtml

Requires Python 3.10 or later.

Documentation | Comparison | Playground | Security policy

JustHTML turns messy unsafe HTML into a sanitized, queryable DOM, then serializes it to text, Markdown, or HTML.

Why Use It?

Most Python HTML libraries optimize for one part of the problem.

html.parser is built in, but not HTML5-correct. BeautifulSoup is convenient, but depends heavily on the parser underneath. lxml and C/Rust-backed parsers are fast, but usually leave sanitization as a separate concern. html5lib and Bleach shaped the Python ecosystem, but both are no longer the obvious foundation for new projects.

JustHTML is for applications that want a boring, inspectable, pure-Python default:

  • Correct parsing: browser-style HTML5 recovery, tested against the web platform html5 treebuilder tests.
  • Safe by default: JustHTML(html) sanitizes before you query or serialize.
  • One DOM: parse once, then sanitize, query, transform, serialize, extract text, or produce Markdown.
  • Easy deployment: zero runtime dependencies, no compiler, works on PyPy and Pyodide.
  • Honest tradeoff: if you are parsing terabytes of trusted HTML, use a C/Rust parser. If you need reliable handling of untrusted or malformed HTML inside a Python app, use JustHTML.

Real-world signal: Mozilla Support migrated from Bleach to JustHTML in Kitsune, the Django application behind support.mozilla.org.

Quick Start

from justhtml import JustHTML

doc = JustHTML(
    "<p>Hello<script>alert(1)</script> "
    "<a href='javascript:alert(1)'>bad</a> "
    "<a href='https://example.com'>ok</a></p>",
    fragment=True,
)

print(doc.to_html(pretty=False))
# => <p>Hello <a>bad</a> <a href="https://example.com">ok</a></p>

Sanitization is enabled by default. Disable it only for trusted input:

doc = JustHTML("<main><p class='intro'>Hello</p></main>", sanitize=False)
intro = doc.query_one("p.intro")

print(intro.to_text())
# => Hello

What You Can Do

from justhtml import JustHTML, Linkify, SetAttrs, Unwrap

doc = JustHTML(
    "<p>Hello <span>world</span> example.com</p>",
    fragment=True,
    sanitize=False,
    transforms=[
        Unwrap("span"),
        Linkify(),
        SetAttrs("a", rel="nofollow"),
    ],
)

print(doc.to_html(pretty=False))
# => <p>Hello world <a href="http://example.com" rel="nofollow">example.com</a></p>

JustHTML includes:

Command Line

# Pretty-print an HTML file
justhtml index.html

# Parse from stdin
curl -s https://example.com | justhtml -

# Extract text from selected nodes
justhtml index.html --selector "main p" --format text

# Convert selected HTML to Markdown
justhtml index.html --selector "article" --format markdown

Correctness

JustHTML is tested against the web platform html5 treebuilder tests, plus html5lib serializer/encoding fixtures and project-specific sanitizer, selector, transform, CLI, and regression tests.

The current test suite enforces 100% combined line and branch coverage, including the parser engine. The parser engine additionally requires exact agreement with the reference path across the web platform html5 treebuilder suite. See Correctness Testing for details.

Documentation

Security

JustHTML sanitizes by default, but output safety still depends on where you put it. HTML body output is not automatically safe inside JavaScript, CSS, URL attributes, or other contexts.

For the supported-version policy and vulnerability reporting, see SECURITY.md.

License

MIT. Free to use for commercial and non-commercial projects.

3.11.2 Aug 27, 2026
3.11.1 Aug 16, 2026
3.11.0 Aug 06, 2026
3.10.1 Jul 25, 2026
3.10.0 Jul 25, 2026
3.9.0 Jul 20, 2026
3.8.0 Jul 19, 2026
3.7.0 Jul 15, 2026
3.6.1 Jul 13, 2026
3.6.0 Jul 13, 2026
3.5.0 Jul 12, 2026
3.4.0 Jul 11, 2026
3.3.0 Jul 04, 2026
3.2.0 Jul 04, 2026
3.1.0 Jul 02, 2026
3.0.0 Jun 21, 2026
2.4.1 Jun 21, 2026
2.4.0 Jun 20, 2026
2.3.0 Jun 12, 2026
2.2.0 Jun 07, 2026
2.1.0 Jun 06, 2026
2.0.0 May 24, 2026
1.23.0 May 24, 2026
1.22.0 May 22, 2026
1.21.0 May 15, 2026
1.20.0 May 14, 2026
1.19.0 May 09, 2026
1.18.0 May 04, 2026
1.17.0 Apr 19, 2026
1.16.0 Apr 12, 2026
1.15.0 Apr 09, 2026
1.14.0 Apr 05, 2026
1.13.0 Mar 21, 2026
1.12.0 Mar 17, 2026
1.11.0 Mar 15, 2026
1.10.0 Mar 15, 2026
1.9.1 Mar 10, 2026
1.9.0 Mar 08, 2026
1.8.0 Mar 05, 2026
1.7.0 Feb 08, 2026
1.6.0 Feb 06, 2026
1.5.0 Feb 01, 2026
1.4.0 Jan 29, 2026
1.3.0 Jan 28, 2026
1.2.0 Jan 25, 2026
1.1.0 Jan 24, 2026
1.0.0 Jan 20, 2026
0.40.0 Jan 19, 2026
0.39.0 Jan 18, 2026
0.38.0 Jan 18, 2026
0.37.0 Jan 18, 2026
0.36.0 Jan 17, 2026
0.35.0 Jan 11, 2026
0.34.0 Jan 10, 2026
0.33.0 Jan 10, 2026
0.32.0 Jan 10, 2026
0.31.0 Jan 09, 2026
0.30.0 Jan 03, 2026
0.29.0 Jan 03, 2026
0.28.0 Jan 03, 2026
0.27.0 Jan 03, 2026
0.26.0 Jan 02, 2026
0.25.0 Jan 01, 2026
0.24.0 Jan 01, 2026
0.23.0 Dec 30, 2025
0.22.0 Dec 28, 2025
0.21.0 Dec 28, 2025
0.20.0 Dec 28, 2025
0.19.0 Dec 28, 2025
0.18.0 Dec 21, 2025
0.17.0 Dec 20, 2025
0.16.0 Dec 18, 2025
0.15.0 Dec 18, 2025
0.14.0 Dec 17, 2025
0.13.1 Dec 17, 2025
0.13.0 Dec 16, 2025
0.12.0 Dec 15, 2025
0.11.0 Dec 15, 2025
0.10.0 Dec 14, 2025
0.9.0 Dec 14, 2025
0.8.0 Dec 13, 2025
0.7.0 Dec 13, 2025
0.6.0 Dec 07, 2025
0.5.2 Dec 07, 2025
0.5.1 Dec 07, 2025
0.5.0 Dec 07, 2025
0.4.0 Dec 06, 2025
0.3.0 Dec 01, 2025
0.2.0 Dec 01, 2025
0.1.0 Nov 30, 2025

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies: