MGraph AI Service Html Graph
A powerful service that transforms HTML documents into graph representations for visualization, analysis, and manipulation. Built on the MGraph AI framework.
Overview
HTML Document ──────► Graph Representation ──────► Visual Output
<html> ┌─────────────┐ ┌─────────────┐
<body> ──► │ Nodes │ ──► │ DOT │
<div> │ Edges │ │ D3 │
</body> │ Clusters │ │ Cytoscape │
</html> └─────────────┘ │ VisJs │
│ Mermaid │
│ Tree │
└─────────────┘
The Html Graph Service converts any HTML into a multi-graph model where different aspects of the document (DOM structure, attributes, scripts, styles) are represented as interconnected graphs that can be visualized using multiple rendering engines.
Features
| Feature | Description |
|---|---|
| Multi-Graph Model | 5 interconnected graphs: Body, Head, Attributes, Scripts, Styles |
| 6 Rendering Engines | DOT (Graphviz), D3, Cytoscape, VisJs, Mermaid, Tree |
| 8 Transformations | Default, Attributes View, Full Document, Head, Scripts, Styles, and more |
| Round-Trip Fidelity | HTML → Graph → HTML preserves all structure including boolean attributes |
| Clustered Views | Group subgraphs with colored clusters for full document visualization |
| REST API | FastAPI-based endpoints for programmatic access |
| AWS Lambda Ready | Deployable as serverless function |
Quick Start
Installation
pip install mgraph-ai-service-html-graph
Basic Usage
from mgraph_ai_service_html_graph.service.html_graph.Html_Graph__Export__Service import Html_Graph__Export__Service
service = Html_Graph__Export__Service()
html = """
<html>
<body>
<div class="container">
<p>Hello World</p>
</div>
</body>
</html>
"""
# Export to DOT format
result = service.export(
html = html,
engine = 'dot',
transformation = 'default'
)
print(result['output'])
Running the Server
# Development
uvicorn mgraph_ai_service_html_graph.web.Html_Graph__Web:app --reload
# Production
uvicorn mgraph_ai_service_html_graph.web.Html_Graph__Web:app --host 0.0.0.0 --port 8000
Architecture
┌─────────────────────────────────────────────────────────────────────────────┐
│ Html_MGraph Document │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────────────┐ │
│ │ HEAD GRAPH │ │ BODY GRAPH │ │ ATTRIBUTES GRAPH │ │
│ │ │ │ │ │ │ │
│ │ <head> │ │ <body> │ │ element ──► instance ──► name │ │
│ │ └─title │ │ └─div │ │ └──► value │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────────────┐ │
│ │SCRIPTS GRAPH│ │STYLES GRAPH │ │ DOCUMENT GRAPH │ │
│ │ │ │ │ │ (Meta View) │ │
│ │ <script> │ │ <style> │ │ Connects all subgraphs │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
API Endpoints
Export HTML to Graph
POST /api/v1/html-graph/export
Content-Type: application/json
{
"html": "<html><body><div>Hello</div></body></html>",
"engine": "dot",
"transformation": "default"
}
List Available Engines
GET /api/v1/html-graph/engines
Returns: ["dot", "d3", "cytoscape", "visjs", "mermaid", "tree"]
List Available Transformations
GET /api/v1/html-graph/transformations
Returns transformation metadata including name, label, and description.
Rendering Engines
| Engine | Output | Best For |
|---|---|---|
| DOT | Graphviz DOT → SVG | Static diagrams, documentation |
| D3 | JSON for D3.js | Interactive web visualizations |
| Cytoscape | JSON for Cytoscape.js | Complex network analysis |
| VisJs | JSON for vis.js | Dynamic, physics-based layouts |
| Mermaid | Mermaid syntax | Markdown-embeddable diagrams |
| Tree | JSON tree structure | Hierarchical views |
Transformations
| Transformation | Description |
|---|---|
default |
Body DOM structure |
attributes-view |
Tags and their attributes |
full-document |
All 5 subgraphs with colored clusters |
head-view |
Head section structure |
scripts-view |
Script elements and content |
styles-view |
Style elements and CSS |
Creating Custom Transformations
from mgraph_ai_service_html_graph.service.html_graph__transformations.Graph_Transformation__Base import Graph_Transformation__Base
class My_Custom_Transformation(Graph_Transformation__Base):
name : str = "my-custom"
label : str = "My Custom View"
description : str = "Custom visualization"
def html_mgraph__to__mgraph(self, html_mgraph):
# Select which graph to visualize
return html_mgraph.attrs_graph.mgraph
def configure_dot(self, config):
# Customize DOT rendering
config.rankdir = 'LR'
return config
The 5-Phase Pipeline
Phase 1 Phase 2 Phase 3 Phase 4 Phase 5
──────── ──────── ──────── ──────── ────────
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
┌───────┐ ┌───────────┐ ┌─────────┐ ┌──────────┐ ┌────────┐
│ HTML │────────► │Html_MGraph│───────►│ MGraph │───────►│ Engine │───────►│ Output │
└───────┘ └───────────┘ └─────────┘ └──────────┘ └────────┘
html__to__ html_mgraph__ transform_ configure_* transform_
html_mgraph() to__mgraph() mgraph() callbacks export()
Each phase has a transformation hook allowing complete customization of the visualization pipeline.
Development
Setup
git clone https://github.com/the-cyber-boardroom/MGraph-AI__Service__Html__Graph.git
cd MGraph-AI__Service__Html__Graph
poetry install
Running Tests
pytest tests/
Project Structure
mgraph_ai_service_html_graph/
├── service/
│ ├── html_graph/ # Export service
│ ├── html_mgraph/ # Multi-graph HTML model
│ │ ├── converters/ # HTML ↔ MGraph converters
│ │ └── graphs/ # Subgraph implementations
│ ├── html_graph__transformations/ # View transformations
│ └── mgraph__engines/ # Rendering engines
└── web/ # FastAPI endpoints
Use Cases
- Web Scraping Analysis - Visualize DOM structure of scraped pages
- HTML Diff Visualization - Compare documents via graph representations
- Accessibility Auditing - Analyze attribute patterns for ARIA compliance
- DOM Manipulation Planning - Visualize before/after transformation states
- Educational Tool - Teach HTML structure through visual graphs
- Security Analysis - Analyze script and style injection points
Documentation
- Project Brief - Comprehensive overview
- Attribute Refactor - 3-node attribute model
License
Apache 2.0 - See LICENSE for details.
Contributing
Contributions welcome! Please read our contributing guidelines and submit pull requests.
Related Projects
- MGraph AI - Core graph framework
- The Cyber Boardroom - Parent organization
Metadata
Release files for mgraph-ai-service-html-graph 1.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mgraph_ai_service_html_graph-1.8.0.tar.gz | 527.1 kB | Without provenance | Details for mgraph_ai_service_html_graph-1.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mgraph_ai_service_html_graph-1.8.0-py3-none-any.whl | Python 3 | none | any | Details for mgraph_ai_service_html_graph-1.8.0-py3-none-any.whl |
Total release size: 1.3 MB
Release files / mgraph_ai_service_html_graph-1.8.0.tar.gz
| Download URL | mgraph_ai_service_html_graph-1.8.0.tar.gz |
|---|---|
| Size | 527.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b58d460094506e825b947f7cb7c23b8fc5d69d1e6e635d3f6ddbe99aed6ee02c
|
|
BLAKE2b-256 checksum How to use checksums |
9e4282bc1e1472e0b0ea187e0c4944de2a91f541b0658fa908e40949acb8cde9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mgraph_ai_service_html_graph-1.8.0-py3-none-any.whl
| Download URL | mgraph_ai_service_html_graph-1.8.0-py3-none-any.whl |
|---|---|
| Size | 813.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bf652668b63f7d4d3f75487f761ae37c5b0d3d9d3c74715128b9636dcfe75351
|
|
BLAKE2b-256 checksum How to use checksums |
efd96e972e5cab9615c25f03a2ac744af2bc074d2daca951749883c4731013d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for mgraph-ai-service-html-graph 1.8.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.