Template

Using supporting Python package

The supporting python package is available in the rendering environment, so it can be imported like any other installed package.

from course_utils.example import utility_function

utility_function(2)
4

In this case the function of utility_function is trivial but it is useful to hide details that are not relevant or that risk being too complicated.

If later you want to show the details one can do

def utility_function(x):
    """
    A simple utility function that performs a basic operation on the input.
    """
    return x * 2

If #| echo: false was to be added to this block it would just show the function definition.

Installing supporting Python package

Others can install the Python package in their environment, for example for a Jupyter environment (e.g. Google Colab)

repo_name = "template" # Replace with relevant repo.
try:
    import course_utils
except:
    !pip install "course-utils @ git+https://github.com/au-mbg/{repo_name}.git#subdirectory=course-utils"