# String Templating Tasks
# StringFormatter
This task contains a template which is formatted with the results of any upstream tasks and returned.
Variables from prefect.context
are also available for formatting.
Args:
template (str, optional)
: the optional default template string to format at runtime; can also be provided as a keyword torun
, which takes precedence over this default.**kwargs (optional)
: additional keyword arguments to pass to the standard Task constructor
from prefect import Flow
from prefect.tasks.templates import StringFormatter
message = '''
Hi {name}! Welcome to Prefect. Today is {today}.
'''
msg_task = StringFormatter(name="message body", template=message)
with Flow("string-template") as flow:
output = msg_task(name="Marvin")
flow_state = flow.run()
print(flow_state.result[output].result)
# Hi Marvin! Welcome to Prefect. Today is 2019-08-28.
methods: |
---|
prefect.tasks.templates.strings.StringFormatter.run (template=None, **format_kwargs)[source] |
Formats the template with the provided kwargs.
|
# JinjaTemplate
This task contains a Jinja template which is formatted with the results of any upstream tasks and returned.
Variables from prefect.context
will also be used for rendering.
Args:
template (str, optional)
: the optional default template string to render at runtime; can also be provided as a keyword torun
, which takes precedence over this default.**kwargs (optional)
: additional keyword arguments to pass to the standard Task constructor
from prefect import Flow
from prefect.tasks.templates import JinjaTemplate
message = '''
Hi {{name}}! Welcome to Prefect. Today is {{today}}.
'''
msg_task = JinjaTemplate(name="message body", template=message)
with Flow("string-template") as flow:
output = msg_task(name="Marvin")
flow_state = flow.run()
print(flow_state.result[output].result)
# Hi Marvin! Welcome to Prefect. Today is 2019-08-28.
methods: |
---|
prefect.tasks.templates.jinja2.JinjaTemplate.run (template=None, **format_kwargs)[source] |
Formats the Jinja Template with the provided kwargs.
|
This documentation was auto-generated from commit n/a
on July 1, 2021 at 18:35 UTC