Pyreball
Pyreball is a Python reporting tool that generates HTML reports from Python scripts.
Main features:
- Charts in Vega-Altair, Plotly, Bokeh, and Matplotlib (and thus also Seaborn etc.).
- Interactive tables based on DataTables library and created from pandas DataFrame.
- Basic text formatting such as headings, emphasis, and lists.
- Hyperlinks, references and table of contents.
The main motivation is to allow users to create persistent reports in the form of HTML pages from scripts retaining the Python syntax. The advantage of using regular Python scripts as the source of these HTML pages is that they are easy to maintain, can be refactored quickly through various IDEs, etc.
Pyreball is designed not to require any dependencies, unless you decide to use them. For example, if you decide to print pandas DataFrames to HTML tables and plot altair charts, you need to install pandas and altair.
Installation
First Report
Create a python script, for example named report.py
:
import pyreball as pb
pb.set_title("Pyreball Illustration")
pb.print_div(
"Pyreball has many features, among others:",
pb.ulist(
"Creating charts.",
"Sortable and scrollable tables.",
f'Basic text formatting such as {pb.em("emphasis")}.',
f'Also {pb.link("hyperlinks", "https://www.python.org/")}.',
),
)
Now run pyreball
on this script as
pyreball
will create report.html
that should look like this when opened in a browser:
It is also possible to pass a module path:
Adding Tables and Figures
The core functionality of pyreball
does not require any 3rd party dependencies.
However, it is possible to generate other types of elements with the help of libraries such
as pandas or seaborn.
Let's create another python script called report_chart.py
:
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import pyreball as pb
pb.set_title("Tables and Figures")
df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 6, 5]})
pb.print_table(df, caption="A data table.")
fig, ax = plt.subplots()
sns.lineplot(x="x", y="y", ax=ax, data=df)
ax.set(xlabel="x", ylabel="y")
pb.print_figure(fig, caption="A line chart.")
Install pandas
and seaborn
, then run pyreball
:
report_chart.html
should look like this:
Next Steps
Continue with Basic Printing chapter to explore more features and examples.