Skip to content

Report

Module with classes for generate reports in various formats.

Main classes in module are Reporter (for LaTeX), MarkdownReporter (for Markdown), and TypstReporter (for Typst). Reporter uses LaTeX executable for building reports, MarkdownReporter uses weasyprint for PDF generation, and TypstReporter uses the typst Python package for PDF generation.

Classes list:

1. EnumFBSection
2. Fragment
3. FragmentsBuilder
4. getTemplatesPath
5. getMarkdownTemplatesPath
6. getTypstTemplatesPath
7. MarkdownFragment
8. MarkdownFragmentsBuilder
9. MarkdownReporter
10. ReportDriverEnum
11. Reporter
12. ReportProperties
13. ReportTemplateEnum
14. TypstFragment
15. TypstFragmentsBuilder
16. TypstReporter

Fragment

Class that hold fragments as list of strings for use with Reporter.

This class is a container for complete a template (ex. LaTex template). Template are processed after with Reporter class. Will be generated automatically a type of file. For example PDF or MD etc.

MarkdownFragment

Class that holds fragments as list of strings for use with MarkdownReporter.

This class is a container for complete a markdown template. Templates are processed using standard Jinja2 delimiters ({{ }}, {% %}).

add_template(name, placeholders)

Add a rendered template using standard Jinja2 delimiters.

MarkdownFragmentsBuilder

Abstract base class for markdown fragment builders.

MarkdownReporter

Class that compiles markdown fragments to produce PDF, MD, or HTML.

This class compiles markdown fragments using weasyprint to produce PDF files, or can output raw markdown and HTML.

Typical usage example:

 reporter = MarkdownReporter(markdownTemplatePath)
 reporter.linkFragments(ReportTemplateEnum.MD_ENG_CAL, [frag])
 reporter.compileDocument(path=str(working_path), fileName="report")

compileDocument(path='', fileName='report', output_format='md', deleteIfExists=True)

Build output file from markdown.

Write the templated content to with name . Extensions are automatically added at the end of file name.

Parameters:

Name Type Description Default
path str

where output files are created. Defaults to ''.

''
fileName str

input file name. Defaults to 'report'.

'report'
output_format Literal['md', 'html', 'pdf']

Output format. Defaults to 'md'.

'md'
deleteIfExists bool

if True delete file if exists

True

linkFragments(template, fragments=None, builder=None, glossary=False, main_file_name='')

Links markdown fragments adding also a main document.

Parameters:

Name Type Description Default
template ReportTemplateEnum

Enum for main document template (MD_ENG_CAL or MD_MAIN).

required
fragments (List[MarkdownFragment], Optional)

List of markdown fragments to put in main document.

None
builder (Union[MarkdownFragmentsBuilder, List[MarkdownFragmentsBuilder]], Optional)

List of fragment builder. This is alternative to fragments argument. Default is None.

None
glossary bool

Default is False.

False
main_file_name str

Default is "".

''

Returns:

Type Description
bool

True on success, False otherwise

ReportTemplateEnum

Bases: Enum

This Enum describe the main documents level

Attributes:

Name Type Description
TEX_ENG_CAL

style for official reports

TEX_KOMA

styled with KOMA scripts LaTex

TEX_MAIN

styled with main LaTex

MD_ENG_CAL

markdown style for official reports

MD_MAIN

markdown styled with main template

Reporter

Class that compiles fragments to produce PDF or others.

This class compiles fragments to produce PDF or others type of files. Actually produces PDF using LaTex files by one of LaTeX implementations as MikTex (popular implementation for Windows) or TexLive (popular on Linux).

Typical usage example:

 reporter = Reporter(latexTemplatePath)
 reporter.linkFragments(ReportDriverEnum.PDFLATEX, ReportTemplateEnum.TEX_ENG_CAL, [frag_title, frag])
 reporter.makePDF(path=str(working_path), fileName="TEX_ENG_CAL")

compileDocument(path='', fileName='report', verbose=False, deleteIfExists=True)

Build a PDF using driver LATEXPDF

Write before templated in with name . Extension are automatically added at the end of file name.

Parameters:

Name Type Description Default
deleteIfExists bool

if True delete file PDF if exists

True
verbose bool
False
path str

where intermediate file are crated. Defaults to ''.

''
fileName str

input file name. Defaults to 'report'.

'report'

linkFragments(template, driver=ReportDriverEnum.PDFLATEX, fragments=None, builder=None, glossary=False, main_file_name='')

Links fragments adding also a main documents.

Links fragments adding also a main documents. For example in LaTex the linking process add

    \documentclass[11pt, a4paper]{article}
    \usepackage[latin1]{inputenc}
    ...
    \begin{document}
    ...
    Fragment line 1
    Fragment line 2
    ...
    Fragment line n
    ...
    \end{document}

Parameters:

Name Type Description Default
template ReportTemplateEnum

Enum for main document template.

required
driver (ReportDriverEnum, Optional)

Leave default option.

PDFLATEX
fragments (List[Fragment], Optional)

List of rows to put in main document.

None
builder (Union[FragmentsBuilder, List[FragmentsBuilder]], Optional)

List of fragment builder. This is alternative to fragments argument. Default is None.

None
glossary bool

Default is False.

False
main_file_name str

Default is "".

''

Returns:

Type Description
bool

True on success, False otherwise

TypstFragment

Class that holds fragments as list of strings for use with TypstReporter.

This class is a container for complete a typst template. Templates use custom Jinja2 delimiters to avoid Typst '#' conflicts: block: <%% ... %%>, variable: << ... >>, comment: <#% ... %#>

add_template(name, placeholders)

Add a rendered template using custom Jinja2 delimiters for Typst.

TypstFragmentsBuilder

Abstract base class for typst fragment builders.

TypstReporter

Class that compiles typst fragments to produce PDF or .typ files.

This class compiles typst fragments using the typst Python package to produce PDF files, or can output raw .typ source.

Typical usage example:

 reporter = TypstReporter(typstTemplatePath)
 reporter.linkFragments(ReportTemplateEnum.TYP_ENG_CAL, [frag])
 reporter.compileDocument(path=str(working_path), fileName="report")

compileDocument(path='', fileName='report', output_format='typ', deleteIfExists=True)

Build output file from typst.

Write the templated content to with name . Extensions are automatically added at the end of file name.

Parameters:

Name Type Description Default
path str

where output files are created. Defaults to ''.

''
fileName str

input file name. Defaults to 'report'.

'report'
output_format Literal['typ', 'pdf']

Output format ('typ' or 'pdf'). Defaults to 'typ'.

'typ'
deleteIfExists bool

if True delete file if exists

True

linkFragments(template, fragments=None, builder=None, glossary=False, main_file_name='')

Links typst fragments adding also a main document.

Parameters:

Name Type Description Default
template ReportTemplateEnum

Enum for main document template (TYP_ENG_CAL or TYP_MAIN).

required
fragments List[TypstFragment] | None

List of typst fragments to put in main document.

None
builder Union[TypstFragmentsBuilder, List[TypstFragmentsBuilder]] | None

List of fragment builder. Alternative to fragments. Default is None.

None
glossary bool

Default is False.

False
main_file_name str

Default is "".

''

Returns:

Type Description
bool

True on success, False otherwise

getMarkdownTemplatesPath()

Function to get templates markdown path.

Returns:

Type Description
Path

A Path object.

getTemplatesPath()

Funtion to get templates latex path.

Returns:

Type Description
Path

A Path object.

getTypstTemplatesPath()

Function to get templates typst path.

Returns:

Type Description
Path

A Path object.