Report

Module: kpireport.report

class kpireport.report.Content(j2: Environment, report: Report)

The rendered report, in a variety of formats.

j2

a Jinja2 context to use for loading and rendering templates.

Type

Jinja2

report

the Report object for the current report.

Type

Report

formats

the list of all formats available for the report. Any formats added via add_format() will be reflected here.

Type

List[str]

add_format(fmt: str, views: list[View])

Render the specified format and add to the output contents.

If a layout file is found for this format, it will be used to render the raw output. If a layout file is not found, there will be no raw output, however, the list of Views will still be stored for the output format. This can be important for output drivers that may not be able to display/send a final rendered report in text, but could still render each view separately. The Slack output driver is a good example of this.

The layout file is expected to exist at ./templates/layout/default.{fmt}, e.g., ./template/layout/default.html for the HTML format.

Parameters
  • fmt (str) – the output format, e.g., "md" or "html".

  • views (List[View]) – the list of Views to render

get_format(fmt: str) Optional[str]

Get the rendered string for the given format.

Parameters

fmt (str) – the desired output format.

Returns

the rendered content for the given format, if any.

Return type

Optional[str]

get_views(fmt: str) list[View]

Get the rendered views for the given format.

Parameters

fmt (str) – the desired output format.

Returns

the list of Views rendered under that format.

Return type

List[View]

class kpireport.report.Report(title=None, interval_days=None, start_date=None, end_date=None, timezone=None, theme=None)

The report object.

Note

This class is not meant to be instantiated directly; instead, use the ReportFactory class to generate an instance.

title

the report title.

Type

str

interval_days

number of days.

Type

int

start_date

the start date.

Type

dateobj

end_date

the end date.

Type

dateobj

timezone

the timezone name. Defaults to the system timezone.

Type

str

theme

the report Theme.

Type

Theme

class kpireport.report.ReportFactory(config)

A factory class for building and executing an entire report.

Once you have a report parsed from its YAML Configuration file, you can execute the report like so:

ReportFactory(conf).create()
config

the (parsed) configuration YAML file.

Type

dict

supported_formats

the output formats that any report can target.

Type

List[str]

create()

Render all Views in the report and output using the output driver.

Important

This will send the report using all configured output drivers! Disable any output drivers you don’t wish to send to during testing.

class kpireport.report.Theme(num_columns=6, column_width=86, padding_width=20, theme_dir=None, ui_colors=None, error_colors=None, success_colors=None, series_colors=None, heading_font=None)

The report theme options.

num_columns

the number of columns in the report grid. (Default 6)

Type

int

column_width

the width of each column, in pixels. (Default 86)

Type

int

padding_width

the width of the horizontal padding at the report edges (Default 20)

Type

int

theme_dir

a directory where additional templates can be found. These templates will override the default templates of the same name, and can be used to alter the overall report appearance.

Type

str

ui_colors

a list of user interface colors. This is expected to be a 5-tuple of (text color, lighter text color, dark bg color, bg accent, bg color)

Type

List[str]

error_colors

a list of error colors used when views render an error vs. success state. This is expected to be a 2-tuple of (dark, light).

Type

List[str]

success_colors

a list of success colors used when views render an error vs. success state. This is expected to be a 2-tuple of (dark, light).

Type

List[str]

series_colors

a list of series colors. There can be as many or as few series colors in the theme; you just want to ensure you can handle whatever needs you have for plotting or displaying data in charts or graphs such that series can be identified clearly.

Type

List[str]

heading_font

A CSS font-family declaration, which will define how the headings are styled. (Default “Helvetica, Arial, sans-serif”). Note that due to Jinja escaping rules, this does not like embedded quotes. Quotes are not required even when a typeface has a space in the name, so they are safe to simply omit.

Type

str