Reference

class pytmlib.output.builder.OutputBuilder(serializer: Serializer)
add_action(title: str, action: Callable[[...], OutputBuilder], **kwargs) OutputBuilder

Add an action button. Creates a button, if the user clicks on it, he will be redirected to the specified action. The action should be a method reference to another action in the exercise class.

Parameters:
  • title – The title for the button, e.g. Submit.

  • action – A method reference to the next action.

  • kwargs – Additional arguments to pass to the action method.

Returns:

The current output builder instance.

add_figure(figure: Figure, description: str = None, dpi: int = None, as_png: bool = None) OutputBuilder

Add a figure to the output.

Parameters:
  • figure – The figure to show.

  • description – An optional description of the figure.

  • dpi – DPI resolution for the figure. Default is 300.

  • as_png – Output the figure as PNG. Default is SVG.

Returns:

The current output builder instance.

add_image(path: str, description: str = None) OutputBuilder

Add an image to the output. The path can either be absolute or relative to the working directory, which is normally the project root folder.

Parameters:
  • path – The path to the image.

  • description – An optional description of the image.

Returns:

The current output builder instance.

add_latex(text: str) OutputBuilder

Add LaTeX to the output.

Parameters:

text – The text to print.

Returns:

The current output builder instance.

add_number_field(name: str, label: str | Latex, value: float = None, required: bool = True, min_value: float = None, max_value: float = None, step: float = None) OutputBuilder

Add a numeric input field. The input will be handled as float. Use add_text_field() to add a text input field.

Parameters:
  • name – The name of the input field, should be unique.

  • label – The label for the input field.

  • value – The default value to display.

  • required – Mark the field as required.

  • min_value – The minimum value to accept.

  • max_value – The maximum value to accept.

  • step – The granularity of the input.

Returns:

The current output builder instance.

add_option_group(name: str, label: str | Latex | None, options: List[Option | str | int | float], required: bool = True, inline: bool = True) OutputBuilder

Add a radio fields. The user can choose between the provided options.

Parameters:
  • name – The name of the input field, should be unique.

  • label – The label for the input field, should be unique.

  • options – A list of available options to choose from.

  • required – Mark the field as required.

  • inline – Display the options inline.

Returns:

The current output builder instance.

add_paragraph(text: str | Latex) OutputBuilder

Add a paragraph to the output. Can be used for normal text output.

Parameters:

text – The text to print.

Returns:

The current output builder instance.

add_score(score: float) OutputBuilder

Set a score. The score will be submitted to the connected LMS (e.g. Moodle).

Parameters:

score – The score to set. Must be in the range 0.0 - 1.0.

Returns:

The current output builder instance.

add_selection_group(name: str, label: str | Latex | None, options: List[Option | str | int | float | bool], required: bool = True, inline: bool = True) OutputBuilder

Add a checkbox fields. The user can choose multiple values from the provided options.

Parameters:
  • name – The name of the input field, should be unique.

  • label – The label for the input field, should be unique.

  • options – A list of available options to choose from.

  • required – Mark the field as required.

  • inline – Display the options inline.

Returns:

The current output builder instance.

add_table(data: List[List[str | int | float | Latex | TableCell]]) OutputBuilder

Add a table to the output.

Parameters:

data – The data to display.

Returns:

The current output builder instance.

add_text_field(name: str, label: str | Latex, value: str = None, required: bool = True, max_length: int = None) OutputBuilder

Add a text input field. The input will be handled as string. Use add_number_field() to add a numeric input field.

Parameters:
  • name – The name of the text field, should be unique.

  • label – The label for the text field.

  • value – The default value to display.

  • required – Mark the field as required.

  • max_length – The maximum length of this text field.

Returns:

The current output builder instance.

class pytmlib.abstract_exercise.AbstractExercise(unique_id: str = None, static_folder_path: str = None, *args, **kwargs)
property output: OutputBuilder

Get a new output builder instance.

Returns:

A new instance of the output builder.

abstract start() OutputBuilder

This is the main entrypoint.

Returns:

The output of this exercise action.

abstract property version: str

Get the semantic version of this exercise.

Returns:

The version of this exercise.

@pytmlib.decorators.entrypoint

Marks an exercise action as entrypoint.

Parameters:

func_or_title – Pass an optional title for the entrypoint.