Prefect Collection Template contains all the boilerplate that you need to create a Prefect collection.
Project description
prefect-jinja
Welcome!
prefect-jinja
is a collection of pre-built Prefect tasks that can be used to quickly build Prefect flows to interact
with Jinja.
Getting Started
Python setup
Requires an installation of Python 3.7+.
We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.
These tasks are designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to the Prefect documentation.
Installation
Install prefect-jinja
with pip
:
pip install prefect-jinja
Then, register to view the block on Prefect Cloud:
prefect block register -m prefect_jinja.blocks
!!! note "Load Block"
To use the load
method on Blocks, you must already have a block document
saved through code or
saved through the UI.
Write and run a flow
Render templates from a directory
Using the JinjaEnvironmentBlock
block and the jinja_render_from_template
function to render an HTML page.
!!! note "Remote storage"
We recommend configuring remote file storage for task execution with
JinjaEnvironmentBlock
block and the jinja_render_from_template
function. This ensures tasks have access to
templates files, particularly when accessing a instance outside the execution environment.
from prefect import flow
from prefect_jinja import JinjaEnvironmentBlock, jinja_render_from_template
@flow
def send_welcome_flow(username: str):
jinja_environment = JinjaEnvironmentBlock(
search_path="templates",
namespace={
"company_name": "Acme",
}
)
return jinja_render_from_template(
"welcome.html",
jinja_environment,
username=username
)
print(send_welcome_flow(username="Neymar"))
Render templates from a string
Using the jinja_render_from_string
function to render a string.
from prefect import flow
from prefect_jinja import jinja_render_from_string
@flow
def send_hello_flow(username: str):
return jinja_render_from_string("Hello, {{name}}!", username=username)
print(send_hello_flow(username="Robinho"))
Resources
If you encounter any bugs while using prefect-jinja
, feel free to open an issue in the
prefect-jinja repository.
If you have any questions or issues while using prefect-jinja
, you can find help in either the
Prefect Discourse forum or the Prefect Slack community.
Development
If you'd like to install a version of prefect-jinja
for development, clone the repository and perform an editable
install with pip
:
git clone https://github.com/hallenmaia/prefect-jinja.git
cd prefect-jinja/
pip install -e ".[dev]"
# Install linting pre-commit hooks
pre-commit install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for prefect_jinja-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cde0c95f80db328f3a908196338a12c03a2ee93dabde01c4abadfc2cfa11023 |
|
MD5 | b448bf9681524b12e11c29e9588adb37 |
|
BLAKE2b-256 | e894c66442d4baccfdfe6c3b5d520ee3ab159175b2b905de4ee0594d566cd21f |