htmldiff2 is a library that uses difflib, genshi and html5lib to diff arbitrary fragments of HTML inline. htmldiff2 is a friendly fork of Armin Ronacher's htmldiff which needed to be upgraded for the diffengine project. See this issue for context.
>>> from htmldiff2 import render_html_diff
>>> render_html_diff('Foo <b>bar</b> baz', 'Foo <i>bar</i> baz')
u'<div class="diff">Foo <i class="tagdiff_replaced">bar</i> baz</div>'
>>> render_html_diff('Foo bar baz', 'Foo baz')
u'<div class="diff">Foo <del>bar</del> baz</div>'
>>> render_html_diff('Foo baz', 'Foo blah baz')
u'<div class="diff">Foo <ins>blah</ins> baz</div>'
python -mvenv .venv
source .venv/bin/activate
python -m pip install -e .
python test.py
python -m pip install setuptools build twine
python -m build
python -m twine upload dist/*