Skip to main content

LLM-optimized HTML cleaning: hydration extraction, token budgets, multiple output formats

Project description

llm-html

CMDOP Skill — install and use via CMDOP agent:

cmdop-skill install llm-html

LLM-optimized HTML cleaning: hydration extraction, token budgets, multiple output formats.

Install

pip install llm-html

Quick Start

from llm_html import HTMLCleaner, CleanerConfig, OutputFormat

# Basic cleaning
cleaner = HTMLCleaner()
result = cleaner.clean(html)
print(f"Reduction: {result.stats.reduction_percent}%")

# Hydration-first (extracts SSR data from Next.js, Nuxt, etc.)
if result.hydration_data:
    data = result.hydration_data
else:
    cleaned = result.html

Convenience Functions

from llm_html import clean, clean_to_json, clean_html, clean_for_llm

# Quick clean
result = clean(html)

# Get JSON if SSR data available, otherwise cleaned HTML
data = clean_to_json(html)

# Pipeline with full control
result = clean_html(html, max_tokens=5000)
result = clean_for_llm(html, output_format="markdown")

Output Formats

from llm_html import to_markdown, to_aom_yaml, to_xtree

md = to_markdown(html)
aom = to_aom_yaml(html)
xtree = to_xtree(html)

Downsampling

Token-budget targeting with D2Snap algorithm:

from llm_html import downsample_html, estimate_tokens

tokens = estimate_tokens(html)
if tokens > 10000:
    html = downsample_html(html, target_tokens=8000)

Semantic Chunking

Split large pages into LLM-sized chunks:

from llm_html import SemanticChunker, ChunkConfig

config = ChunkConfig(max_tokens=8000, max_items=20)
chunker = SemanticChunker(config)
result = chunker.chunk(soup)
for chunk in result.chunks:
    process(chunk.html)

Shadow DOM

Flatten Web Components for LLM visibility:

from llm_html import flatten_shadow_dom

flat = flatten_shadow_dom(html)

Helpers

from llm_html import html_to_text, extract_links, extract_images, json_to_toon

text = html_to_text(html)
links = extract_links(html, base_url="https://example.com")
images = extract_images(html)
toon = json_to_toon({"key": "value"})

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_html-0.1.7.tar.gz (53.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_html-0.1.7-py3-none-any.whl (70.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_html-0.1.7.tar.gz.

File metadata

  • Download URL: llm_html-0.1.7.tar.gz
  • Upload date:
  • Size: 53.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for llm_html-0.1.7.tar.gz
Algorithm Hash digest
SHA256 dea8d3784bc53690ed6d5c72da8e2faf1a3508718cf4aeca60d31d2fc41f59aa
MD5 4635b1da8fada488ea285136cb079886
BLAKE2b-256 55eec5ebdf07ae927dba0e7a113b7800fd1f0d7337122eaf6252ffa477262d8a

See more details on using hashes here.

File details

Details for the file llm_html-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: llm_html-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 70.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for llm_html-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 989b53f9e6d4cdf53740128cf0a002f73e15e61568e8dd13dc7f47e162e79846
MD5 76ca8a4ac327c863eee9a8398bfbae01
BLAKE2b-256 ed4ef2f67f7ad78a174c18288d7c12f5ec2b8d75a16b7ec7d77e806f43e14422

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page