simple_report.report module

class simple_report.report.Report(report_dir, report_title=None, report_date=None, config_file=None, color_mode='light')[source]

Bases: object

Main report object

Parameters:
  • report_dir (str | Path)

  • report_title (str | None)

  • report_date (str | int | date | datetime | None)

  • config_file (str | Path | None)

  • color_mode (str)

add_accordion_item(name)[source]

Add another accordion item to the current accordion layout

Parameters:

name (str) – The text shown on the accordion

add_column()[source]

Add another column to the current column layout

add_custom_html_code(html)[source]

Add custom / generic html code

Parameters:

html (str) – The HTML string.

add_error_warning_info_section(**kwargs)[source]

Add a section detailing errors, warnings, and info

Add a link to another page to the navbar

Parameters:
  • page_name (str) – The key/name of the page to link to

  • link_name (str) – The text that will be displayed

add_header(header_text, color=None)[source]

Add a header to the current page

Parameters:
  • header_text (str) – Header text. You can use any valid HTML code inside the text, e.g., links and such.

  • color (Optional[str]) – Color of the header box

add_image(image_source, remove_source=None, responsive=None, center=None)[source]

Add an image to the current page

Parameters:
  • image_source (Union[str, Path]) – The path to the image to add

  • remove_source (Optional[bool]) – If true the source will be deleted and only acopy in the report dir is kept

  • responsive (Optional[bool]) – If true the image will automatically be resized to match the outer container

  • center (Optional[bool]) – If true the image will be centered

add_list(list_items)[source]

Add a list to the current page

Parameters:

list_items (list[str]) – A list to be added to the page

Add a link to another page to the current page

Parameters:
  • page_name (str) – The key/name of the page to link to

  • link_name (str) – The text that will be displayed

add_navbar_item(name)[source]

Add another navbar item to the current navbar layout

Parameters:

name (str) – The text shown on the navbar pill

add_page(name, subpage=True, color_mode=None)[source]

Add a new page to the report

Parameters:
  • name (str) – The name of the report page

  • subpage (bool) – Indicates this is a subpage of the report

  • color_mode (Optional[str]) – Color mode of the page, either light or dark

add_report_header(include_date=True, color='primary')[source]

Add a report header to the current page

Parameters:
  • include_date (bool) – Add the current date to the report

  • color (str) – The backgroound color for the header

add_sub_header(header_text, color=None, sub_level=None)[source]

Add a sub header to the current page

Parameters:
  • header_text (str) – Header text. You can use any valid HTML code inside the text, e.g., links and such.

  • color (Optional[str]) – Color of the header box

  • sub_level (Optional[int]) – Shrinks the width of the header box. Levels can be 1 to 5. The higher the level the smaller the box

add_tab(name)[source]

Add another tab to the current tab layout

Parameters:

name (str) – The text shown on the tab

add_table(table_data, formatters=None, options=None, size=None, align=None, caption=None, footers=None, order=None, color=None)[source]

Add a table to the page.

table_data can either be a pandas DataFrame or a list of lists. For the former we assume indices and column labels are already properly formatted. For the latter we assume the first item contains the headers.

Parameters:
  • table_data (Union[DataFrame, list[list[Any]]]) – Data to tabelize.

  • formatters (Optional[Union[str, Callable, list[str], list[Callable]]]) – Formatters applied to each table element. If a list is provided it must match the number of columns. A single formatter is applied to all columns. The default formatter is str().

  • options (Optional[list[str]]) –

    Turn optional elements of the DataTable on. Supported options:

    • page - Split long tables into pages of 10 (configurable)

    • info - Show number of rows

    • search - Add a search field

    • no_sort - Disable initial sorting

    • color_negative_values - Highlight values < 0 in red

    • color_positive_values - Highlight values > 0 in green

    • full_width - Table spans full window width

  • size (Optional[int]) – Sets the width of the table (1-12). 12 uses full container width.

  • align (Optional[str]) – Alignment of cell content.

  • caption (Optional[str]) – Text shown below the table.

  • footers (Optional[list[list[Any]]]) – Rows always shown at the bottom of the table.

  • order (Optional[list[list[Any]]]) – Default table order in the form [[col_idx, 'asc' | 'desc'], ...].

  • color (Optional[str]) – Text color. Automatically determined if omitted.

add_text(text, color=None, align=None)[source]

Add (colored) text to the page

This will create a new paragraph. So if you want to mix colors within one paragraph you’ll have to do this yourself for now

Parameters:
  • text (str) – Your text

  • color (Optional[str]) – One of the supported colors

  • align (Optional[Literal['left', 'center', 'right']]) – Alignment of text

close_accordion()[source]

Close the current accorion layout

close_columns()[source]

Close the current column layout

close_navbar()[source]

Close the current navbar layout

close_sublevel()[source]

Close the current sub-level layout

close_tabs()[source]

Close the current tab layout

dump()[source]

Save the report to file and add the CSS files

Get a link to the current page

Get a link to another page to the current page

Parameters:
  • page_name (str) – The key/name of the page to link to

  • link_name (str) – The text that will be displayed

open_accordion(**kwargs)[source]

Open a accordion layout

open_columns()[source]

Start a column layout

open_navbar(**kwargs)[source]

Open a navbar layout

open_sublevel(**kwargs)[source]

Open a sub-level layout

open_tabs()[source]

Open a tab layout

set_current_page(page_name)[source]

Set the current page that is being worked on

Parameters:

page_name (str) – The page you want to switch to