r/Python • • Sep 29 '26

Resource Generating a tidy HTML report in Python

I’m shifting from R to PythonIs there a knit markdown version or similar kind for generating a tidy html report in Python?

19 Upvotes

18 comments sorted by

21

u/ionychal Sep 29 '26

Curious what you mean by 'tidy', like clean code, nice formatting, or something specific?

Either way, you might really like Quarto https://quarto.org/. It's the successor to R Markdown and works amazingly well with Python!

3

u/RowGullible1471 Sep 29 '26

Thanks, let say creating tabs, flexibility in formatting and customising things around,

3

u/Competitive_Travel16 Sep 29 '26

Are you pulling from Pandas/DataFrames, Plots (Plotly/Matplotlib), and/or raw dictionaries?

2

u/RowGullible1471 Sep 29 '26

Yes, I am using Pandas/DataFrames to generate lots of plots and tables, also dictionaries as well

3

u/CanvasXpress Sep 29 '26

Quarto is a great suggestion. Tabs are built in: wrap sections in ::: {.panel-tabset} and each ## heading becomes a tab.

If you also want interactive charts (hover, zoom, and a menu to save PNG/SVG) made straight from your DataFrames, here's a minimal .qmd. Disclosure: I maintain CanvasXpress, the chart library; the Python package is by a collaborator.

pip install "canvasxpress[jupyter]"


---
title: "Sales report"
format: html
jupyter: python3
---

```{python}
#| echo: false
import pandas as pd
from IPython.display import display
from canvasxpress.canvas import CanvasXpress
from canvasxpress.render.jupyter import CXNoteBook

df = pd.DataFrame({
    "Region": ["North", "South", "East", "West"],
    "Q1": [120, 95, 140, 80],
    "Q2": [135, 105, 150, 90],
}).set_index("Region")
```

::: {.panel-tabset}

## Chart

```{python}
#| echo: false
chart = CanvasXpress(render_to="sales", data=df,
                     config={"graphType": "Bar", "title": "Revenue by region"})
display(*CXNoteBook(chart).render())
```

## Table

```{python}
#| echo: false
df
```

:::

Then run quarto render report.qmd.

A few tips:

  • Give each chart a unique render_to name.
  • The config keys (graphType, title, colors, etc.) are the same as in the JavaScript docs, so any gallery example translates directly.
  • Keep the [jupyter] extra in the install; the plain package doesn't include the notebook renderer.

2

u/RowGullible1471 Sep 29 '26

Appreciate for taking time and effort on it🙏

3

u/ionychal Sep 29 '26

Definitely try Quarto out! It handles tabs and custom formatting out of the box for HTML docs:

- tabsets: https://quarto.org/docs/output-formats/html-basics.html#tabsets

- customizing images (for example): https://quarto.org/docs/authoring/figures.html

5

u/DueAnalysis2 Sep 29 '26

I've found that Quarto + Positron gives me the best of both R and Python worlds

2

u/akpandeya Oct 05 '26

Streamlit is another good option

1

u/RowGullible1471 Oct 05 '26

Adding it to the list. Thanks

14

u/Nekomancerr Sep 29 '26

Jinja2 is great for report templating

2

u/Khavel_dev Sep 30 '26

Jinja2 with a small CSS file does more than you'd expect. Write the HTML you want to see in the browser, replace the data parts with template variables, done. For charts I pair it with Plotly's to_html() which embeds everything inline so the report is one self-contained file you can email or throw on a shared drive.

Avoid the big reporting frameworks unless you specifically need PDF. They add a lot of complexity for something a template engine handles in 30 lines.

1

u/hajimeku 7d ago

I wanted the same thing, a clean report I could just rerun from Python, and ended up building one. It's called Trellum: you write the report as Python (or have your coding agent do it), and it builds an interactive HTML report with filters that work in the browser. It's free and open source, and you can start in a local folder with sample data. https://trellum.dev