π₯οΈ html_rendererΒΆ
Provides the ReportHTMLRenderer class, which is responsible for rendering
HTML reports from structured data using Jinja2 templates.
OverviewΒΆ
This module provides the ReportHTMLRenderer class for rendering HTML
reports from structured data using Jinja2 templates. It supports rendering from
both Python dictionaries and JSON files, and saving the resulting HTML to disk.
Key FeaturesΒΆ
Configurable template path for custom report layouts
Rendering from in-memory data or JSON files
Safe file output with directory creation
Typical usage example:
renderer = ReportHTMLRenderer()
html = renderer.render(report_data) # Render from a Python dictionary
html_from_json = renderer.render_from_json("report_data.json") # Render from JSON file
renderer.save_html(html, output_path="outputs/report.html")
ClassesΒΆ
ReportHTMLRendererΒΆ
- class owlmix.reporting.html_renderer.ReportHTMLRenderer(template_path: str | Path = DEFAULT_TEMPLATE_PATH)ΒΆ
Renders HTML reports from structured data using Jinja2 templates.
This class provides methods to render HTML from a Python dictionary or a JSON file, and to save the rendered HTML to disk. It is designed for use in automated EDA or analytics pipelines where reports need to be generated programmatically.
- Parameters:
template_path (
Optional[Union[str, Path]]) β Path to the directory containing Jinja2 templates. Defaults to the internal β_templatesβ directory.
Methods
- render(report_data: dict) strΒΆ
Render HTML from a dictionary of report data.
- Parameters:
report_data (
dict) β The report data to render. Should contain a βsectionsβ key with section data.- Returns:
The rendered HTML as a string.
- Return type:
str
- render_from_json(json_path: str | Path) strΒΆ
Render HTML from a JSON file containing report data.
- Parameters:
json_path (
strorPath) β Path to the JSON file with report data.- Returns:
The rendered HTML as a string.
- Return type:
str
- save_html(html_str: str = None, output_path: str | Path = None)ΒΆ
Save the rendered HTML to a file.
- Parameters:
html_str (
Optional[str]) β The HTML string to save. If None, uses the last rendered HTML.output_path (
Optional[Union[str, Path]]) β The file path to save the HTML to.
- Raises:
ValueError β If no HTML has been rendered or output_path is not specified.
- html_strΒΆ
Get the most recently rendered HTML string.
- Returns:
The last rendered HTML string, or None if not rendered yet.
- Return type:
Optional[str]
Module AttributesΒΆ
- owlmix.reporting.html_renderer.DEFAULT_TEMPLATE_PATHΒΆ
Default path to the internal β_templatesβ directory for Jinja2 templates.
- owlmix.reporting.html_renderer.STATIC_PATHΒΆ
Path to the internal β_staticβ directory for Jinja2 static assets used in reports.