prefect.utilities.templating

Functions

determine_placeholder_type

determine_placeholder_type(name: str) -> PlaceholderType

Determines the type of a placeholder based on its name.

Args:

  • name: The name of the placeholder

Returns:

  • The type of the placeholder

find_placeholders

find_placeholders(template: T) -> set[Placeholder]

Finds all placeholders in a template.

Args:

  • template: template to discover placeholders in

Returns:

  • A set of all placeholders in the template

apply_values

apply_values(template: T, values: dict[str, Any], remove_notset: bool = True, warn_on_notset: bool = False) -> Union[T, type[NotSet]]

Replaces placeholders in a template with values from a supplied dictionary.

Will recursively replace placeholders in dictionaries and lists.

If a value has no placeholders, it will be returned unchanged.

If a template contains only a single placeholder, the placeholder will be fully replaced with the value.

If a template contains text before or after a placeholder or there are multiple placeholders, the placeholders will be replaced with the corresponding variable values.

If a template contains a placeholder that is not in values, NotSet will be returned to signify that no placeholder replacement occurred. If template is a dictionary that contains a key with a value of NotSet, the key will be removed in the return value unless remove_notset is set to False.

Args:

  • template: template to discover and replace values in
  • values: The values to apply to placeholders in the template
  • remove_notset: If True, remove keys with an unset value
  • warn_on_notset: If True, warn when a placeholder is not found in values

Returns:

  • The template with the values applied

Classes

PlaceholderType

Placeholder