Hooks API

Types

This is the Python documentation of the two types of hooks (actions and filters) as well as the contexts system which is used to instrument them. Understanding how Tutor hooks work is useful to create plugins that modify the behaviour of Tutor. However, plugin developers should almost certainly not import these hook types directly. Instead, use the reference hooks catalog.

Utilities

Functions

tutor.core.hooks.clear_all(context=None)

Clear both actions and filters.

Parameters:

context (str | None)

Return type:

None

tutor.hooks.lru_cache(func)

LRU cache decorator similar to functools.lru_cache that is automatically cleared whenever plugins are updated.

Use this to decorate functions that need to be called multiple times with a return value that depends on which plugins are loaded. Typically: functions that depend on the output of filters.

Parameters:

func (Callable[[...], Any])

Return type:

Callable[[…], Any]

Priorities

tutor.core.hooks.priorities.DEFAULT = 10

By default, all callbacks have the same priority and are processed in the order they were added.

tutor.core.hooks.priorities.HIGH = 5

High priority callbacks are triggered first.

tutor.core.hooks.priorities.LOW = 50

Low-priority callbacks are called last. Add callbacks with this priority to override previous callbacks. To add callbacks with even lower priority, use LOW + somevalue (though such behaviour is not encouraged).