WhyML provides both a Python API and a REST API for programmatic access to all functionality. This reference covers all available classes, methods, and endpoints.
Main processor class for converting manifests to different formats.
from whyml import WhyMLProcessor
processor = WhyMLProcessor()
convert_to_html(manifest_path: str, **kwargs) -> ConversionResultConvert YAML manifest to HTML.
Parameters:
manifest_path (str): Path to YAML manifest file**kwargs: Additional conversion options
optimize_output (bool): Minify HTML outputinclude_meta_tags (bool): Include SEO meta tagsresponsive_design (bool): Include responsive viewportReturns: ConversionResult object
Example:
result = await processor.convert_to_html('manifest.yaml', optimize_output=True)
result.save_to_file('output.html')
convert_to_react(manifest_path: str, **kwargs) -> ConversionResultConvert YAML manifest to React component.
Parameters:
manifest_path (str): Path to YAML manifest file**kwargs: Additional options
use_typescript (bool): Generate TypeScript componentuse_hooks (bool): Use React hookscss_modules (bool): Use CSS modulesExample:
result = await processor.convert_to_react(
'manifest.yaml',
use_typescript=True,
css_modules=True
)
convert_to_vue(manifest_path: str, **kwargs) -> ConversionResultConvert YAML manifest to Vue component.
Parameters:
manifest_path (str): Path to YAML manifest file**kwargs: Additional options
composition_api (bool): Use Composition APItypescript (bool): Use TypeScriptscoped_styles (bool): Use scoped CSSconvert_to_php(manifest_path: str, **kwargs) -> ConversionResultConvert YAML manifest to PHP component.
Parameters:
manifest_path (str): Path to YAML manifest file**kwargs: Additional options
namespace (str): PHP namespaceuse_type_declarations (bool): Use PHP type hintsscrape_url_to_manifest(url: str, **kwargs) -> dictScrape URL and convert to YAML manifest.
Parameters:
url (str): URL to scrape**kwargs: Scraping options
max_depth (int): Maximum nesting depthsimplify_structure (bool): Simplify HTML structuresections (list): Sections to extractLoad and process YAML manifests with inheritance support.
from whyml import ManifestLoader
loader = ManifestLoader()
load_manifest(path: str) -> dictLoad YAML manifest from file or URL.
Parameters:
path (str): Path to manifest file or URLReturns: Parsed manifest dictionary
Example:
async with loader:
manifest = await loader.load_manifest('manifest.yaml')
resolve_dependencies(manifest: dict) -> dictResolve template inheritance and dependencies.
Parameters:
manifest (dict): Loaded manifestReturns: Resolved manifest with all dependencies
Advanced web scraping with structure analysis.
from whyml.scrapers import URLScraper
scraper = URLScraper(
max_depth=5,
simplify_structure=True,
preserve_semantic=True
)
max_depth (int): Maximum HTML nesting depthsimplify_structure (bool): Enable structure simplificationflatten_containers (bool): Remove wrapper divspreserve_semantic (bool): Preserve semantic HTML elementsextract_styles (bool): Extract CSS stylesextract_scripts (bool): Extract JavaScriptenable_analysis (bool): Enable page analysisscrape_url(url: str, **kwargs) -> ScrapingResultScrape URL and return structured result.
Parameters:
url (str): URL to scrape**kwargs: Additional optionsReturns: ScrapingResult object
Example:
result = await scraper.scrape_url('https://example.com')
manifest = result.to_manifest()
Analyze webpage content and structure.
from whyml.scrapers import WebpageAnalyzer
analyzer = WebpageAnalyzer()
analyze_page(html: str, url: str) -> dictAnalyze HTML content and return metrics.
Parameters:
html (str): HTML contenturl (str): Page URLReturns: Analysis dictionary with metrics
Individual converter classes for each output format.
from whyml.converters import HTMLConverter
converter = HTMLConverter(
doctype="html5",
include_meta_tags=True,
responsive_design=True
)
result = converter.convert(manifest)
from whyml.converters import ReactConverter
converter = ReactConverter(
use_typescript=True,
use_hooks=True,
css_framework="css-modules"
)
result = converter.convert(manifest)
from whyml.converters import VueConverter
converter = VueConverter(
vue_version=3,
use_composition_api=True,
scoped_styles=True
)
result = converter.convert(manifest)
from whyml.converters import PHPConverter
converter = PHPConverter(
namespace="App\\Components",
use_type_declarations=True
)
result = converter.convert(manifest)
Result object returned by all converters.
content (str): Generated code contentfilename (str): Suggested filenameformat_type (str): Output formatmetadata (dict): Conversion metadatasave_to_file(path: str) -> NoneSave content to file.
get_size() -> intGet content size in bytes.
get_lines() -> intGet number of lines in content.
WhyML provides a FastAPI-based REST API for web integration.
whyml-server --host 0.0.0.0 --port 8000
http://localhost:8000
Currently no authentication required. API keys coming in future versions.
GET /api/health
Check API health status.
Response:
{
"status": "healthy",
"version": "1.0.0",
"timestamp": "2025-01-20T10:30:00Z"
}
POST /api/convert
Convert YAML manifest to specified format.
Request Body:
{
"manifest": "metadata:\n title: Test\n...",
"format": "html",
"options": {
"optimize_output": true,
"include_meta_tags": true
}
}
Parameters:
manifest (string): YAML manifest contentformat (string): Output format (html, react, vue, php)options (object): Format-specific optionsResponse:
{
"success": true,
"content": "<!DOCTYPE html>...",
"filename": "component.html",
"metadata": {
"format": "html",
"size": 1024,
"lines": 45
}
}
POST /api/scrape
Scrape URL and return YAML manifest.
Request Body:
{
"url": "https://example.com",
"options": {
"max_depth": 5,
"simplify_structure": true,
"sections": ["metadata", "structure", "styles"]
}
}
Response:
{
"success": true,
"manifest": "metadata:\n title: Example\n...",
"analysis": {
"page_type": "landing_page",
"complexity_score": 3,
"seo_score": 85
}
}
POST /api/validate
Validate YAML manifest structure.
Request Body:
{
"manifest": "metadata:\n title: Test\n..."
}
Response:
{
"valid": true,
"errors": [],
"warnings": [
"Missing description in metadata"
]
}
POST /api/batch-convert
Convert multiple manifests in batch.
Request Body:
{
"manifests": [
{
"name": "page1",
"content": "metadata:\n title: Page 1\n..."
},
{
"name": "page2",
"content": "metadata:\n title: Page 2\n..."
}
],
"format": "html",
"options": {}
}
Response:
{
"success": true,
"results": [
{
"name": "page1",
"content": "<!DOCTYPE html>...",
"filename": "page1.html"
},
{
"name": "page2",
"content": "<!DOCTYPE html>...",
"filename": "page2.html"
}
]
}
All endpoints return errors in this format:
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid manifest structure",
"details": {
"line": 5,
"column": 10,
"field": "metadata.title"
}
}
}
Real-time conversion and scraping via WebSocket.
const ws = new WebSocket('ws://localhost:8000/ws');
{
"type": "convert",
"data": {
"manifest": "...",
"format": "html"
}
}
{
"type": "convert_result",
"data": {
"content": "...",
"filename": "..."
}
}
from whyml.exceptions import (
WhyMLError,
ManifestLoadingError,
ConversionError,
ScrapingError,
ValidationError
)
Base exception class for all WhyML errors.
Raised when manifest loading fails.
Raised when format conversion fails.
Raised when web scraping fails.
Raised when manifest validation fails.
try:
result = await processor.convert_to_html('manifest.yaml')
except ManifestLoadingError as e:
print(f"Failed to load manifest: {e}")
except ConversionError as e:
print(f"Conversion failed: {e}")
except WhyMLError as e:
print(f"WhyML error: {e}")
from whyml import configure
configure(
default_timeout=30,
cache_enabled=True,
cache_dir="~/.whyml/cache",
log_level="INFO"
)
WHYML_CACHE_DIR: Cache directory pathWHYML_LOG_LEVEL: Logging levelWHYML_TIMEOUT: Default timeout in secondsWHYML_API_KEY: API key for external servicesimport asyncio
from whyml import WhyMLProcessor, URLScraper
async def complete_workflow():
# Scrape website
scraper = URLScraper(simplify_structure=True)
scraping_result = await scraper.scrape_url('https://example.com')
# Save manifest
manifest_content = scraping_result.to_yaml()
with open('scraped.yaml', 'w') as f:
f.write(manifest_content)
# Convert to multiple formats
processor = WhyMLProcessor()
# HTML
html_result = await processor.convert_to_html('scraped.yaml')
html_result.save_to_file('output.html')
# React
react_result = await processor.convert_to_react(
'scraped.yaml',
use_typescript=True
)
react_result.save_to_file('Component.tsx')
# Vue
vue_result = await processor.convert_to_vue(
'scraped.yaml',
composition_api=True
)
vue_result.save_to_file('Component.vue')
asyncio.run(complete_workflow())
from whyml.converters import BaseConverter
class CustomConverter(BaseConverter):
@property
def format_name(self) -> str:
return "Custom"
@property
def file_extension(self) -> str:
return "custom"
def convert(self, manifest: dict, **kwargs):
# Custom conversion logic
content = self.generate_custom_format(manifest)
return ConversionResult(
content=content,
filename=self.generate_filename(manifest),
format_type="custom"
)