prefect_jinja.blocks
A module to interact with Jinja Environment.
JinjaEnvironmentBlock
Block to create a template environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace |
dict
|
A dict of variables that are available in every template loaded by the environment. |
required |
search_path |
str
|
A path to the directory that contains the templates. Can be relative or absolute.
Relative paths are relative to the running |
required |
Example
Load a environment block:
from prefect_jinja import JinjaEnvironmentBlock
block = JinjaEnvironmentBlock.load("BLOCK_NAME")
Source code in prefect_jinja/blocks.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
get_env
Creates a Jinja Environment with a loader that searches for template files in the path provided by the
search_path attribute and sets the global variables provided by the namespace attribute.
Returns:
| Type | Description |
|---|---|
Environment
|
A Jinja environment. |
Example
@flow
def example_get_jinja_environment_flow():
env_block = JinjaEnvironmentBlock(
search_path="templates", namespace={"sender_mail": "sender@test.com"}
)
return env_block.get_env()
jinja_env = example_get_jinja_environment_flow()
Source code in prefect_jinja/blocks.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |