Skip to main content

htmlcompare

A Python library to ensure two HTML documents are "equal". Currently the functionality is very limited but the idea is that the library should ignore differences automatically when these are not relevant for HTML semantics (e.g. <img style=""> should be the same as <img>.

Usage

import htmlcompare

diff = htmlcompare.compare('<div>', '<p>')
is_same = bool(diff)

To ease testing the library provides some helpers

from htmlcompare import assert_different_html, assert_same_html

assert_different_html('<br>', '<p>')
assert_same_html('<div />', '<div></div>')

Limitations / Plans

CSS is currently not validated. Later I hope to add CSS parsing using a real CSS parser like tinycss2 but right now the only support for CSS is that contents of <style> tags is completely ignored and that trailing ;s in style attributes are stripped.

No validation of conditional comments. Not sure which library I can use here but at some point I'll likely need this as well.

JavaScript - for obvious reasons it will be impossible to implement perfect JS comparison but it might be possible to run some kind of "beautifier" to take care of insignificant stylistic changes. However I don't need this feature so this is unlikely to get implemented (unless contributed by someone else).

Custom hooks could help adapting the comparison to your specific needs. However I don't know which API would be best so this will wait until there are real-world use cases.

Better API: The current API is very minimal and implements just what I needed right now. I hope to improve the API once I use this project in more complex scenarios.

Other projects

xmldiff is a well established project to compare two XML documents. However it seems as if the code does not contain knowledge about specific HTML semantics (e.g. CSS, empty attributes, insignificant attribute order).

Misc

The code is licensed under the MIT license. It supports Python 2.7 and Python 3.4+.

Metadata

Release files for HTMLCompare 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for HTMLCompare 0.2.1
File Size Uploaded Provenance Actions
HTMLCompare-0.2.1.tar.gz 5.7 kB Without provenance Details for HTMLCompare-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for HTMLCompare 0.2.1
File Interpreter ABI Platform Actions
HTMLCompare-0.2.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for HTMLCompare-0.2.1-py2.py3-none-any.whl

Total release size: 13.3 kB

Release files / HTMLCompare-0.2.1.tar.gz

Download URL HTMLCompare-0.2.1.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2478dad790276f1aac9e0f334310a22e7bff1672f84fd2e9f1981121cd2f2e3a
BLAKE2b-256 checksum
How to use checksums
2624517866f8fbdaaca259497baa380cab74feadfdb3b8afd0cb8347355bc3d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.8

Release files / HTMLCompare-0.2.1-py2.py3-none-any.whl

Download URL HTMLCompare-0.2.1-py2.py3-none-any.whl
Size 7.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8fa572c700f4fc2e279b367369ff0f7a2358656a987f483fc643d897e4809a03
BLAKE2b-256 checksum
How to use checksums
13fab658ee915a2d730ac4e887a4b098f59a8b15e92e0a57acc555384e1337de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.8

Security for HTMLCompare 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page