Skip to main content

domdrift

domdrift checks saved HTML and JSON responses against a structural contract and tells a scraper when it got a challenge page instead.

uvx domdrift diff yesterday.html today.html

Save a contract from a known-good response. Successful checks print nothing:

$ printf '<main><span class="price">$12</span></main>' > good.html
$ uvx domdrift init good.html --select 'price=main > .price' -o contract.json
$ uvx domdrift check -c contract.json good.html; echo $?
0
$ printf '<main><span class="sale-price">$10</span></main>' | uvx domdrift check -c contract.json --max-bytes 512 > repair.txt
$ echo $?
2
$ wc -c < repair.txt
256
$ cat repair.txt
DRIFT_DETECTED
violations: rule=price selector=main > .price reason=matched 0, need >= 1
survivors: selector=main count=1 broken=.price
candidates: selector=main > .sale-price count=1
candidates: selector=main > span count=1
  <main>
    <span.sale-price>
$ printf '<title>Just a moment...</title>' | uvx domdrift check -c contract.json
SOFT_BLOCK_DETECTED
Cloudflare: challenge page title. Keep existing selectors.
$ echo $?
3

For an MCP client that launches local stdio servers:

{
  "mcpServers": {
    "domdrift": { "command": "uvx", "args": ["domdrift", "mcp"] }
  }
}

domdrift_init takes baseline content or a public URL. Pass its contract to domdrift_check with the next response. domdrift_diff compares two content strings directly. Check and diff return status, exit_code and report.

Installation

Run without installing via uv:

uvx domdrift --version

Or install into a persistent environment:

uv tool install domdrift
# or
pip install domdrift

Requires Python 3.11+ and uses only the Python standard library (dependencies = []).

Contracts

init accepts a file path, an HTTP(S) URL or stdin. Without --select, it looks for landmarks, repeating HTML items and their fields, or infers JSON paths and types. Use --auto-landmarks to add automatic HTML rules to explicit selections.

uvx domdrift init catalog.json --select 'price=$.data.items[*].unit_price' -o catalog.contract
uvx domdrift check -c catalog.contract next.json --format json --max-bytes 1024

HTML rules support min_count, max_count, min_non_empty_ratio, required_attr and a Python regex pattern on the attribute or visible text. CSS supports groups, descendant, child and sibling combinators, attribute operators, :not, :has, :contains, and first/last/nth-child. The parser works on supplied markup; it does not execute JavaScript.

JSON paths start at $ and use .key and [*]. Inferred rules record types, nullability, field presence, non-empty ratios and minimum array sizes. A check permits value changes that satisfy those rules. A snapshot diff also reports inventory additions, removals, count changes, moves between HTML containers and type changes in optional JSON fields.

Exit codes and limits

Code Meaning
0 Contract holds, or no structural change in a diff.
1 Invalid arguments, contract or input, or a read error.
2 Structural drift. Inspect the surviving prefix, candidate and skeleton.
3 Likely challenge, access gate, rate limit or empty hydration shell. Keep the current selectors.

Reports default to 2048 UTF-8 bytes. --max-bytes accepts budgets of 256 bytes or more. JSON output stays valid when details are trimmed. Evidence uses structural labels and JSON types rather than body text or JSON scalar values. Keep contracts from trusted sources: selectors and regexes are executable checks on incoming documents.

Input reads are capped at 10 MiB. URL connections use a 15-second socket timeout and check public addresses on each redirect and connection. --allow-private-net permits local HTTP fixtures on the CLI. MCP URL inputs always require public HTTP(S) addresses.

From a source checkout, run uv run domdrift --help. Python 3.11 or newer is required; the installed package uses only the standard library.

Metadata

Release files for domdrift 0.1.0

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

Source distribution (sdist)

Source distribution for domdrift 0.1.0
File Size Uploaded Provenance Actions
domdrift-0.1.0.tar.gz 36.7 kB Without provenance Details for domdrift-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for domdrift 0.1.0
File Interpreter ABI Platform Actions
domdrift-0.1.0-py3-none-any.whl Python 3 none any Details for domdrift-0.1.0-py3-none-any.whl

Total release size: 64.7 kB

Release files / domdrift-0.1.0.tar.gz

Download URL domdrift-0.1.0.tar.gz
Size 36.7 kB
Tags Source
SHA-256 checksum
How to use checksums
382d86e397895ee4a0e81d4b84d6c00f98130855953fecb1d307942a62fba7a3
BLAKE2b-256 checksum
How to use checksums
3283fb3ca41e116f20f8c7b869b5ce47f70fc0a41ef0b76b50169aa5e51aae3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / domdrift-0.1.0-py3-none-any.whl

Download URL domdrift-0.1.0-py3-none-any.whl
Size 28.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56b74f9a9936f77cdde2d06042326afd0133a2a92b5ee8f50e2624d9c6bac2eb
BLAKE2b-256 checksum
How to use checksums
6678babd4d13d7eef100fae522ed3f350f76f24c3b76189bc5f5a79fdb3d71eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for domdrift 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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